From: Matt Corallo Date: Mon, 9 Sep 2024 15:30:54 +0000 (+0000) Subject: Write `ChannelId`s out as hex in `Debug` output X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=cc6e2a0f7af60b0809dd9ff849bd3a41d3a78d3f;p=rust-lightning Write `ChannelId`s out as hex in `Debug` output `ChannelId`s are almost always referenced as hex, so having debug output print the raw bytes is somewhat annoying. Instead, we should dump them as hex the same way we do for `Display`. This uses the `hex_conservative` `impl_fmt_macros` which does all the work for us, like we use for `lightning_types`. --- diff --git a/lightning/src/ln/types.rs b/lightning/src/ln/types.rs index 9d56ad46d..dbe1e216b 100644 --- a/lightning/src/ln/types.rs +++ b/lightning/src/ln/types.rs @@ -30,8 +30,8 @@ use bitcoin::hashes::{ HashEngine as _, sha256::Hash as Sha256, }; +use bitcoin::hex::display::impl_fmt_traits; use core::borrow::Borrow; -use core::fmt; use core::ops::Deref; /// A unique 32-byte identifier for a channel. @@ -42,7 +42,7 @@ use core::ops::Deref; /// A _temporary_ ID is generated randomly. /// (Later revocation-point-based _v2_ is a possibility.) /// The variety (context) is not stored, it is relevant only at creation. -#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct ChannelId(pub [u8; 32]); impl ChannelId { @@ -122,18 +122,18 @@ impl Readable for ChannelId { } } -impl fmt::Display for ChannelId { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - crate::util::logger::DebugBytes(&self.0).fmt(f) - } -} - impl Borrow<[u8]> for ChannelId { fn borrow(&self) -> &[u8] { &self.0[..] } } +impl_fmt_traits! { + impl fmt_traits for ChannelId { + const LENGTH: usize = 32; + } +} + pub use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret}; #[cfg(test)]