Skip to content

Commit d578a48

Browse files
authored
Reverse dependencies between api and transport (#604)
1 parent 8d70aac commit d578a48

40 files changed

+3842
-3476
lines changed

crates/bcr-ebill-api/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ futures.workspace = true
2727
infer = { version = "0.19.0", default-features = false }
2828
bcr-ebill-core.workspace = true
2929
bcr-ebill-persistence.workspace = true
30-
bcr-ebill-transport.workspace = true
3130
tokio.workspace = true
3231
tokio_with_wasm.workspace = true
3332
secp256k1.workspace = true

crates/bcr-ebill-api/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod blockchain;
77
pub mod constants;
88
pub mod data;
99
pub mod external;
10-
mod persistence;
10+
pub mod persistence;
1111
pub mod service;
1212
#[cfg(test)]
1313
mod tests;

crates/bcr-ebill-api/src/service/bill_service/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{blockchain, external, persistence, util};
1+
use crate::{blockchain, external, persistence, service::notification_service, util};
22
use thiserror::Error;
33

44
/// Generic error type
@@ -33,7 +33,7 @@ pub enum Error {
3333
Cryptography(#[from] util::crypto::Error),
3434

3535
#[error("Notification error: {0}")]
36-
Notification(#[from] bcr_ebill_transport::Error),
36+
Notification(#[from] notification_service::Error),
3737

3838
#[error("io error {0}")]
3939
Io(#[from] std::io::Error),

crates/bcr-ebill-api/src/service/bill_service/issue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{
33
constants::MAX_BILL_ATTACHMENTS,
44
data::validate_node_id_network,
55
get_config,
6+
service::notification_service::event::BillChainEvent,
67
util::{self, file::UploadFileType},
78
};
89
use bcr_ebill_core::{
@@ -17,7 +18,6 @@ use bcr_ebill_core::{
1718
contact::{BillAnonParticipant, BillIdentParticipant, BillParticipant},
1819
util::BcrKeys,
1920
};
20-
use bcr_ebill_transport::BillChainEvent;
2121
use log::{debug, error, info};
2222

2323
impl BillService {

crates/bcr-ebill-api/src/service/bill_service/propagation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::collections::HashMap;
22

3+
use crate::service::notification_service::event::BillChainEvent;
4+
35
use super::{BillAction, Result, service::BillService};
46
use bcr_ebill_core::{
57
NodeId,
@@ -9,7 +11,6 @@ use bcr_ebill_core::{
911
identity::Identity,
1012
notification::ActionType,
1113
};
12-
use bcr_ebill_transport::BillChainEvent;
1314

1415
impl BillService {
1516
pub(super) async fn notify_for_block_action(

crates/bcr-ebill-api/src/service/bill_service/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::persistence::company::{CompanyChainStoreApi, CompanyStoreApi};
2525
use crate::persistence::contact::ContactStoreApi;
2626
use crate::persistence::file_upload::FileUploadStoreApi;
2727
use crate::persistence::identity::{IdentityChainStoreApi, IdentityStoreApi};
28+
use crate::service::notification_service::NotificationServiceApi;
2829
use crate::util::BcrKeys;
2930
use crate::util::file::UploadFileType;
3031
use crate::{external, util};
@@ -47,7 +48,6 @@ use bcr_ebill_core::notification::ActionType;
4748
use bcr_ebill_core::util::currency;
4849
use bcr_ebill_core::{File, ServiceTraitBounds, Validate, ValidationError};
4950
use bcr_ebill_persistence::mint::MintStoreApi;
50-
use bcr_ebill_transport::NotificationServiceApi;
5151
use log::{debug, error, info, warn};
5252
use std::collections::{HashMap, HashSet};
5353
use std::sync::Arc;

crates/bcr-ebill-api/src/service/bill_service/test_utils.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ use crate::{
55
service::{
66
company_service::tests::get_valid_company_block,
77
contact_service::tests::get_baseline_contact,
8+
notification_service::MockNotificationServiceApi,
89
},
910
tests::tests::{
1011
MockBillChainStoreApiMock, MockBillStoreApiMock, MockCompanyChainStoreApiMock,
1112
MockCompanyStoreApiMock, MockContactStoreApiMock, MockFileUploadStoreApiMock,
1213
MockIdentityChainStoreApiMock, MockIdentityStoreApiMock, MockMintStore,
13-
MockNotificationService, VALID_PAYMENT_ADDRESS_TESTNET, bill_id_test,
14-
bill_identified_participant_only_node_id, bill_participant_only_node_id, empty_address,
15-
empty_bill_identified_participant, empty_bitcredit_bill, empty_identity, init_test_cfg,
16-
node_id_test, node_id_test_other, node_id_test_other2, private_key_test,
14+
VALID_PAYMENT_ADDRESS_TESTNET, bill_id_test, bill_identified_participant_only_node_id,
15+
bill_participant_only_node_id, empty_address, empty_bill_identified_participant,
16+
empty_bitcredit_bill, empty_identity, init_test_cfg, node_id_test, node_id_test_other,
17+
node_id_test_other2, private_key_test,
1718
},
1819
util,
1920
};
@@ -52,7 +53,7 @@ pub struct MockBillContext {
5253
pub company_store: MockCompanyStoreApiMock,
5354
pub file_upload_store: MockFileUploadStoreApiMock,
5455
pub file_upload_client: MockFileStorageClientApi,
55-
pub notification_service: MockNotificationService,
56+
pub notification_service: MockNotificationServiceApi,
5657
pub mint_store: MockMintStore,
5758
pub mint_client: MockMintClientApi,
5859
}
@@ -283,7 +284,7 @@ pub fn get_ctx() -> MockBillContext {
283284
company_chain_store: MockCompanyChainStoreApiMock::new(),
284285
contact_store: MockContactStoreApiMock::new(),
285286
company_store: MockCompanyStoreApiMock::new(),
286-
notification_service: MockNotificationService::new(),
287+
notification_service: MockNotificationServiceApi::new(),
287288
mint_store: MockMintStore::new(),
288289
mint_client: MockMintClientApi::new(),
289290
}

crates/bcr-ebill-api/src/service/company_service.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::Result;
2+
use super::notification_service::NotificationServiceApi;
23
use crate::blockchain::Blockchain;
34
use crate::blockchain::company::{
45
CompanyAddSignatoryBlockData, CompanyBlock, CompanyBlockchain, CompanyCreateBlockData,
@@ -18,6 +19,7 @@ use crate::external::file_storage::FileStorageClientApi;
1819
use crate::get_config;
1920
use crate::persistence::company::{CompanyChainStoreApi, CompanyStoreApi};
2021
use crate::persistence::identity::IdentityChainStoreApi;
22+
use crate::service::notification_service::event::{CompanyChainEvent, IdentityChainEvent};
2123
use crate::util::BcrKeys;
2224
use crate::util::file::UploadFileType;
2325
use crate::{
@@ -29,9 +31,6 @@ use crate::{
2931
use async_trait::async_trait;
3032
use bcr_ebill_core::identity::IdentityType;
3133
use bcr_ebill_core::{NodeId, PublicKey, SecretKey, ServiceTraitBounds, ValidationError};
32-
use bcr_ebill_transport::NotificationServiceApi;
33-
use bcr_ebill_transport::event::company_events::CompanyChainEvent;
34-
use bcr_ebill_transport::event::identity_events::IdentityChainEvent;
3534
use log::{debug, error, info};
3635
use std::sync::Arc;
3736

@@ -862,12 +861,15 @@ pub mod tests {
862861
blockchain::{Blockchain, identity::IdentityBlockchain},
863862
data::identity::IdentityWithAll,
864863
external::file_storage::MockFileStorageClientApi,
865-
service::contact_service::tests::get_baseline_contact,
864+
service::{
865+
contact_service::tests::get_baseline_contact,
866+
notification_service::MockNotificationServiceApi,
867+
},
866868
tests::tests::{
867869
MockCompanyChainStoreApiMock, MockCompanyStoreApiMock, MockContactStoreApiMock,
868870
MockFileUploadStoreApiMock, MockIdentityChainStoreApiMock, MockIdentityStoreApiMock,
869-
MockNotificationService, empty_address, empty_identity, empty_optional_address,
870-
node_id_test, node_id_test_other, node_id_test_other2, private_key_test,
871+
empty_address, empty_identity, empty_optional_address, node_id_test,
872+
node_id_test_other, node_id_test_other2, private_key_test,
871873
},
872874
};
873875
use std::{collections::HashMap, str::FromStr};
@@ -881,7 +883,7 @@ pub mod tests {
881883
mock_contacts_storage: MockContactStoreApiMock,
882884
mock_identity_chain_storage: MockIdentityChainStoreApiMock,
883885
mock_company_chain_storage: MockCompanyChainStoreApiMock,
884-
notification_service: MockNotificationService,
886+
notification_service: MockNotificationServiceApi,
885887
) -> CompanyService {
886888
CompanyService::new(
887889
Arc::new(mock_storage),
@@ -903,7 +905,7 @@ pub mod tests {
903905
MockContactStoreApiMock,
904906
MockIdentityChainStoreApiMock,
905907
MockCompanyChainStoreApiMock,
906-
MockNotificationService,
908+
MockNotificationServiceApi,
907909
) {
908910
(
909911
MockCompanyStoreApiMock::new(),
@@ -913,7 +915,7 @@ pub mod tests {
913915
MockContactStoreApiMock::new(),
914916
MockIdentityChainStoreApiMock::new(),
915917
MockCompanyChainStoreApiMock::new(),
916-
MockNotificationService::new(),
918+
MockNotificationServiceApi::new(),
917919
)
918920
}
919921

crates/bcr-ebill-api/src/service/identity_service.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use super::Result;
2+
use super::notification_service::NotificationServiceApi;
3+
use super::notification_service::event::IdentityChainEvent;
24
use crate::data::validate_node_id_network;
35
use crate::external::file_storage::FileStorageClientApi;
46
use crate::util::file::UploadFileType;
@@ -17,8 +19,6 @@ use async_trait::async_trait;
1719
use bcr_ebill_core::identity::validation::{validate_create_identity, validate_update_identity};
1820
use bcr_ebill_core::identity::{ActiveIdentityState, IdentityType};
1921
use bcr_ebill_core::{NodeId, ServiceTraitBounds, ValidationError};
20-
use bcr_ebill_transport::NotificationServiceApi;
21-
use bcr_ebill_transport::event::identity_events::IdentityChainEvent;
2222
use log::{debug, error, info};
2323
use std::sync::Arc;
2424

@@ -678,9 +678,10 @@ mod tests {
678678
use super::*;
679679
use crate::{
680680
external::file_storage::MockFileStorageClientApi,
681+
service::notification_service::MockNotificationServiceApi,
681682
tests::tests::{
682683
MockFileUploadStoreApiMock, MockIdentityChainStoreApiMock, MockIdentityStoreApiMock,
683-
MockNotificationService, empty_identity, empty_optional_address, init_test_cfg,
684+
empty_identity, empty_optional_address, init_test_cfg,
684685
},
685686
};
686687
use mockall::predicate::eq;
@@ -691,14 +692,14 @@ mod tests {
691692
Arc::new(MockFileUploadStoreApiMock::new()),
692693
Arc::new(MockFileStorageClientApi::new()),
693694
Arc::new(MockIdentityChainStoreApiMock::new()),
694-
Arc::new(MockNotificationService::new()),
695+
Arc::new(MockNotificationServiceApi::new()),
695696
)
696697
}
697698

698699
fn get_service_with_chain_storage(
699700
mock_storage: MockIdentityStoreApiMock,
700701
mock_chain_storage: MockIdentityChainStoreApiMock,
701-
notification: MockNotificationService,
702+
notification: MockNotificationServiceApi,
702703
) -> IdentityService {
703704
IdentityService::new(
704705
Arc::new(mock_storage),
@@ -722,7 +723,7 @@ mod tests {
722723
.returning(|| Ok(BcrKeys::new()));
723724
let mut chain_storage = MockIdentityChainStoreApiMock::new();
724725
chain_storage.expect_add_block().returning(|_| Ok(()));
725-
let mut notification = MockNotificationService::new();
726+
let mut notification = MockNotificationServiceApi::new();
726727
notification
727728
.expect_send_identity_chain_events()
728729
.returning(|_| Ok(()))
@@ -762,7 +763,7 @@ mod tests {
762763
.returning(|| Ok(BcrKeys::new()));
763764
let mut chain_storage = MockIdentityChainStoreApiMock::new();
764765
chain_storage.expect_add_block().returning(|_| Ok(()));
765-
let mut notification = MockNotificationService::new();
766+
let mut notification = MockNotificationServiceApi::new();
766767
notification
767768
.expect_send_identity_chain_events()
768769
.returning(|_| Ok(()))
@@ -816,7 +817,7 @@ mod tests {
816817
.clone(),
817818
)
818819
});
819-
let mut notification = MockNotificationService::new();
820+
let mut notification = MockNotificationServiceApi::new();
820821
notification
821822
.expect_send_identity_chain_events()
822823
.returning(|_| Ok(()))
@@ -861,7 +862,7 @@ mod tests {
861862
});
862863
let mut chain_storage = MockIdentityChainStoreApiMock::new();
863864
chain_storage.expect_add_block().returning(|_| Ok(()));
864-
let mut notification = MockNotificationService::new();
865+
let mut notification = MockNotificationServiceApi::new();
865866
notification.expect_send_identity_chain_events().never();
866867

867868
let service = get_service_with_chain_storage(storage, chain_storage, notification);
@@ -906,7 +907,7 @@ mod tests {
906907
});
907908
let mut chain_storage = MockIdentityChainStoreApiMock::new();
908909
chain_storage.expect_add_block().returning(|_| Ok(()));
909-
let mut notification = MockNotificationService::new();
910+
let mut notification = MockNotificationServiceApi::new();
910911
notification.expect_send_identity_chain_events().never();
911912

912913
let service = get_service_with_chain_storage(storage, chain_storage, notification);
@@ -956,7 +957,7 @@ mod tests {
956957
)
957958
});
958959
chain_storage.expect_add_block().returning(|_| Ok(()));
959-
let mut notification = MockNotificationService::new();
960+
let mut notification = MockNotificationServiceApi::new();
960961
notification
961962
.expect_send_identity_chain_events()
962963
.returning(|_| Ok(()))
@@ -1046,7 +1047,7 @@ mod tests {
10461047
.expect_add_block()
10471048
.returning(|_| Ok(()))
10481049
.once();
1049-
let mut notification = MockNotificationService::new();
1050+
let mut notification = MockNotificationServiceApi::new();
10501051
notification.expect_send_identity_chain_events().never();
10511052

10521053
let service = get_service_with_chain_storage(storage, chain_storage, notification);

crates/bcr-ebill-api/src/service/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub enum Error {
2727

2828
/// errors stemming from sending or receiving notifications
2929
#[error("Notification service error: {0}")]
30-
NotificationService(#[from] bcr_ebill_transport::Error),
30+
NotificationService(#[from] notification_service::Error),
3131

3232
/// errors stemming from handling bills
3333
#[error("Bill service error: {0}")]

0 commit comments

Comments
 (0)