Struct SparseMerkleTree

Source
pub struct SparseMerkleTree<H, V, S> { /* private fields */ }
Expand description

Sparse merkle tree

Implementations§

Source§

impl<H: Hasher + Default, V: Value, S: Store<V>> SparseMerkleTree<H, V, S>

Source

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

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: H256, 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: &H256) -> Result<V>

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

Source

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

Generate merkle proof

Trait Implementations§

Source§

impl<H: Debug, V: Debug, S: Debug> Debug for SparseMerkleTree<H, V, S>

Source§

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

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

impl<H: Default, V: Default, S: Default> Default for SparseMerkleTree<H, V, S>

Source§

fn default() -> SparseMerkleTree<H, V, S>

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

Auto Trait Implementations§

§

impl<H, V, S> Freeze for SparseMerkleTree<H, V, S>
where S: Freeze,

§

impl<H, V, S> RefUnwindSafe for SparseMerkleTree<H, V, S>

§

impl<H, V, S> Send for SparseMerkleTree<H, V, S>
where S: Send, H: Send, V: Send,

§

impl<H, V, S> Sync for SparseMerkleTree<H, V, S>
where S: Sync, H: Sync, V: Sync,

§

impl<H, V, S> Unpin for SparseMerkleTree<H, V, S>
where S: Unpin, H: Unpin, V: Unpin,

§

impl<H, V, S> UnwindSafe for SparseMerkleTree<H, V, S>
where S: UnwindSafe, H: UnwindSafe, V: UnwindSafe,

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, 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.