Skip to content

Commit

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

pub fn relays_to_strings(&self) -> Vec<String> {
self.relays.relays[0..(self.relays.num_relays as usize)]
.iter()
.map(|block| block.as_str().to_string())
.collect()
}
}

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

pub fn relays_to_strings(&self) -> Vec<String> {
self.relays.relays[0..(self.relays.num_relays as usize)]
.iter()
.map(|block| block.as_str().to_string())
.collect()
}
}

impl bindings::bech32_naddr {
pub fn relays_to_strings(&self) -> Vec<String> {
self.relays.relays[0..(self.relays.num_relays as usize)]
.iter()
.map(|block| block.as_str().to_string())
.collect()
}
}

impl<'a> Mention<'a> {
Expand Down Expand Up @@ -421,6 +444,10 @@ 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");
assert_eq!(
p.relays_to_strings(),
vec!["wss://r.x.com", "wss://djbas.sadkb.com"]
);
nprofile_check = true;
}
}
Expand Down

0 comments on commit 6383c8d

Please sign in to comment.