Skip to content

Commit cc6e2a0

Browse files
committed
Write ChannelIds 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`.
1 parent 91a60c8 commit cc6e2a0

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lightning/src/ln/types.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use bitcoin::hashes::{
3030
HashEngine as _,
3131
sha256::Hash as Sha256,
3232
};
33+
use bitcoin::hex::display::impl_fmt_traits;
3334
use core::borrow::Borrow;
34-
use core::fmt;
3535
use core::ops::Deref;
3636

3737
/// A unique 32-byte identifier for a channel.
@@ -42,7 +42,7 @@ use core::ops::Deref;
4242
/// A _temporary_ ID is generated randomly.
4343
/// (Later revocation-point-based _v2_ is a possibility.)
4444
/// The variety (context) is not stored, it is relevant only at creation.
45-
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
45+
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
4646
pub struct ChannelId(pub [u8; 32]);
4747

4848
impl ChannelId {
@@ -122,18 +122,18 @@ impl Readable for ChannelId {
122122
}
123123
}
124124

125-
impl fmt::Display for ChannelId {
126-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
127-
crate::util::logger::DebugBytes(&self.0).fmt(f)
128-
}
129-
}
130-
131125
impl Borrow<[u8]> for ChannelId {
132126
fn borrow(&self) -> &[u8] {
133127
&self.0[..]
134128
}
135129
}
136130

131+
impl_fmt_traits! {
132+
impl fmt_traits for ChannelId {
133+
const LENGTH: usize = 32;
134+
}
135+
}
136+
137137
pub use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
138138

139139
#[cfg(test)]

0 commit comments

Comments
 (0)