@@ -9,8 +9,12 @@ use crate::{
99use async_trait:: async_trait;
1010use bcr_common:: core:: NodeId ;
1111use bcr_ebill_core:: {
12- protocol:: Timestamp , protocol:: blockchain:: BlockchainType ,
13- protocol:: blockchain:: bill:: participant:: BillParticipant , protocol:: crypto:: BcrKeys ,
12+ application:: nostr_contact:: { NostrContact , TrustLevel } ,
13+ protocol:: {
14+ Timestamp ,
15+ blockchain:: { BlockchainType , bill:: participant:: BillParticipant } ,
16+ crypto:: BcrKeys ,
17+ } ,
1418} ;
1519use bitcoin:: base58;
1620use log:: { debug, error, info, trace, warn} ;
@@ -27,7 +31,7 @@ use std::{
2731} ;
2832
2933use bcr_ebill_api:: {
30- constants:: NOSTR_EVENT_TIME_SLACK ,
34+ constants:: { NOSTR_EVENT_TIME_SLACK , NOSTR_MAX_RELAYS } ,
3135 service:: {
3236 contact_service:: ContactServiceApi ,
3337 transport_service:: {
@@ -358,8 +362,8 @@ impl NostrClient {
358362 let current_relays: HashSet < url:: Url > = client
359363 . relays ( )
360364 . await
361- . into_iter ( )
362- . filter_map ( | ( _ , relay ) | relay . url ( ) . as_str ( ) . parse :: < url :: Url > ( ) . ok ( ) )
365+ . keys ( )
366+ . map ( |url| url. to_owned ( ) . into ( ) )
363367 . collect ( ) ;
364368
365369 // Add new relays
@@ -1353,12 +1357,9 @@ mod tests {
13531357/// Internal relay calculation function (pure function for testing)
13541358fn calculate_relay_set_internal (
13551359 user_relays : & [ url:: Url ] ,
1356- contacts : & [ bcr_ebill_core :: application :: nostr_contact :: NostrContact ] ,
1360+ contacts : & [ NostrContact ] ,
13571361 max_relays : Option < usize > ,
13581362) -> HashSet < url:: Url > {
1359- use bcr_ebill_core:: application:: nostr_contact:: TrustLevel ;
1360- use std:: collections:: HashSet ;
1361-
13621363 let mut relay_set = HashSet :: new ( ) ;
13631364
13641365 // Pass 1: Add all user relays (exempt from limit)
@@ -1367,11 +1368,10 @@ fn calculate_relay_set_internal(
13671368 }
13681369
13691370 // Filter and sort contacts by trust level
1370- let mut eligible_contacts: Vec < & bcr_ebill_core:: application:: nostr_contact:: NostrContact > =
1371- contacts
1372- . iter ( )
1373- . filter ( |c| matches ! ( c. trust_level, TrustLevel :: Trusted | TrustLevel :: Participant ) )
1374- . collect ( ) ;
1371+ let mut eligible_contacts: Vec < & NostrContact > = contacts
1372+ . iter ( )
1373+ . filter ( |c| matches ! ( c. trust_level, TrustLevel :: Trusted | TrustLevel :: Participant ) )
1374+ . collect ( ) ;
13751375
13761376 // Sort: Trusted (0) before Participant (1)
13771377 eligible_contacts. sort_by_key ( |c| match c. trust_level {
@@ -1380,7 +1380,7 @@ fn calculate_relay_set_internal(
13801380 _ => 2 , // unreachable due to filter
13811381 } ) ;
13821382
1383- let contact_relay_limit = max_relays. unwrap_or ( usize :: MAX ) ;
1383+ let contact_relay_limit = NOSTR_MAX_RELAYS . min ( max_relays. unwrap_or ( NOSTR_MAX_RELAYS ) ) ;
13841384 let user_relay_count = relay_set. len ( ) ;
13851385
13861386 // Pass 2: Add first relay from each contact (priority order)
0 commit comments