Add several Debug impls for existing types

Resolves #237
This commit is contained in:
Deirdre Connolly 2020-02-07 14:53:44 -06:00 committed by Henry de Valence
parent 866acde6e8
commit 824f206dbe
3 changed files with 31 additions and 5 deletions

View File

@ -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<Transaction> ZcashDeserialize for MerkleTree<Transaction> {
/// 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<MerkleTree<Transaction>> 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()
}
}

View File

@ -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<SaplingNoteCommitmentTree> for SaplingNoteTreeRootHash {
fn from(_tree: SaplingNoteCommitmentTree) -> Self {
// TODO: The Sapling note commitment tree requires a Pedersen

View File

@ -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<u8>);
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<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
writer.write_compactsize(self.0.len() as u64)?;