pub struct MerkleTree {
pub nodes: Vec<[u8; 32]>,
pub leaf_count: usize,
pub root: [u8; 32],
}Fields§
§nodes: Vec<[u8; 32]>All nodes: leaves first, then internal nodes bottom-up. Root is last.
leaf_count: usize§root: [u8; 32]Implementations§
Source§impl MerkleTree
impl MerkleTree
Sourcepub fn verify_leaf(&self, index: usize, data: &[u8]) -> bool
pub fn verify_leaf(&self, index: usize, data: &[u8]) -> bool
Verify a single leaf at index against stored hash.
Sourcepub fn proof(&self, index: usize) -> Vec<([u8; 32], bool)>
pub fn proof(&self, index: usize) -> Vec<([u8; 32], bool)>
Get Merkle proof path for a leaf. Returns Vec of (sibling_hash, is_right) pairs from leaf to root.
Sourcepub fn verify_proof(
root: &[u8; 32],
leaf_data: &[u8],
proof: &[([u8; 32], bool)],
) -> bool
pub fn verify_proof( root: &[u8; 32], leaf_data: &[u8], proof: &[([u8; 32], bool)], ) -> bool
Verify a Merkle proof against a known root.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serialize tree to bytes. Format: [u32 leaf_count][u32 node_count][nodes: 32 bytes each]
Sourcepub fn from_bytes(data: &[u8]) -> Option<Self>
pub fn from_bytes(data: &[u8]) -> Option<Self>
Deserialize from bytes.
Auto Trait Implementations§
impl Freeze for MerkleTree
impl RefUnwindSafe for MerkleTree
impl Send for MerkleTree
impl Sync for MerkleTree
impl Unpin for MerkleTree
impl UnsafeUnpin for MerkleTree
impl UnwindSafe for MerkleTree
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more