From 646b506e7adb66e26544713d69ee9dffba35e07f Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Wed, 12 Aug 2020 02:51:11 -0400 Subject: [PATCH] Whoops forgot to add sprout::NoteTreeRootHash --- zebra-chain/src/treestate/sprout.rs | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 zebra-chain/src/treestate/sprout.rs diff --git a/zebra-chain/src/treestate/sprout.rs b/zebra-chain/src/treestate/sprout.rs new file mode 100644 index 00000000..11337742 --- /dev/null +++ b/zebra-chain/src/treestate/sprout.rs @@ -0,0 +1,47 @@ +//! Note Commitment Trees. +//! +//! A note commitment tree is an incremental Merkle tree of fixed depth +//! used to store note commitments that JoinSplit transfers or Spend +//! transfers produce. Just as the unspent transaction output set (UTXO +//! set) used in Bitcoin, it is used to express the existence of value and +//! the capability to spend it. However, unlike the UTXO set, it is not +//! the job of this tree to protect against double-spending, as it is +//! append-only. +//! +//! A root of a note commitment tree is associated with each treestate. +#![allow(clippy::unit_arg)] + +use std::fmt; + +#[cfg(test)] +use proptest_derive::Arbitrary; + +/// Sprout note commitment tree root node hash. +/// +/// The root hash in LEBS2OSP256(rt) encoding of the Sprout note +/// commitment tree corresponding to the final Sprout treestate of +/// this block. A root of a note commitment tree is associated with +/// each treestate. +#[derive(Clone, Copy, Default, Eq, PartialEq, Serialize, Deserialize)] +#[cfg_attr(test, derive(Arbitrary))] +pub struct NoteTreeRootHash([u8; 32]); + +impl fmt::Debug for NoteTreeRootHash { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("SproutNoteTreeRootHash") + .field(&hex::encode(&self.0)) + .finish() + } +} + +impl From<[u8; 32]> for NoteTreeRootHash { + fn from(bytes: [u8; 32]) -> NoteTreeRootHash { + Self(bytes) + } +} + +impl From for [u8; 32] { + fn from(rt: NoteTreeRootHash) -> [u8; 32] { + rt.0 + } +}