Skip to content

Commit 5f7cba4

Browse files
committed
nostr: update Nip19Profile::new and Nip19Coordinate::new signature
Pull-Request: #910 Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
1 parent fde1123 commit 5f7cba4

File tree

4 files changed

+27
-30
lines changed

4 files changed

+27
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- nostr: remove `NostrConnectMethod::GetRelays`, `NostrConnectRequest::GetRelays` and `ResponseResult::GetRelays` ([Yuki Kishimoto] at https://github.com/rust-nostr/nostr/pull/894)
3131
- nostr: remove `Market::Mention` (NIP-10) ([Yuki Kishimoto] at https://github.com/rust-nostr/nostr/pull/895)
3232
- nostr: remove `parser` feature ([Yuki Kishimoto] at https://github.com/rust-nostr/nostr/pull/899)
33+
- nostr: update `Nip19Profile::new` and `Nip19Coordinate::new` signature ([Yuki Kishimoto] at https://github.com/rust-nostr/nostr/pull/910)
3334
- connect: remove `NostrConnect::get_relays` ([Yuki Kishimoto] at https://github.com/rust-nostr/nostr/pull/894)
3435

3536
### Changed

crates/nostr/examples/nip19.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ use nostr::prelude::*;
77
fn main() -> Result<()> {
88
let pubkey =
99
PublicKey::from_hex("3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d")?;
10-
let profile =
11-
Nip19Profile::new(pubkey, vec!["wss://r.x.com", "wss://djbas.sadkb.com"]).unwrap();
10+
let profile = Nip19Profile::new(
11+
pubkey,
12+
[
13+
RelayUrl::parse("wss://r.x.com").unwrap(),
14+
RelayUrl::parse("wss://djbas.sadkb.com").unwrap(),
15+
],
16+
);
1217
println!("{}", profile.to_bech32()?);
1318

1419
Ok(())

crates/nostr/src/nips/nip19.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use super::nip05::Nip05Profile;
2424
#[cfg(feature = "nip49")]
2525
use super::nip49::{self, EncryptedSecretKey};
2626
use crate::event::id::EventId;
27-
use crate::types::url::{self, RelayUrl, TryIntoUrl};
27+
use crate::types::url::{self, RelayUrl};
2828
use crate::{event, key, Event, Kind, PublicKey, SecretKey};
2929

3030
pub const PREFIX_BECH32_SECRET_KEY: &str = "nsec";
@@ -559,19 +559,14 @@ pub struct Nip19Profile {
559559
}
560560

561561
impl Nip19Profile {
562-
pub fn new<I, U>(public_key: PublicKey, relays: I) -> Result<Self, Error>
562+
pub fn new<I>(public_key: PublicKey, relays: I) -> Self
563563
where
564-
I: IntoIterator<Item = U>,
565-
U: TryIntoUrl,
566-
Error: From<<U as TryIntoUrl>::Err>,
564+
I: IntoIterator<Item = RelayUrl>,
567565
{
568-
Ok(Self {
566+
Self {
569567
public_key,
570-
relays: relays
571-
.into_iter()
572-
.map(|u| u.try_into_url())
573-
.collect::<Result<_, _>>()?,
574-
})
568+
relays: relays.into_iter().collect(),
569+
}
575570
}
576571

577572
fn from_bech32_data(mut data: Vec<u8>) -> Result<Self, Error> {
@@ -678,18 +673,13 @@ impl Deref for Nip19Coordinate {
678673
}
679674

680675
impl Nip19Coordinate {
681-
pub fn new<I, U>(coordinate: Coordinate, relays: I) -> Result<Self, Error>
676+
pub fn new<I>(coordinate: Coordinate, relays: I) -> Result<Self, Error>
682677
where
683-
I: IntoIterator<Item = U>,
684-
U: TryIntoUrl,
685-
Error: From<<U as TryIntoUrl>::Err>,
678+
I: IntoIterator<Item = RelayUrl>,
686679
{
687680
Ok(Self {
688681
coordinate,
689-
relays: relays
690-
.into_iter()
691-
.map(|u| u.try_into_url())
692-
.collect::<Result<_, _>>()?,
682+
relays: relays.into_iter().collect(),
693683
})
694684
}
695685

@@ -861,13 +851,13 @@ mod tests {
861851
.unwrap();
862852

863853
assert_eq!(
864-
Nip19::Profile(
865-
Nip19Profile::new(
866-
expected_pubkey,
867-
["wss://r.x.com/", "wss://djbas.sadkb.com/"]
868-
)
869-
.unwrap()
870-
),
854+
Nip19::Profile(Nip19Profile::new(
855+
expected_pubkey,
856+
[
857+
RelayUrl::parse("wss://r.x.com/").unwrap(),
858+
RelayUrl::parse("wss://djbas.sadkb.com/").unwrap()
859+
],
860+
)),
871861
nip19
872862
);
873863

crates/nostr/src/nips/nip21.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ fn take_valid_bech32(prefix: Nip19Prefix, full_input: &str) -> Option<&str> {
273273
#[cfg(test)]
274274
mod tests {
275275
use super::*;
276+
use crate::types::RelayUrl;
276277

277278
#[test]
278279
fn test_to_nostr_uri() {
@@ -317,8 +318,8 @@ mod tests {
317318
"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245",
318319
)
319320
.unwrap(),
320-
["wss://relay.damus.io/"]
321-
).unwrap()),
321+
[RelayUrl::parse("wss://relay.damus.io/").unwrap()]
322+
)),
322323
);
323324
}
324325

0 commit comments

Comments
 (0)