From 7447a599f7d01ce1e99b7524dd6262d57bedb3c4 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 5 Apr 2022 17:51:42 +0000 Subject: [PATCH 1/2] zcash_primitives: Show hex encoding of `TxId` in its `Debug` impl The (byte-flipped) hex string is more useful than the raw bytes, because we can look that up in RPC methods and block explorers. --- zcash_primitives/src/transaction/mod.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/zcash_primitives/src/transaction/mod.rs b/zcash_primitives/src/transaction/mod.rs index 885116b32..2495822e6 100644 --- a/zcash_primitives/src/transaction/mod.rs +++ b/zcash_primitives/src/transaction/mod.rs @@ -61,9 +61,18 @@ const ZFUTURE_VERSION_GROUP_ID: u32 = 0xFFFFFFFF; #[cfg(feature = "zfuture")] const ZFUTURE_TX_VERSION: u32 = 0x0000FFFF; -#[derive(Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)] +#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash)] pub struct TxId([u8; 32]); +impl fmt::Debug for TxId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // The (byte-flipped) hex string is more useful than the raw bytes, because we can + // look that up in RPC methods and block explorers. + let txid_str = self.to_string(); + f.debug_tuple("TxId").field(&txid_str).finish() + } +} + impl fmt::Display for TxId { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { let mut data = self.0; From 6e8c457e30dbdf9dc91cdb667ebccf5186d50195 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 5 Apr 2022 17:55:56 +0000 Subject: [PATCH 2/2] zcash_primitives: Show hex encoding of `BlockHash` in its `Debug` impl The (byte-flipped) hex string is more useful than the raw bytes, because we can look that up in RPC methods and block explorers. --- zcash_primitives/src/block.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/zcash_primitives/src/block.rs b/zcash_primitives/src/block.rs index 1304192d6..8ded03fc4 100644 --- a/zcash_primitives/src/block.rs +++ b/zcash_primitives/src/block.rs @@ -9,9 +9,18 @@ use zcash_encoding::Vector; pub use equihash; -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, Hash)] pub struct BlockHash(pub [u8; 32]); +impl fmt::Debug for BlockHash { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // The (byte-flipped) hex string is more useful than the raw bytes, because we can + // look that up in RPC methods and block explorers. + let block_hash_str = self.to_string(); + f.debug_tuple("BlockHash").field(&block_hash_str).finish() + } +} + impl fmt::Display for BlockHash { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { let mut data = self.0;