Skip to content

Commit 8a29d1d

Browse files
authored
Chain events part 1 (#435)
* Move mod, start chain event builder * Retry queue * Move transport * Allow resolving nodes with block height from chain * Moved push and event handlers * Move email * Moved notification_service * Issue Bill rework * Review fixes * More fixes * Typo * Errors, keys
1 parent 80e2c74 commit 8a29d1d

File tree

32 files changed

+1124
-361
lines changed

32 files changed

+1124
-361
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22
resolver = "3"
3-
members = [ "crates/bcr-ebill-web", "crates/bcr-ebill-core", "crates/bcr-ebill-api", "crates/bcr-ebill-persistence" ]
3+
members = [ "crates/bcr-ebill-web", "crates/bcr-ebill-core", "crates/bcr-ebill-api", "crates/bcr-ebill-persistence" , "crates/bcr-ebill-transport"]
44

55

66
[workspace.dependencies]

crates/bcr-ebill-api/Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ uuid.workspace = true
2222
bitcoin.workspace = true
2323
nostr-sdk.workspace = true
2424
futures.workspace = true
25-
reqwest = { version = "0.12.12", default-features = false, features = ["rustls-tls", "json"] }
25+
reqwest = { version = "0.12.12", default-features = false, features = [
26+
"rustls-tls",
27+
"json",
28+
] }
2629
rust_decimal = { version = "1.36.0", default-features = false }
2730
infer = { version = "0.19.0", default-features = false }
28-
bcr-ebill-core = { path = "../bcr-ebill-core"}
29-
bcr-ebill-persistence = { path = "../bcr-ebill-persistence"}
31+
bcr-ebill-core = { path = "../bcr-ebill-core" }
32+
bcr-ebill-persistence = { path = "../bcr-ebill-persistence" }
33+
bcr-ebill-transport = { path = "../bcr-ebill-transport" }
3034

3135
[dev-dependencies]
3236
mockall = "0.13.1"

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, service::notification_service, util};
1+
use crate::{blockchain, external, persistence, util};
22
use thiserror::Error;
33

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

