Skip to content

Commit

Permalink
add relays_iter to bech32_{nprofile,nevent,naddr}
Browse files Browse the repository at this point in the history
  • Loading branch information
ksedgwic committed Feb 4, 2025
1 parent c083372 commit ad3b345
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ impl bindings::bech32_nprofile {
pub fn pubkey(&self) -> &[u8; 32] {
unsafe { &*(self.pubkey as *const [u8; 32]) }
}

pub fn relays_iter(&self) -> impl Iterator<Item = &str> {
self.relays.relays[0..(self.relays.num_relays as usize)]
.iter()
.map(|block| block.as_str())
}
}

impl bindings::bech32_npub {
Expand Down Expand Up @@ -98,6 +104,20 @@ impl bindings::bech32_nevent {
Some(&*(self.pubkey as *const [u8; 32]))
}
}

pub fn relays_iter(&self) -> impl Iterator<Item = &str> {
self.relays.relays[0..(self.relays.num_relays as usize)]
.iter()
.map(|block| block.as_str())
}
}

impl bindings::bech32_naddr {
pub fn relays_iter(&self) -> impl Iterator<Item = &str> {
self.relays.relays[0..(self.relays.num_relays as usize)]
.iter()
.map(|block| block.as_str())
}
}

impl<'a> Mention<'a> {
Expand Down Expand Up @@ -421,6 +441,8 @@ mod tests {
assert_eq!(p.relays.num_relays, 2);
assert_eq!(p.relays.relays[0].as_str(), "wss://r.x.com");
assert_eq!(p.relays.relays[1].as_str(), "wss://djbas.sadkb.com");
let relays: Vec<&str> = p.relays_iter().collect();
assert_eq!(relays, vec!["wss://r.x.com", "wss://djbas.sadkb.com"]);
nprofile_check = true;
}
}
Expand Down

0 comments on commit ad3b345

Please sign in to comment.