Skip to content

Commit 8e66d4c

Browse files
committed
feat: add max_relays config field with default of 50
1 parent 57d3539 commit 8e66d4c

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,25 @@ pub struct PaymentConfig {
8484
}
8585

8686
/// Nostr specific configuration
87-
#[derive(Debug, Clone, Default)]
87+
#[derive(Debug, Clone)]
8888
pub struct NostrConfig {
8989
/// Only known contacts can message us via DM.
9090
pub only_known_contacts: bool,
9191
/// All relays we want to publish our messages to and receive messages from.
9292
pub relays: Vec<url::Url>,
93+
/// Maximum number of contact relays to connect to (user relays are exempt).
94+
/// Defaults to 50 if not specified.
95+
pub max_relays: Option<usize>,
96+
}
97+
98+
impl Default for NostrConfig {
99+
fn default() -> Self {
100+
Self {
101+
only_known_contacts: false,
102+
relays: vec![],
103+
max_relays: Some(50),
104+
}
105+
}
93106
}
94107

95108
/// Mint configuration

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ pub mod tests {
142142
impl NostrContactStoreApi for NostrContactStore {
143143
async fn by_node_id(&self, node_id: &NodeId) -> Result<Option<NostrContact>>;
144144
async fn by_node_ids(&self, node_ids: Vec<NodeId>) -> Result<Vec<NostrContact>>;
145+
async fn get_all(&self) -> Result<Vec<NostrContact>>;
145146
async fn by_npub(&self, npub: &NostrPublicKey) -> Result<Option<NostrContact>>;
146147
async fn upsert(&self, data: &NostrContact) -> Result<()>;
147148
async fn delete(&self, node_id: &NodeId) -> Result<()>;
@@ -492,6 +493,7 @@ pub mod tests {
492493
nostr_config: NostrConfig {
493494
only_known_contacts: false,
494495
relays: vec![url::Url::parse("ws://localhost:8080").unwrap()],
496+
max_relays: Some(50),
495497
},
496498
mint_config: MintConfig {
497499
default_mint_url: url::Url::parse("http://localhost:4242/").unwrap(),
@@ -681,4 +683,35 @@ pub mod tests {
681683
pub fn test_ts() -> Timestamp {
682684
Timestamp::new(1731593928).unwrap()
683685
}
686+
687+
#[cfg(test)]
688+
mod config_tests {
689+
use crate::NostrConfig;
690+
691+
#[test]
692+
fn test_nostr_config_default_max_relays() {
693+
let config = NostrConfig::default();
694+
assert_eq!(config.max_relays, Some(50));
695+
}
696+
697+
#[test]
698+
fn test_nostr_config_with_custom_max_relays() {
699+
let config = NostrConfig {
700+
only_known_contacts: true,
701+
relays: vec![],
702+
max_relays: Some(100),
703+
};
704+
assert_eq!(config.max_relays, Some(100));
705+
}
706+
707+
#[test]
708+
fn test_nostr_config_with_no_relay_limit() {
709+
let config = NostrConfig {
710+
only_known_contacts: false,
711+
relays: vec![],
712+
max_relays: None,
713+
};
714+
assert_eq!(config.max_relays, None);
715+
}
716+
}
684717
}

0 commit comments

Comments
 (0)