pub struct MerkleTree<E: Environment, LH: LeafHash<Hash = PH::Hash>, PH: PathHash<Hash = Field<E>>, const DEPTH: u8> { /* private fields */ }
Implementations§
source§impl<E: Environment, LH: LeafHash<Hash = PH::Hash>, PH: PathHash<Hash = Field<E>>, const DEPTH: u8> MerkleTree<E, LH, PH, DEPTH>
impl<E: Environment, LH: LeafHash<Hash = PH::Hash>, PH: PathHash<Hash = Field<E>>, const DEPTH: u8> MerkleTree<E, LH, PH, DEPTH>
sourcepub fn new(
leaf_hasher: &LH,
path_hasher: &PH,
leaves: &[LH::Leaf]
) -> Result<Self>
pub fn new( leaf_hasher: &LH, path_hasher: &PH, leaves: &[LH::Leaf] ) -> Result<Self>
Initializes a new Merkle tree with the given leaves.
sourcepub fn prepare_append(&self, new_leaves: &[LH::Leaf]) -> Result<Self>
pub fn prepare_append(&self, new_leaves: &[LH::Leaf]) -> Result<Self>
Returns a new Merkle tree with the given new leaves appended to it.
sourcepub fn append(&mut self, new_leaves: &[LH::Leaf]) -> Result<()>
pub fn append(&mut self, new_leaves: &[LH::Leaf]) -> Result<()>
Updates the Merkle tree with the given new leaves appended to it.
sourcepub fn update(&mut self, leaf_index: usize, new_leaf: &LH::Leaf) -> Result<()>
pub fn update(&mut self, leaf_index: usize, new_leaf: &LH::Leaf) -> Result<()>
Updates the Merkle tree at the location of the given leaf index with the new leaf.
sourcepub fn prepare_update(
&self,
leaf_index: usize,
new_leaf: &LH::Leaf
) -> Result<Self>
pub fn prepare_update( &self, leaf_index: usize, new_leaf: &LH::Leaf ) -> Result<Self>
Returns a new Merkle tree with updates at the location of the given leaf index with the new leaf.
sourcepub fn update_many(&mut self, updates: &BTreeMap<usize, LH::Leaf>) -> Result<()>
pub fn update_many(&mut self, updates: &BTreeMap<usize, LH::Leaf>) -> Result<()>
Updates the Merkle tree at the location of the given leaf indices with the new leaves.
sourcepub fn prepare_remove_last_n(&self, n: usize) -> Result<Self>
pub fn prepare_remove_last_n(&self, n: usize) -> Result<Self>
Returns a new Merkle tree with the last ‘n’ leaves removed from it.
sourcepub fn remove_last_n(&mut self, n: usize) -> Result<()>
pub fn remove_last_n(&mut self, n: usize) -> Result<()>
Updates the Merkle tree with the last ‘n’ leaves removed from it.
sourcepub fn prove(
&self,
leaf_index: usize,
leaf: &LH::Leaf
) -> Result<MerklePath<E, DEPTH>>
pub fn prove( &self, leaf_index: usize, leaf: &LH::Leaf ) -> Result<MerklePath<E, DEPTH>>
Returns the Merkle path for the given leaf index and leaf.
sourcepub fn verify(
&self,
path: &MerklePath<E, DEPTH>,
root: &PH::Hash,
leaf: &LH::Leaf
) -> bool
pub fn verify( &self, path: &MerklePath<E, DEPTH>, root: &PH::Hash, leaf: &LH::Leaf ) -> bool
Returns true
if the given Merkle path is valid for the given root and leaf.
sourcepub fn tree(&self) -> &[PH::Hash]
pub fn tree(&self) -> &[PH::Hash]
Returns the Merkle tree (excluding the hashes of the leaves).
sourcepub const fn empty_hash(&self) -> &PH::Hash
pub const fn empty_hash(&self) -> &PH::Hash
Returns the empty hash.
sourcepub fn leaf_hashes(&self) -> Result<&[LH::Hash]>
pub fn leaf_hashes(&self) -> Result<&[LH::Hash]>
Returns the leaf hashes from the Merkle tree.
sourcepub const fn number_of_leaves(&self) -> usize
pub const fn number_of_leaves(&self) -> usize
Returns the number of leaves in the Merkle tree.
Trait Implementations§
source§impl<E: Clone + Environment, LH: Clone + LeafHash<Hash = PH::Hash>, PH: Clone + PathHash<Hash = Field<E>>, const DEPTH: u8> Clone for MerkleTree<E, LH, PH, DEPTH>where
PH::Hash: Clone,
impl<E: Clone + Environment, LH: Clone + LeafHash<Hash = PH::Hash>, PH: Clone + PathHash<Hash = Field<E>>, const DEPTH: u8> Clone for MerkleTree<E, LH, PH, DEPTH>where PH::Hash: Clone,
source§fn clone(&self) -> MerkleTree<E, LH, PH, DEPTH>
fn clone(&self) -> MerkleTree<E, LH, PH, DEPTH>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more