mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-19 01:24:21 +01:00
add NoteId::from_bech method
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -36,6 +36,16 @@ impl NoteId {
|
||||
pub fn to_bech(&self) -> Option<String> {
|
||||
bech32::encode::<bech32::Bech32>(HRP_NOTE, &self.0).ok()
|
||||
}
|
||||
|
||||
pub fn from_bech(bech: &str) -> Option<Self> {
|
||||
let (hrp, data) = bech32::decode(bech).ok()?;
|
||||
|
||||
if hrp != HRP_NOTE {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(NoteId::new(data.try_into().ok()?))
|
||||
}
|
||||
}
|
||||
|
||||
/// Event is the struct used to represent a Nostr event
|
||||
|
||||
Reference in New Issue
Block a user