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>
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>
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 moreAuto Trait Implementations§
impl<E, LH, PH, const DEPTH: u8> Freeze for MerkleTree<E, LH, PH, DEPTH>
impl<E, LH, PH, const DEPTH: u8> RefUnwindSafe for MerkleTree<E, LH, PH, DEPTH>
impl<E, LH, PH, const DEPTH: u8> Send for MerkleTree<E, LH, PH, DEPTH>
impl<E, LH, PH, const DEPTH: u8> Sync for MerkleTree<E, LH, PH, DEPTH>
impl<E, LH, PH, const DEPTH: u8> Unpin for MerkleTree<E, LH, PH, DEPTH>
impl<E, LH, PH, const DEPTH: u8> UnwindSafe for MerkleTree<E, LH, PH, DEPTH>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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> ⓘ
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