Skip to content

Commit 59d0a9e

Browse files
authored
Add default mint to nostr contacts on startup (#551)
1 parent b366277 commit 59d0a9e

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Set the BTC network in the identity and check, if the persisted network is the same as the one configured in the application, failing if it doesn't.
44
* Nostr npub as primary key in Nostr contacts (breaking DB change)
5+
* Add default mint to nostr contacts as default, so it doesn't have to be added to contacts anymore
56

67
# 0.3.15
78

crates/bcr-ebill-api/src/service/notification_service/default_service.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ mod tests {
625625
};
626626
use bcr_ebill_core::blockchain::bill::{BillBlock, BillBlockchain};
627627
use bcr_ebill_core::blockchain::{Blockchain, BlockchainType};
628+
use bcr_ebill_core::nostr_contact::{
629+
HandshakeStatus, NostrContact, NostrPublicKey, TrustLevel,
630+
};
628631
use bcr_ebill_core::util::{BcrKeys, date::now};
629632
use bcr_ebill_transport::event::bill_blockchain_event::ChainInvite;
630633
use bcr_ebill_transport::{EventEnvelope, EventType, PushApi};
@@ -677,7 +680,7 @@ mod tests {
677680
MockBillChainStoreApiMock, MockBillStoreApiMock, MockChainKeyService,
678681
MockNostrChainEventStore, MockNostrContactStore, MockNostrEventOffsetStoreApiMock,
679682
MockNostrQueuedMessageStore, MockNotificationStoreApiMock, TEST_BILL_ID,
680-
TEST_PRIVATE_KEY_SECP, TEST_PUB_KEY_SECP,
683+
TEST_NODE_ID_SECP_AS_NPUB_HEX, TEST_PRIVATE_KEY_SECP, TEST_PUB_KEY_SECP,
681684
};
682685

683686
fn check_chain_payload(event: &EventEnvelope, bill_event_type: BillEventType) -> bool {
@@ -1905,7 +1908,16 @@ mod tests {
19051908
let push_service = Arc::new(MockPushService::new());
19061909
let bill_store = Arc::new(MockBillStoreApiMock::new());
19071910
let bill_blockchain_store = Arc::new(MockBillChainStoreApiMock::new());
1908-
let nostr_contact_store = Arc::new(MockNostrContactStore::new());
1911+
let mut nostr_contact_store = MockNostrContactStore::new();
1912+
nostr_contact_store.expect_by_node_id().returning(|_| {
1913+
Ok(Some(NostrContact {
1914+
npub: NostrPublicKey::from_hex(TEST_NODE_ID_SECP_AS_NPUB_HEX).unwrap(),
1915+
name: None,
1916+
relays: Vec::default(),
1917+
trust_level: TrustLevel::Participant,
1918+
handshake_status: HandshakeStatus::None,
1919+
}))
1920+
});
19091921
let chain_key_store = Arc::new(MockChainKeyService::new());
19101922
let chain_event_store = Arc::new(MockNostrChainEventStore::new());
19111923
let _ = create_nostr_consumer(
@@ -1916,7 +1928,7 @@ mod tests {
19161928
push_service,
19171929
bill_blockchain_store,
19181930
bill_store,
1919-
nostr_contact_store,
1931+
Arc::new(nostr_contact_store),
19201932
chain_key_store,
19211933
chain_event_store,
19221934
)

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::collections::HashMap;
22
use std::sync::Arc;
33

4-
use crate::Config;
54
use crate::persistence::identity::IdentityStoreApi;
65
use crate::persistence::nostr::NostrEventOffsetStoreApi;
76
use crate::persistence::notification::NotificationStoreApi;
7+
use crate::{Config, get_config};
88
use bcr_ebill_persistence::bill::{BillChainStoreApi, BillStoreApi};
99
use bcr_ebill_persistence::company::CompanyStoreApi;
1010
use bcr_ebill_persistence::nostr::{
@@ -139,6 +139,11 @@ pub async fn create_nostr_consumer(
139139
nostr_contact_store,
140140
));
141141

142+
// on startup, we make sure the configured default mint exists
143+
processor
144+
.ensure_nostr_contact(&get_config().mint_config.default_mint_node_id)
145+
.await;
146+
142147
// register the logging event handler for all events for now. Later we will probably
143148
// setup the handlers outside and pass them to the consumer via this functions arguments.
144149
let handlers: Vec<Box<dyn NotificationHandlerApi>> = vec![

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl BillChainEventProcessor {
7272
}
7373
}
7474

75-
async fn ensure_nostr_contact(&self, node_id: &str) {
75+
pub async fn ensure_nostr_contact(&self, node_id: &str) {
7676
// we already have the contact in the store, no need to resolve it
7777
if let Ok(Some(_)) = self.nostr_contact_store.by_node_id(node_id).await {
7878
return;

crates/bcr-ebill-wasm/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ let config = {
5454
nostr_only_known_contacts: false,
5555
job_runner_initial_delay_seconds: 1,
5656
job_runner_check_interval_seconds: 600,
57-
default_mint_url: "http://localhost:4343",
58-
// default_mint_url: "https://wildcat-dev-docker.minibill.tech",
57+
// default_mint_url: "http://localhost:4343",
58+
default_mint_url: "https://wildcat-dev-docker.minibill.tech",
5959
default_mint_node_id: "02b7102bd5a4a572298f2aa485e86e490881e9ad7906fcae741db141b8ba1e8acc",
60+
// default_mint_node_id: "0372422bfa5c9b60ef2f10ced26e764983b2e675cd7fac374f5f223616530ce3fb", // dev mint
6061
};
6162

6263
async function start() {

0 commit comments

Comments
 (0)