Skip to content

Commit

Permalink
nostr: add Event::coordinates method
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Dec 4, 2023
1 parent c8f8c44 commit 3985caa
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/nostr/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub use self::kind::Kind;
pub use self::partial::{MissingPartialEvent, PartialEvent};
pub use self::tag::{Marker, Tag, TagIndexValues, TagIndexes, TagKind};
pub use self::unsigned::UnsignedEvent;
use crate::nips::nip01::Coordinate;
#[cfg(feature = "std")]
use crate::types::time::Instant;
use crate::types::time::TimeSupplier;
Expand Down Expand Up @@ -292,6 +293,24 @@ impl Event {
})
}

/// Extract coordinates from tags (`a` tag)
pub fn coordinates(&self) -> impl Iterator<Item = Coordinate> + '_ {
self.tags.iter().filter_map(|t| match t {
Tag::A {
kind,
public_key,
identifier,
..
} => Some(Coordinate {
kind: *kind,
pubkey: *public_key,
identifier: identifier.clone(),
relays: Vec::new(),
}),
_ => None,
})
}

/// Build tags index
pub fn build_tags_index(&self) -> TagIndexes {
TagIndexes::from(self.tags.iter().map(|t| t.as_vec()))
Expand Down

0 comments on commit 3985caa

Please sign in to comment.