Skip to content

Commit ab21b35

Browse files
committed
nostr: impl ToBech32 and ToNostrUri for Event
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 0a5ba88 commit ab21b35

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

crates/nostr/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
- Implement `ToNostrUri` for `Coordinate`
4949
- Implement `ToBech32` for `CoordinateBorrow`
5050
- Implement `ToNostrUri` for `CoordinateBorrow`
51+
- Implement `ToBech32` for `Event`
52+
- Implement `ToNostrUri` for `Event`
5153
- Implement `From<&Event>` for `Nip19Event`
5254
- Add `CowTag::kind` and `CowTag::content`
5355
- Add `Timestamp::as_secs`

crates/nostr/src/event/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub use self::kind::Kind;
3131
pub use self::tag::{Tag, TagKind, TagStandard, Tags};
3232
pub use self::unsigned::UnsignedEvent;
3333
use crate::nips::nip01::CoordinateBorrow;
34+
use crate::nips::nip19::{self, Nip19Event, ToBech32};
35+
use crate::nips::nip21::ToNostrUri;
3436
#[cfg(feature = "std")]
3537
use crate::types::time::Instant;
3638
use crate::types::time::TimeSupplier;
@@ -294,6 +296,19 @@ impl JsonUtil for Event {
294296
}
295297
}
296298

299+
impl ToBech32 for Event {
300+
type Err = nip19::Error;
301+
302+
fn to_bech32(&self) -> Result<String, Self::Err> {
303+
match self.coordinate() {
304+
Some(coordinate) => coordinate.to_bech32(),
305+
None => Nip19Event::from(self).to_bech32(),
306+
}
307+
}
308+
}
309+
310+
impl ToNostrUri for Event {}
311+
297312
impl TryFrom<&Event> for Metadata {
298313
type Error = serde_json::Error;
299314

0 commit comments

Comments
 (0)