Skip to content

Commit

Permalink
nostr: refactor NIP19 relay URL parsing logic
Browse files Browse the repository at this point in the history
Update NIP19 relay URL parsing to use `str::from_utf8` and handle potential parsing errors gracefully. This improves code efficiency and error handling by eliminating unnecessary allocation.

Closes #649

Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Nov 27, 2024
1 parent fa54497 commit ec790f4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions crates/nostr/src/nips/nip19.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,10 @@ impl Nip19Profile {
}
}
RELAY => {
let url = String::from_utf8(bytes.to_vec())?;
let url = RelayUrl::parse(&url)?;
relays.push(url);
let url: &str = str::from_utf8(bytes)?;
if let Ok(url) = RelayUrl::parse(url) {
relays.push(url);
}
}
_ => (),
};
Expand Down Expand Up @@ -673,8 +674,10 @@ impl Coordinate {
}
}
RELAY => {
let url = String::from_utf8(bytes.to_vec())?;
relays.push(RelayUrl::parse(url)?);
let url: &str = str::from_utf8(bytes)?;
if let Ok(url) = RelayUrl::parse(url) {
relays.push(url);
}
}
AUTHOR => {
if pubkey.is_none() {
Expand Down

0 comments on commit ec790f4

Please sign in to comment.