Struct SparseMerkleTree

Source
pub struct SparseMerkleTree<H, K, V, S, const N: usize>
where H: Hasher + Default, K: Key<N>, V: Value, S: Store<K, V, N>,
{ /* private fields */ }
Expand description

Sparse merkle tree

Implementations§

Source§

impl<H, K, V, S, const N: usize> SparseMerkleTree<H, K, V, S, N>
where H: Hasher + Default, K: Key<N>, V: Value + PartialEq, S: Store<K, V, N>,

Source

pub fn new(root: H256, store: S) -> SparseMerkleTree<H, K, V, S, N>

Build a merkle tree from root and store

Source

pub fn root(&self) -> &H256

Merkle root

Source

pub fn is_empty(&self) -> bool

Check empty of the tree

Source

pub fn take_store(self) -> S

Destroy current tree and retake store

Source

pub fn store(&self) -> &S

Get backend store

Source

pub fn store_mut(&mut self) -> &mut S

Get mutable backend store

Source

pub fn update(&mut self, key: K, value: V) -> Result<&H256>

Update a leaf, return new merkle root set to zero value to delete a key

Source

pub fn get(&self, key: &K) -> Result<V>

Get value of a leaf return zero value if leaf not exists

Source

pub fn merkle_proof(&self, keys: Vec<K>) -> Result<MerkleProof>

Generate merkle proof

Source

pub fn membership_proof(&self, key: &K) -> Result<CommitmentProof>

Generate ICS 23 commitment proof for the existing key

Source

pub fn non_membership_proof(&self, key: &K) -> Result<CommitmentProof>

Generate ICS 23 commitment proof for the non-existing key

Source

pub fn validate(&self) -> bool

Recompute the root of the merkle tree from the store. Check if it agrees with the root in self.

Trait Implementations§

Source§

impl<H, K, V, S, const N: usize> Debug for SparseMerkleTree<H, K, V, S, N>
where H: Hasher + Default + Debug, K: Key<N> + Debug, V: Value + Debug, S: Store<K, V, N> + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<H, K, V, S, const N: usize> Default for SparseMerkleTree<H, K, V, S, N>
where H: Hasher + Default, K: Key<N>, V: Value + PartialEq, S: Store<K, V, N>,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<H, K, V, S, const N: usize> Freeze for SparseMerkleTree<H, K, V, S, N>
where S: Freeze,

§

impl<H, K, V, S, const N: usize> RefUnwindSafe for SparseMerkleTree<H, K, V, S, N>

§

impl<H, K, V, S, const N: usize> Send for SparseMerkleTree<H, K, V, S, N>
where S: Send, H: Send, K: Send, V: Send,

§

impl<H, K, V, S, const N: usize> Sync for SparseMerkleTree<H, K, V, S, N>
where S: Sync, H: Sync, K: Sync, V: Sync,

§

impl<H, K, V, S, const N: usize> Unpin for SparseMerkleTree<H, K, V, S, N>
where S: Unpin, H: Unpin, K: Unpin, V: Unpin,

§

impl<H, K, V, S, const N: usize> UnwindSafe for SparseMerkleTree<H, K, V, S, N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.