pub struct MerkleTree { /* private fields */ }Expand description
RFC 6962-compatible Merkle tree.
Implementations§
Source§impl MerkleTree
impl MerkleTree
Sourcepub fn from_leaves<T>(leaves: &[T]) -> Result<MerkleTree, Error>
pub fn from_leaves<T>(leaves: &[T]) -> Result<MerkleTree, Error>
Build a Merkle tree from leaf data.
Returns Err(Error::EmptyTree) if the slice is empty.
Sourcepub fn from_hashes(leaf_hashes: Vec<Hash>) -> Result<MerkleTree, Error>
pub fn from_hashes(leaf_hashes: Vec<Hash>) -> Result<MerkleTree, Error>
Build a Merkle tree from pre-hashed leaves.
Sourcepub fn leaf_count(&self) -> usize
pub fn leaf_count(&self) -> usize
Get the number of leaves.
Sourcepub fn consistency_proof(&self, old_size: usize) -> Result<Vec<Hash>, Error>
pub fn consistency_proof(&self, old_size: usize) -> Result<Vec<Hash>, Error>
Generate an RFC 6962 consistency proof (RFC 9162 section 2.1.4.1)
showing that the tree over the first old_size leaves is a prefix of
this tree.
The proof for old_size == leaf_count() is empty. Returns
Err(Error::InvalidProofIndex) when old_size is zero or exceeds the
current leaf count.
Sourcepub fn consistency_proof_between(
&self,
old_size: usize,
new_size: usize,
) -> Result<Vec<Hash>, Error>
pub fn consistency_proof_between( &self, old_size: usize, new_size: usize, ) -> Result<Vec<Hash>, Error>
Generate an RFC 6962 consistency proof between two prefixes of this tree without rebuilding the shorter tree.
Sourcepub fn prefix_root(&self, tree_size: usize) -> Result<Hash, Error>
pub fn prefix_root(&self, tree_size: usize) -> Result<Hash, Error>
Return the root of the first tree_size leaves without rebuilding that
prefix.
Sourcepub fn inclusion_proof(&self, leaf_index: usize) -> Result<MerkleProof, Error>
pub fn inclusion_proof(&self, leaf_index: usize) -> Result<MerkleProof, Error>
Generate an inclusion proof for a leaf at the given index.
Sourcepub fn inclusion_proof_at_size(
&self,
leaf_index: usize,
tree_size: usize,
) -> Result<MerkleProof, Error>
pub fn inclusion_proof_at_size( &self, leaf_index: usize, tree_size: usize, ) -> Result<MerkleProof, Error>
Generate an inclusion proof within a prefix of this tree without rebuilding that prefix.
Trait Implementations§
Source§impl Clone for MerkleTree
impl Clone for MerkleTree
Source§fn clone(&self) -> MerkleTree
fn clone(&self) -> MerkleTree
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more