AccountTreeBackend

Trait AccountTreeBackend 

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

    // Required methods
    fn num_leaves(&self) -> usize;
    fn leaves<'a>(
        &'a self,
    ) -> Box<dyn Iterator<Item = (LeafIndex<SMT_DEPTH>, SmtLeaf)> + 'a>;
    fn open(&self, key: &Word) -> SmtProof;
    fn apply_mutations(
        &mut self,
        set: MutationSet<SMT_DEPTH, Word, Word>,
    ) -> Result<(), Self::Error>;
    fn apply_mutations_with_reversion(
        &mut self,
        set: MutationSet<SMT_DEPTH, Word, Word>,
    ) -> Result<MutationSet<SMT_DEPTH, Word, Word>, Self::Error>;
    fn compute_mutations(
        &self,
        updates: Vec<(Word, Word)>,
    ) -> Result<MutationSet<SMT_DEPTH, Word, Word>, Self::Error>;
    fn insert(&mut self, key: Word, value: Word) -> Result<Word, Self::Error>;
    fn get_value(&self, key: &Word) -> Word;
    fn get_leaf(&self, key: &Word) -> SmtLeaf;
    fn root(&self) -> Word;
}
Expand description

This trait abstracts over different SMT backends (e.g., Smt and LargeSmt) to allow the AccountTree to work with either implementation transparently.

Implementors must provide Default for creating empty instances. Users should instantiate the backend directly (potentially with entries) and then pass it to AccountTree::new.

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 leaves<'a>( &'a self, ) -> Box<dyn Iterator<Item = (LeafIndex<SMT_DEPTH>, SmtLeaf)> + 'a>

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

Source

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

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

Source

fn apply_mutations( &mut self, set: MutationSet<SMT_DEPTH, Word, Word>, ) -> Result<(), Self::Error>

Applies the given mutation set to the SMT.

Source

fn apply_mutations_with_reversion( &mut self, set: MutationSet<SMT_DEPTH, Word, Word>, ) -> Result<MutationSet<SMT_DEPTH, Word, Word>, Self::Error>

Applies the given mutation set to the SMT and returns the reverse mutation set.

The reverse mutation set can be used to revert the changes made by this operation.

Source

fn compute_mutations( &self, updates: Vec<(Word, Word)>, ) -> Result<MutationSet<SMT_DEPTH, Word, Word>, Self::Error>

Computes the mutation set required to apply the given updates to the SMT.

Source

fn insert(&mut self, key: Word, value: Word) -> Result<Word, Self::Error>

Inserts a key-value pair into the SMT, returning the previous value at that key.

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", so this trait is not object safe.

Implementors§

Source§

impl AccountTreeBackend for Smt

Source§

impl<Backend> AccountTreeBackend for LargeSmt<Backend>
where Backend: SmtStorage,

Available on crate feature std only.