From 56132f59d56782d200a9d5eec78336c1f5e55fec Mon Sep 17 00:00:00 2001 From: 448 OG Date: Sun, 10 Mar 2024 14:16:12 +0300 Subject: [PATCH] Remove the `:#` formatting for `hex_fmt_impl` macro This fixes the issue where pretty debug like `dbg` or `{:#}` introduce the use of `0x` prefix to hex encoded transaction ID. The transaction id is being forced to pretty print inside the `hex_fmt_impl` macro using `{:#}` in the line `write!(f, "{:#}", self)` debug formatter. Resolves: #2505 --- bitcoin/src/blockdata/transaction.rs | 23 +++++++++++++++++++++++ hashes/src/util.rs | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index f957e702..7e336de6 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -2444,6 +2444,29 @@ mod tests { let seq = Sequence::from_seconds_floor(1000); println!("{:?}", seq) } + + #[test] + fn outpoint_format() { + let outpoint = OutPoint::default(); + + let debug = "OutPoint { txid: 0000000000000000000000000000000000000000000000000000000000000000, vout: 4294967295 }"; + assert_eq!(debug, format!("{:?}", &outpoint)); + + let display = "0000000000000000000000000000000000000000000000000000000000000000:4294967295"; + assert_eq!(display, format!("{}", &outpoint)); + + let pretty_debug = "OutPoint {\n txid: 0000000000000000000000000000000000000000000000000000000000000000,\n vout: 4294967295,\n}"; + assert_eq!(pretty_debug, format!("{:#?}", &outpoint)); + + let debug_txid = "0000000000000000000000000000000000000000000000000000000000000000"; + assert_eq!(debug_txid, format!("{:?}", &outpoint.txid)); + + let display_txid = "0000000000000000000000000000000000000000000000000000000000000000"; + assert_eq!(display_txid, format!("{}", &outpoint.txid)); + + let pretty_txid = "0x0000000000000000000000000000000000000000000000000000000000000000"; + assert_eq!(pretty_txid, format!("{:#}", &outpoint.txid)); + } } #[cfg(bench)] diff --git a/hashes/src/util.rs b/hashes/src/util.rs index 92fd4855..813562a1 100644 --- a/hashes/src/util.rs +++ b/hashes/src/util.rs @@ -39,7 +39,7 @@ macro_rules! hex_fmt_impl( impl<$($gen: $gent),*> $crate::_export::_core::fmt::Debug for $ty<$($gen),*> { #[inline] fn fmt(&self, f: &mut $crate::_export::_core::fmt::Formatter) -> $crate::_export::_core::fmt::Result { - write!(f, "{:#}", self) + write!(f, "{}", self) } } );