143143
#[error("Notification error: {0}")]
144-
Notification(#[from] notification_service::Error),
144+
Notification(#[from] bcr_ebill_transport::Error),
145145

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

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use bcr_ebill_core::{
1010
contact::IdentityPublicData,
1111
util::BcrKeys,
1212
};
13+
use bcr_ebill_transport::BillChainEvent;
1314
use log::error;
1415

1516
impl BillService {
@@ -37,16 +38,12 @@ impl BillService {
3738
let public_key = keys.get_public_key();
3839

3940
let bill_id = util::sha256_hash(public_key.as_bytes());
41+
let bill_keys = BillKeys {
42+
private_key: keys.get_private_key_string(),
43+
public_key: keys.get_public_key(),
44+
};
4045

41-
self.store
42-
.save_keys(
43-
&bill_id,
44-
&BillKeys {
45-
private_key: keys.get_private_key_string(),
46-
public_key: keys.get_public_key(),
47-
},
48-
)
49-
.await?;
46+
self.store.save_keys(&bill_id, &bill_keys).await?;
5047

5148
let mut bill_files: Vec<File> = vec![];
5249
if let Some(ref upload_id) = file_upload_id {
@@ -121,7 +118,7 @@ impl BillService {
121118

122119
// send notification to all required recipients
123120
self.notification_service
124-
.send_bill_is_signed_event(&bill)
121+
.send_bill_is_signed_event(&BillChainEvent::new(&bill, &chain, &bill_keys)?)
125122
.await?;
126123

127124
// propagate the bill

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use super::super::notification_service::NotificationServiceApi;
21
use super::error::Error;
32
use super::{BillAction, BillServiceApi, Result};
43
use crate::blockchain::Blockchain;
@@ -29,6 +28,7 @@ use bcr_ebill_core::constants::{
2928
ACCEPT_DEADLINE_SECONDS, PAYMENT_DEADLINE_SECONDS, RECOURSE_DEADLINE_SECONDS,
3029
};
3130
use bcr_ebill_core::notification::ActionType;
31+
use bcr_ebill_transport::NotificationServiceApi;
3232
use futures::future::try_join_all;
3333
use log::{error, info};
3434
use std::collections::HashSet;

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ use crate::{
55
service::{
66
company_service::tests::get_valid_company_block,
77
contact_service::tests::get_baseline_contact,
8-
notification_service::MockNotificationServiceApi,
98
},
109
tests::tests::{
1110
MockBillChainStoreApiMock, MockBillStoreApiMock, MockCompanyChainStoreApiMock,
1211
MockCompanyStoreApiMock, MockContactStoreApiMock, MockFileUploadStoreApiMock,
13-
MockIdentityChainStoreApiMock, MockIdentityStoreApiMock, TEST_PRIVATE_KEY_SECP,
14-
TEST_PUB_KEY_SECP, empty_address, empty_bitcredit_bill, empty_identity,
15-
empty_identity_public_data, identity_public_data_only_node_id,
12+
MockIdentityChainStoreApiMock, MockIdentityStoreApiMock, MockNotificationService,
13+
TEST_PRIVATE_KEY_SECP, TEST_PUB_KEY_SECP, empty_address, empty_bitcredit_bill,
14+
empty_identity, empty_identity_public_data, identity_public_data_only_node_id,
1615
},
1716
util,
1817
};
@@ -42,7 +41,7 @@ pub struct MockBillContext {
4241
pub company_chain_store: MockCompanyChainStoreApiMock,
4342
pub company_store: MockCompanyStoreApiMock,
4443
pub file_upload_store: MockFileUploadStoreApiMock,
45-
pub notification_service: MockNotificationServiceApi,
44+
pub notification_service: MockNotificationService,
4645
}
4746

4847
pub fn get_baseline_identity() -> IdentityWithAll {
@@ -165,7 +164,7 @@ pub fn get_ctx() -> MockBillContext {
165164
company_chain_store: MockCompanyChainStoreApiMock::new(),
166165
contact_store: MockContactStoreApiMock::new(),
167166
company_store: MockCompanyStoreApiMock::new(),
168-
notification_service: MockNotificationServiceApi::new(),
167+
notification_service: MockNotificationService::new(),
169168
}
170169
}
171170

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ use crate::util;
1414
use crate::{blockchain, external};
1515
use backup_service::{BackupService, BackupServiceApi};
1616
use bcr_ebill_persistence::db::SurrealDbConfig;
17+
use bcr_ebill_transport::{NotificationServiceApi, PushApi, PushService};
1718
use bill_service::{BillServiceApi, service::BillService};
1819
use company_service::{CompanyService, CompanyServiceApi};
1920
use contact_service::{ContactService, ContactServiceApi};
2021
use file_upload_service::{FileUploadService, FileUploadServiceApi};
2122
use identity_service::{IdentityService, IdentityServiceApi};
2223
use log::error;
23-
use notification_service::push_notification::{PushApi, PushService};
2424
use notification_service::{
25-
NostrConsumer, NotificationServiceApi, create_nostr_client, create_nostr_consumer,
26-
create_notification_service,
25+
NostrConsumer, create_nostr_client, create_nostr_consumer, create_notification_service,
2726
};
2827
use search_service::{SearchService, SearchServiceApi};
2928
use std::sync::Arc;
@@ -50,7 +49,7 @@ pub enum Error {
5049

5150
/// errors stemming from sending or receiving notifications
5251
#[error("Notification service error: {0}")]
53-
NotificationService(#[from] notification_service::Error),
52+
NotificationService(#[from] bcr_ebill_transport::Error),
5453

5554
/// errors stemming from handling bills
5655
#[error("Bill service error: {0}")]
@@ -147,8 +146,12 @@ pub async fn create_service_context(
147146
let bitcoin_client = Arc::new(BitcoinClient::new());
148147

149148
let nostr_client = create_nostr_client(&config, db.identity_store.clone()).await?;
150-
let notification_service =
151-
create_notification_service(nostr_client.clone(), db.notification_store.clone()).await?;
149+
let notification_service = create_notification_service(
150+
nostr_client.clone(),
151+
db.notification_store.clone(),
152+
contact_service.clone(),
153+
)
154+
.await?;
152155

153156
let bill_service = Arc::new(BillService::new(
154157
db.bill_store,

0 commit comments

Comments
 (0)