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§
Required Methods§
Sourcefn num_leaves(&self) -> usize
fn num_leaves(&self) -> usize
Returns the number of leaves in the SMT.
Sourcefn leaves<'a>(
&'a self,
) -> Box<dyn Iterator<Item = (LeafIndex<SMT_DEPTH>, SmtLeaf)> + 'a>
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.
Sourcefn open(&self, key: &Word) -> SmtProof
fn open(&self, key: &Word) -> SmtProof
Opens the leaf at the given key, returning a Merkle proof.
Sourcefn apply_mutations(
&mut self,
set: MutationSet<SMT_DEPTH, Word, Word>,
) -> Result<(), Self::Error>
fn apply_mutations( &mut self, set: MutationSet<SMT_DEPTH, Word, Word>, ) -> Result<(), Self::Error>
Applies the given mutation set to the SMT.
Sourcefn apply_mutations_with_reversion(
&mut self,
set: MutationSet<SMT_DEPTH, Word, Word>,
) -> Result<MutationSet<SMT_DEPTH, Word, Word>, Self::Error>
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.
Sourcefn compute_mutations(
&self,
updates: Vec<(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>
Computes the mutation set required to apply the given updates to 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
impl AccountTreeBackend for Smt
type Error = MerkleError
Source§impl<Backend> AccountTreeBackend for LargeSmt<Backend>where
Backend: SmtStorage,
Available on crate feature std only.
impl<Backend> AccountTreeBackend for LargeSmt<Backend>where
Backend: SmtStorage,
std only.