#[repr(C)]pub struct MerkleMountainRange<const MAX_N: u64>{ /* private fields */ }
Expand description
Merkle Mountain Range variant that has pre-hashed leaves with arbitrary number of elements.
This can be considered a general case of UnbalancedMerkleTree
. The root and proofs are
identical for both. UnbalancedMerkleTree
is more efficient and should be preferred when
possible, while this data structure is designed for aggregating data incrementally over long
periods of time.
MAX_N
generic constant defines the maximum number of elements supported and controls stack
usage.
Implementations§
Source§impl<const MAX_N: u64> MerkleMountainRange<MAX_N>
impl<const MAX_N: u64> MerkleMountainRange<MAX_N>
Sourcepub fn from_peaks(peaks: &MmrPeaks<MAX_N>) -> Option<Self>
pub fn from_peaks(peaks: &MmrPeaks<MAX_N>) -> Option<Self>
Create a new instance from previously collected peaks.
Returns None
if input is invalid.
Sourcepub fn as_bytes(&self) -> &MerkleMountainRangeBytes<MAX_N>
pub fn as_bytes(&self) -> &MerkleMountainRangeBytes<MAX_N>
Get byte representation of Merkle Mountain Range
Sourcepub unsafe fn from_bytes(bytes: &MerkleMountainRangeBytes<MAX_N>) -> &Self
pub unsafe fn from_bytes(bytes: &MerkleMountainRangeBytes<MAX_N>) -> &Self
Create an instance from byte representation.
§Safety
Bytes must be previously created by Self::as_bytes()
.
Sourcepub fn num_leaves(&self) -> u64
pub fn num_leaves(&self) -> u64
Get number of leaves aggregated in Merkle Mountain Range so far
Sourcepub fn root(&self) -> Option<[u8; 32]>
pub fn root(&self) -> Option<[u8; 32]>
Calculate the root of Merkle Mountain Range.
In case MMR contains a single leaf hash, that leaf hash is returned, None
is returned if
there were no leafs added yet.
Sourcepub fn add_leaf(&mut self, leaf: &[u8; 32]) -> bool
pub fn add_leaf(&mut self, leaf: &[u8; 32]) -> bool
Add leaf to Merkle Mountain Range.
There is a more efficient version Self::add_leaves()
in case multiple leaves are
available.
Returns true
on success, false
if too many leafs were added.
Sourcepub fn add_leaves<'a, Item, Iter>(&mut self, leaves: Iter) -> bool
pub fn add_leaves<'a, Item, Iter>(&mut self, leaves: Iter) -> bool
Add many leaves to Merkle Mountain Range.
This is a more efficient version of Self::add_leaf()
in case multiple leaves are
available.
Returns true
on success, false
if too many leaves were added.
Sourcepub fn add_leaf_and_compute_proof(
&mut self,
leaf: &[u8; 32],
) -> Option<([u8; 32], Vec<[u8; 32]>)>
pub fn add_leaf_and_compute_proof( &mut self, leaf: &[u8; 32], ) -> Option<([u8; 32], Vec<[u8; 32]>)>
Add leaf to Merkle Mountain Range and generate inclusion proof.
Returns Some((root, proof))
on success, None
if too many leafs were added.
Sourcepub fn add_leaf_and_compute_proof_in<'proof>(
&mut self,
leaf: &[u8; 32],
proof: &'proof mut [MaybeUninit<[u8; 32]>; { _ }],
) -> Option<([u8; 32], &'proof mut [[u8; 32]])>
pub fn add_leaf_and_compute_proof_in<'proof>( &mut self, leaf: &[u8; 32], proof: &'proof mut [MaybeUninit<[u8; 32]>; { _ }], ) -> Option<([u8; 32], &'proof mut [[u8; 32]])>
Add leaf to Merkle Mountain Range and generate inclusion proof.
Returns Some((root, proof))
on success, None
if too many leafs were added.
pub fn add_leaf_and_compute_proof_inner( &mut self, leaf: &[u8; 32], proof: &mut [MaybeUninit<[u8; 32]>; { _ }], ) -> Option<([u8; 32], usize)>
Trait Implementations§
Source§impl<const MAX_N: u64> Clone for MerkleMountainRange<MAX_N>
impl<const MAX_N: u64> Clone for MerkleMountainRange<MAX_N>
Source§fn clone(&self) -> MerkleMountainRange<MAX_N>
fn clone(&self) -> MerkleMountainRange<MAX_N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more