Skip to content

Commit

Permalink
nostr: add event_ids method to Event
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Oct 27, 2023
1 parent 5850bca commit 1469810
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions crates/nostr/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,24 @@ impl Event {
}

/// Extract public keys from tags (`p` tag)
pub fn public_keys(&self) -> Vec<&XOnlyPublicKey> {
let mut public_keys: Vec<&XOnlyPublicKey> = Vec::new();
for tag in self.tags.iter() {
if let Tag::PubKey(public_key, ..) = tag {
public_keys.push(public_key);
}
}
public_keys
///
/// **This method extract ONLY `Tag::PubKey` and `Tag::ContactList`**
pub fn public_keys(&self) -> impl Iterator<Item = &XOnlyPublicKey> {
self.tags.iter().filter_map(|t| match t {
Tag::PubKey(pk, ..) => Some(pk),
Tag::ContactList { pk, .. } => Some(pk),
_ => None,
})
}

/// Extract event IDs from tags (`e` tag)
///
/// **This method extract ONLY `Tag::Event`**
pub fn event_ids(&self) -> impl Iterator<Item = &EventId> {
self.tags.iter().filter_map(|t| match t {
Tag::Event(id, ..) => Some(id),
_ => None,
})
}
}

Expand Down

0 comments on commit 1469810

Please sign in to comment.