Skip to content

Commit f9be33d

Browse files
committed
feat: trigger relay refresh on contact updates
1 parent b4beef6 commit f9be33d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

crates/bcr-ebill-transport/src/handler/nostr_contact_processor.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@ pub struct NostrContactProcessor {
1717
transport: Arc<dyn TransportClientApi>,
1818
nostr_contact_store: Arc<dyn NostrContactStoreApi>,
1919
bitcoin_network: bitcoin::Network,
20+
nostr_client: Option<Arc<crate::nostr::NostrClient>>,
2021
}
2122

2223
impl NostrContactProcessor {
2324
pub fn new(
2425
transport: Arc<dyn TransportClientApi>,
2526
nostr_contact_store: Arc<dyn NostrContactStoreApi>,
2627
bitcoin_network: bitcoin::Network,
28+
nostr_client: Option<Arc<crate::nostr::NostrClient>>,
2729
) -> Self {
2830
Self {
2931
transport,
3032
nostr_contact_store,
3133
bitcoin_network,
34+
nostr_client,
3235
}
3336
}
3437
}
@@ -73,8 +76,17 @@ impl NostrContactProcessor {
7376
async fn upsert_contact(&self, node_id: &NodeId, contact: &NostrContact) {
7477
if let Err(e) = self.nostr_contact_store.upsert(contact).await {
7578
error!("Failed to save nostr contact information for node_id {node_id}: {e}");
76-
} else if let Err(e) = self.transport.add_contact_subscription(node_id).await {
77-
error!("Failed to add nostr contact subscription for contact node_id {node_id}: {e}");
79+
} else {
80+
if let Err(e) = self.transport.add_contact_subscription(node_id).await {
81+
error!("Failed to add nostr contact subscription for contact node_id {node_id}: {e}");
82+
}
83+
84+
// Trigger relay refresh to include new contact's relays
85+
if let Some(ref client) = self.nostr_client {
86+
if let Err(e) = client.refresh_relays().await {
87+
warn!("Failed to refresh relays after contact update for {node_id}: {e}");
88+
}
89+
}
7890
}
7991
}
8092
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ pub async fn create_transport_service(
130130
transport.clone(),
131131
db_context.nostr_contact_store.clone(),
132132
get_config().bitcoin_network(),
133+
Some(client.clone()),
133134
));
134135
let bill_processor = Arc::new(BillChainEventProcessor::new(
135136
db_context.bill_blockchain_store.clone(),
@@ -223,6 +224,7 @@ pub async fn create_nostr_consumer(
223224
transport.clone(),
224225
db_context.nostr_contact_store.clone(),
225226
get_config().bitcoin_network(),
227+
Some(client.clone()),
226228
));
227229

228230
let bill_processor = Arc::new(BillChainEventProcessor::new(
@@ -338,6 +340,7 @@ pub async fn create_restore_account_service(
338340
nostr_client.clone(),
339341
db_context.nostr_contact_store.clone(),
340342
config.bitcoin_network(),
343+
Some(nostr_client.clone()),
341344
));
342345

343346
let bill_processor = Arc::new(BillChainEventProcessor::new(

0 commit comments

Comments
 (0)