feat: add merkle node index

This commit introduces a wrapper structure to encapsulate the merkle
tree traversal.

related issue: #36
This commit is contained in:
Victor Lopez
2023-02-11 12:50:52 +01:00
parent 0c242d2c51
commit 0799b1bb9d
9 changed files with 531 additions and 320 deletions

View File

@@ -5,6 +5,9 @@ use super::{
};
use core::fmt;
mod index;
pub use index::NodeIndex;
mod merkle_tree;
pub use merkle_tree::MerkleTree;
@@ -22,11 +25,11 @@ pub use simple_smt::SimpleSmt;
#[derive(Clone, Debug)]
pub enum MerkleError {
DepthTooSmall(u32),
DepthTooBig(u32),
DepthTooSmall(u8),
DepthTooBig(u8),
NumLeavesNotPowerOfTwo(usize),
InvalidIndex(u32, u64),
InvalidDepth(u32, u32),
InvalidIndex(NodeIndex),
InvalidDepth { expected: u8, provided: u8 },
InvalidPath(MerklePath),
InvalidEntriesCount(usize, usize),
NodeNotInSet(u64),
@@ -41,11 +44,11 @@ impl fmt::Display for MerkleError {
NumLeavesNotPowerOfTwo(leaves) => {
write!(f, "the leaves count {leaves} is not a power of 2")
}
InvalidIndex(depth, index) => write!(
InvalidIndex(index) => write!(
f,
"the leaf index {index} is not valid for the depth {depth}"
"the index value {} is not valid for the depth {}", index.value(), index.depth()
),
InvalidDepth(expected, provided) => write!(
InvalidDepth { expected, provided } => write!(
f,
"the provided depth {provided} is not valid for {expected}"
),