pub struct MerkleTree { /* private fields */ }unstable only.Expand description
A Blake2b256 Merkle tree.
The tree is built once from a set of leaves and then queried for its
root or for MerkleProofs.
Implementations§
Source§impl MerkleTree
impl MerkleTree
Sourcepub fn build_from_serialized<I>(iter: I) -> Self
pub fn build_from_serialized<I>(iter: I) -> Self
Build a tree by hashing each input as a leaf.
Sourcepub fn build_from_unserialized<I>(iter: I) -> Result<Self, MerkleError>
pub fn build_from_unserialized<I>(iter: I) -> Result<Self, MerkleError>
Build a tree by BCS-encoding each input and using its hash as a leaf.
Returns MerkleError::InvalidInput if any leaf fails BCS
serialization, which in practice can only happen for unusual Serialize
impls (e.g. infinite recursion); ordinary value types do not fail.
Sourcepub fn build_from_leaf_hashes<I>(iter: I) -> Self
pub fn build_from_leaf_hashes<I>(iter: I) -> Self
Build a tree directly from already-hashed leaves.
Each input node is interpreted as a leaf hash; callers are responsible
for applying the LEAF_PREFIX before hashing.
Sourcepub fn root(&self) -> Node
pub fn root(&self) -> Node
The Merkle root.
An empty tree (built from zero leaves) returns Node::Empty.
Sourcepub fn get_proof(&self, leaf_index: usize) -> Result<MerkleProof, MerkleError>
pub fn get_proof(&self, leaf_index: usize) -> Result<MerkleProof, MerkleError>
Build an inclusion proof for the leaf at leaf_index.
Returns MerkleError::InvalidInput if leaf_index >= n_leaves.
Sourcepub fn compute_non_inclusion_proof<L>(
&self,
sorted_leaves: &[L],
target: &L,
) -> Result<MerkleNonInclusionProof<L>, MerkleError>
pub fn compute_non_inclusion_proof<L>( &self, sorted_leaves: &[L], target: &L, ) -> Result<MerkleNonInclusionProof<L>, MerkleError>
Build a non-inclusion proof showing that target does not appear in
this tree.
The tree must have been built from sorted_leaves in sorted order;
the caller is responsible for passing the same sorted slice it built
the tree from. Returns MerkleError::InvalidInput if target is
actually present in sorted_leaves.
Trait Implementations§
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§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read moreSource§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> 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