Skip to content

Commit 936219e

Browse files
committed
nostr: update nip17::extract_relay_list and nip17::extract_owned_relay_list behavior and output
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 03114ff commit 936219e

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

crates/nostr/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
## Unreleased
2727

28+
### Breaking changes
29+
30+
- Change the output and behavior of nip17::extract_relay_list and nip17::extract_owned_relay_list functions
31+
2832
### Changed
2933

3034
- Rename `NostrWalletConnectURI` to `NostrWalletConnectUri`

crates/nostr/src/nips/nip17.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,30 @@
66
//!
77
//! <https://github.com/nostr-protocol/nips/blob/master/17.md>
88
9-
use alloc::boxed::Box;
10-
use core::iter;
11-
12-
use crate::{Event, Kind, RelayUrl, TagStandard};
9+
use crate::{Event, RelayUrl, TagStandard};
1310

1411
/// Extracts the relay list
15-
pub fn extract_relay_list<'a>(event: &'a Event) -> Box<dyn Iterator<Item = &'a RelayUrl> + 'a> {
16-
if event.kind != Kind::InboxRelays {
17-
return Box::new(iter::empty());
18-
}
19-
20-
Box::new(event.tags.iter().filter_map(|tag| {
12+
///
13+
/// This function doesn't verify if the event kind is [`Kind::InboxRelays`](crate::Kind::InboxRelays)!
14+
pub fn extract_relay_list(event: &Event) -> impl Iterator<Item = &RelayUrl> {
15+
event.tags.iter().filter_map(|tag| {
2116
if let Some(TagStandard::Relay(url)) = tag.as_standardized() {
2217
Some(url)
2318
} else {
2419
None
2520
}
26-
}))
21+
})
2722
}
2823

2924
/// Extracts the relay list
30-
pub fn extract_owned_relay_list(event: Event) -> Box<dyn Iterator<Item = RelayUrl>> {
31-
if event.kind != Kind::InboxRelays {
32-
return Box::new(iter::empty());
33-
}
34-
35-
Box::new(event.tags.into_iter().filter_map(|tag| {
25+
///
26+
/// This function doesn't verify if the event kind is [`Kind::InboxRelays`](crate::Kind::InboxRelays)!
27+
pub fn extract_owned_relay_list(event: Event) -> impl Iterator<Item = RelayUrl> {
28+
event.tags.into_iter().filter_map(|tag| {
3629
if let Some(TagStandard::Relay(url)) = tag.to_standardized() {
3730
Some(url)
3831
} else {
3932
None
4033
}
41-
}))
34+
})
4235
}

0 commit comments

Comments
 (0)