Skip to content

Commit

Permalink
nostr: better Debug trait impl for EventId, PublicKey and Tag
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Aug 8, 2024
1 parent 6ffebcb commit 852631a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* nostr: add NIP-50 support to `Filter::match_event` method ([Yuki Kishimoto])
* nostr: remove `Arc<T>` from `OnceCell<T>` in `Event` and `Tag` ([Yuki Kishimoto])
* nostr: move `sig` field from `PartialEvent` to `MissingPartialEvent` ([Yuki Kishimoto])
* nostr: better `Debug` trait impl for `EventId`, `PublicKey` and `Tag` ([Yuki Kishimoto])
* pool: take mutex ownership instead of clone in `InternalRelayPool::get_events_from` ([Yuki Kishimoto])
* pool: remove IDs collection from `InternalRelayPool::get_events_from` ([Yuki Kishimoto])
* pool: better checks before perform queries or send messages to relays ([Yuki Kishimoto])
Expand Down
8 changes: 7 additions & 1 deletion crates/nostr/src/event/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ impl From<hex::Error> for Error {
/// 32-bytes lowercase hex-encoded sha256 of the serialized event data
///
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct EventId([u8; 32]);

impl fmt::Debug for EventId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "EventId({})", self.to_hex())
}
}

impl EventId {
/// Event ID len
pub const LEN: usize = 32;
Expand Down
9 changes: 8 additions & 1 deletion crates/nostr/src/event/tag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::cmp::Ordering;
use core::fmt;
use core::hash::{Hash, Hasher};

#[cfg(feature = "std")]
Expand All @@ -33,12 +34,18 @@ use crate::types::url::Url;
use crate::{ImageDimensions, PublicKey, SingleLetterTag, Timestamp, UncheckedUrl};

/// Tag
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Tag {
buf: Vec<String>,
standardized: OnceCell<Option<TagStandard>>,
}

impl fmt::Debug for Tag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Tag").field(&self.buf).finish()
}
}

impl PartialEq for Tag {
fn eq(&self, other: &Self) -> bool {
self.buf == other.buf
Expand Down
2 changes: 1 addition & 1 deletion crates/nostr/src/key/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl From<XOnlyPublicKey> for PublicKey {

impl fmt::Debug for PublicKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("PublicKey").field(&self.to_bytes()).finish()
write!(f, "PublicKey({})", self.to_hex())
}
}

Expand Down

0 comments on commit 852631a

Please sign in to comment.