Skip to main content

SmtBackendReader

Trait SmtBackendReader 

Source
pub trait SmtBackendReader: Sized {
    type Error: Error + Send + 'static;

    // Required methods
    fn num_leaves(&self) -> usize;
    fn num_entries(&self) -> usize;
    fn leaves(
        &self,
    ) -> Box<dyn Iterator<Item = (LeafIndex<SMT_DEPTH>, SmtLeaf)> + '_>;
    fn entries(&self) -> Box<dyn Iterator<Item = (Word, Word)> + '_>;
    fn open(&self, key: &Word) -> SmtProof;
    fn get_value(&self, key: &Word) -> Word;
    fn get_leaf(&self, key: &Word) -> SmtLeaf;
    fn root(&self) -> Word;
}
Expand description

Abstracts over the read-only operations of the different SMT backends (e.g. Smt and LargeSmt), so that the block trees can work with either implementation transparently.

This trait is value-agnostic: leaves are stored as raw Words. Trees that wrap a more specific value type (such as the nullifier tree) are responsible for converting to and from Word in their own accessors.

The method set is intentionally the superset required by both the account and nullifier trees, so a given tree only uses the subset relevant to it (e.g. the account tree iterates leaves, the nullifier tree iterates entries).

This trait contains only read-only methods. For write methods, see SmtBackend.

Required Associated Types§

Source

type Error: Error + Send + 'static

Required Methods§

Source

fn num_leaves(&self) -> usize

Returns the number of leaves in the SMT.

Source

fn num_entries(&self) -> usize

Returns the number of key-value entries in the SMT.

This can exceed Self::num_leaves when keys collide into the same leaf.

Source

fn leaves( &self, ) -> Box<dyn Iterator<Item = (LeafIndex<SMT_DEPTH>, SmtLeaf)> + '_>

Returns all leaves in the SMT as an iterator over leaf index and leaf pairs.

Source

fn entries(&self) -> Box<dyn Iterator<Item = (Word, Word)> + '_>

Returns all key-value entries in the SMT.

Source

fn open(&self, key: &Word) -> SmtProof

Opens the leaf at the given key, returning a Merkle proof.

Source

fn get_value(&self, key: &Word) -> Word

Returns the value associated with the given key.

Source

fn get_leaf(&self, key: &Word) -> SmtLeaf

Returns the leaf at the given key.

Source

fn root(&self) -> Word

Returns the root of the SMT.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl SmtBackendReader for Smt

Source§

impl<Backend> SmtBackendReader for LargeSmt<Backend>
where Backend: SmtStorageReader,

Available on crate feature std only.