From 824f206dbea68c7160c9112ec56bf7804fba4d8c Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 7 Feb 2020 14:53:44 -0600 Subject: [PATCH] Add several Debug impls for existing types Resolves #237 --- zebra-chain/src/merkle_tree.rs | 12 ++++++++++-- zebra-chain/src/note_commitment_tree.rs | 14 ++++++++++++-- zebra-chain/src/types.rs | 10 +++++++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/zebra-chain/src/merkle_tree.rs b/zebra-chain/src/merkle_tree.rs index b9e2292a..54cf4846 100644 --- a/zebra-chain/src/merkle_tree.rs +++ b/zebra-chain/src/merkle_tree.rs @@ -1,7 +1,7 @@ //! A binary hash tree of SHA256d (two rounds of SHA256) hashes for //! node values. -use std::io; +use std::{fmt, io}; #[cfg(test)] use proptest_derive::Arbitrary; @@ -31,7 +31,7 @@ impl ZcashDeserialize for MerkleTree { /// A SHA-256d hash of the root node of a merkle tree of SHA256-d /// hashed transactions in a block. -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Eq, PartialEq)] #[cfg_attr(test, derive(Arbitrary))] pub struct MerkleTreeRootHash(pub [u8; 32]); @@ -44,3 +44,11 @@ impl From> for MerkleTreeRootHash { Self(hash_writer.finish()) } } + +impl fmt::Debug for MerkleTreeRootHash { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("MerkleTreeRootHash") + .field(&hex::encode(&self.0)) + .finish() + } +} diff --git a/zebra-chain/src/note_commitment_tree.rs b/zebra-chain/src/note_commitment_tree.rs index fdecee26..975e02bf 100644 --- a/zebra-chain/src/note_commitment_tree.rs +++ b/zebra-chain/src/note_commitment_tree.rs @@ -10,7 +10,9 @@ //! //! A root of a note commitment tree is associated with each treestate. -use std::io; +use std::{fmt, io}; + +use hex; #[cfg(test)] use proptest_derive::Arbitrary; @@ -31,10 +33,18 @@ pub struct SaplingNoteCommitmentTree; /// commitment tree corresponding to the final Sapling treestate of /// this block. A root of a note commitment tree is associated with /// each treestate. -#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] +#[derive(Clone, Copy, Default, Eq, PartialEq)] #[cfg_attr(test, derive(Arbitrary))] pub struct SaplingNoteTreeRootHash(pub [u8; 32]); +impl fmt::Debug for SaplingNoteTreeRootHash { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("SaplingNoteTreeRootHash") + .field(&hex::encode(&self.0)) + .finish() + } +} + impl From for SaplingNoteTreeRootHash { fn from(_tree: SaplingNoteCommitmentTree) -> Self { // TODO: The Sapling note commitment tree requires a Pedersen diff --git a/zebra-chain/src/types.rs b/zebra-chain/src/types.rs index f746c188..bd15a73e 100644 --- a/zebra-chain/src/types.rs +++ b/zebra-chain/src/types.rs @@ -101,10 +101,18 @@ impl Arbitrary for LockTime { } /// An encoding of a Bitcoin script. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Eq, PartialEq)] #[cfg_attr(test, derive(Arbitrary))] pub struct Script(pub Vec); +impl fmt::Debug for Script { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("Script") + .field(&hex::encode(&self.0)) + .finish() + } +} + impl ZcashSerialize for Script { fn zcash_serialize(&self, mut writer: W) -> Result<(), io::Error> { writer.write_compactsize(self.0.len() as u64)?;