pub struct MerkleTree<E, H, I, const ARITY: usize, T>{ /* private fields */ }
Expand description
A standard append only Merkle tree implementation
Implementations§
Source§impl<E, H, I, const ARITY: usize, T> MerkleTree<E, H, I, ARITY, T>
impl<E, H, I, const ARITY: usize, T> MerkleTree<E, H, I, ARITY, T>
Source§impl<E, H, const ARITY: usize, T> MerkleTree<E, H, u64, ARITY, T>
impl<E, H, const ARITY: usize, T> MerkleTree<E, H, u64, ARITY, T>
Sourcepub fn from_elems(
height: Option<usize>,
elems: impl IntoIterator<Item = impl Borrow<E>>,
) -> Result<Self, MerkleTreeError>
pub fn from_elems( height: Option<usize>, elems: impl IntoIterator<Item = impl Borrow<E>>, ) -> Result<Self, MerkleTreeError>
Construct a new Merkle tree with given height from a data slice
height
- height of the Merkle tree, ifNone
, it will calculate the minimum height that could hold all elements.elems
- an iterator to all elementsreturns
- A constructed Merkle tree, orErr()
if errors
Trait Implementations§
Source§impl<E, H, const ARITY: usize, T> AppendableMerkleTreeScheme for MerkleTree<E, H, u64, ARITY, T>
impl<E, H, const ARITY: usize, T> AppendableMerkleTreeScheme for MerkleTree<E, H, u64, ARITY, T>
Source§fn push(
&mut self,
elem: impl Borrow<Self::Element>,
) -> Result<(), MerkleTreeError>
fn push( &mut self, elem: impl Borrow<Self::Element>, ) -> Result<(), MerkleTreeError>
Insert a new value at the leftmost available slot Read more
Source§fn extend(
&mut self,
elems: impl IntoIterator<Item = impl Borrow<Self::Element>>,
) -> Result<(), MerkleTreeError>
fn extend( &mut self, elems: impl IntoIterator<Item = impl Borrow<Self::Element>>, ) -> Result<(), MerkleTreeError>
Insert a list of new values at the leftmost available slots Read more
Source§impl<E, H, I, const ARITY: usize, T> Clone for MerkleTree<E, H, I, ARITY, T>
impl<E, H, I, const ARITY: usize, T> Clone for MerkleTree<E, H, I, ARITY, T>
Source§fn clone(&self) -> MerkleTree<E, H, I, ARITY, T>
fn clone(&self) -> MerkleTree<E, H, I, ARITY, T>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<E, H, I, const ARITY: usize, T> Debug for MerkleTree<E, H, I, ARITY, T>
impl<E, H, I, const ARITY: usize, T> Debug for MerkleTree<E, H, I, ARITY, T>
Source§impl<'de, E, H, I, const ARITY: usize, T> Deserialize<'de> for MerkleTree<E, H, I, ARITY, T>where
E: Element + CanonicalSerialize + CanonicalDeserialize,
H: DigestAlgorithm<E, I, T>,
I: Index + CanonicalSerialize + CanonicalDeserialize,
T: NodeValue,
impl<'de, E, H, I, const ARITY: usize, T> Deserialize<'de> for MerkleTree<E, H, I, ARITY, T>where
E: Element + CanonicalSerialize + CanonicalDeserialize,
H: DigestAlgorithm<E, I, T>,
I: Index + CanonicalSerialize + CanonicalDeserialize,
T: NodeValue,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<E, H, I, const ARITY: usize, T> ForgetableMerkleTreeScheme for MerkleTree<E, H, I, ARITY, T>
impl<E, H, I, const ARITY: usize, T> ForgetableMerkleTreeScheme for MerkleTree<E, H, I, ARITY, T>
Source§fn from_commitment(
com: impl Borrow<Self::Commitment>,
height: usize,
num_leaves: u64,
) -> Self
fn from_commitment( com: impl Borrow<Self::Commitment>, height: usize, num_leaves: u64, ) -> Self
Rebuild a merkle tree from a commitment.
Return a tree which is entirely forgotten.
Source§fn forget(
&mut self,
pos: impl Borrow<Self::Index>,
) -> LookupResult<Self::Element, Self::MembershipProof, ()>
fn forget( &mut self, pos: impl Borrow<Self::Index>, ) -> LookupResult<Self::Element, Self::MembershipProof, ()>
Trim the leaf at position
i
from memory, if present.
Should not trim if position i
is the last inserted leaf position.
Return is identical to result if get_leaf(pos)
were called before this
call.Source§fn remember(
&mut self,
pos: impl Borrow<Self::Index>,
element: impl Borrow<Self::Element>,
proof: impl Borrow<Self::MembershipProof>,
) -> Result<(), MerkleTreeError>
fn remember( &mut self, pos: impl Borrow<Self::Index>, element: impl Borrow<Self::Element>, proof: impl Borrow<Self::MembershipProof>, ) -> Result<(), MerkleTreeError>
“Re-insert” a leaf into the tree using its proof.
Returns Ok(()) if insertion is successful, or Err(err) if the
proof disagrees with the merkle tree
Source§impl<E, H, I, const ARITY: usize, T> Hash for MerkleTree<E, H, I, ARITY, T>
impl<E, H, I, const ARITY: usize, T> Hash for MerkleTree<E, H, I, ARITY, T>
Source§impl<'a, E, H, I, const ARITY: usize, T> IntoIterator for &'a MerkleTree<E, H, I, ARITY, T>
impl<'a, E, H, I, const ARITY: usize, T> IntoIterator for &'a MerkleTree<E, H, I, ARITY, T>
Source§impl<E, H, I, const ARITY: usize, T> IntoIterator for MerkleTree<E, H, I, ARITY, T>
impl<E, H, I, const ARITY: usize, T> IntoIterator for MerkleTree<E, H, I, ARITY, T>
Source§impl<E, H, I, const ARITY: usize, T> MerkleTreeScheme for MerkleTree<E, H, I, ARITY, T>
impl<E, H, I, const ARITY: usize, T> MerkleTreeScheme for MerkleTree<E, H, I, ARITY, T>
Source§type MembershipProof = MerkleTreeProof<T>
type MembershipProof = MerkleTreeProof<T>
Merkle proof
Source§type BatchMembershipProof = ()
type BatchMembershipProof = ()
Batch proof
Source§type Commitment = T
type Commitment = T
Merkle tree commitment
Source§fn num_leaves(&self) -> u64
fn num_leaves(&self) -> u64
Return the current number of leaves
Source§fn commitment(&self) -> Self::Commitment
fn commitment(&self) -> Self::Commitment
Return a merkle commitment
Source§fn lookup(
&self,
pos: impl Borrow<Self::Index>,
) -> LookupResult<&Self::Element, Self::MembershipProof, ()>
fn lookup( &self, pos: impl Borrow<Self::Index>, ) -> LookupResult<&Self::Element, Self::MembershipProof, ()>
Returns the leaf value given a position Read more
Source§impl<E, H, I, const ARITY: usize, T> PartialEq for MerkleTree<E, H, I, ARITY, T>
impl<E, H, I, const ARITY: usize, T> PartialEq for MerkleTree<E, H, I, ARITY, T>
Source§fn eq(&self, other: &MerkleTree<E, H, I, ARITY, T>) -> bool
fn eq(&self, other: &MerkleTree<E, H, I, ARITY, T>) -> bool
Tests for
self
and other
values to be equal, and is used by ==
.Source§impl<E, H, I, const ARITY: usize, T> Serialize for MerkleTree<E, H, I, ARITY, T>where
E: Element + CanonicalSerialize + CanonicalDeserialize,
H: DigestAlgorithm<E, I, T>,
I: Index + CanonicalSerialize + CanonicalDeserialize,
T: NodeValue,
impl<E, H, I, const ARITY: usize, T> Serialize for MerkleTree<E, H, I, ARITY, T>where
E: Element + CanonicalSerialize + CanonicalDeserialize,
H: DigestAlgorithm<E, I, T>,
I: Index + CanonicalSerialize + CanonicalDeserialize,
T: NodeValue,
impl<E, H, I, const ARITY: usize, T> Eq for MerkleTree<E, H, I, ARITY, T>
impl<E, H, I, const ARITY: usize, T> StructuralPartialEq for MerkleTree<E, H, I, ARITY, T>
Auto Trait Implementations§
impl<E, H, I, const ARITY: usize, T> Freeze for MerkleTree<E, H, I, ARITY, T>
impl<E, H, I, const ARITY: usize, T> RefUnwindSafe for MerkleTree<E, H, I, ARITY, T>
impl<E, H, I, const ARITY: usize, T> Send for MerkleTree<E, H, I, ARITY, T>
impl<E, H, I, const ARITY: usize, T> Sync for MerkleTree<E, H, I, ARITY, T>
impl<E, H, I, const ARITY: usize, T> Unpin for MerkleTree<E, H, I, ARITY, T>where
H: Unpin,
impl<E, H, I, const ARITY: usize, T> UnwindSafe for MerkleTree<E, H, I, ARITY, T>
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
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>
Converts
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>
Converts
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