SparseMerkleTreeWithHistoryBounded

Struct SparseMerkleTreeWithHistoryBounded 

Source
pub struct SparseMerkleTreeWithHistoryBounded<'a, L: Serialize + DeserializeOwned + Clone + Debug + PartialEq + PrimaryKey<'a>, H: Hasher<L>, const HISTORY_LEVEL: u32> {
    pub history_index: Item<'a, u32>,
    pub root_history: Map<'a, L, Empty>,
    pub root_index: Map<'a, u32, L>,
    pub tree: SparseMerkleTree<'a, L, H>,
}
Expand description

Like SparseMerkleTree but able to check valid root hash with previous root hashes upto specified history level.

Fields§

§history_index: Item<'a, u32>§root_history: Map<'a, L, Empty>§root_index: Map<'a, u32, L>§tree: SparseMerkleTree<'a, L, H>

Implementations§

Source§

impl<'a, L: Serialize + DeserializeOwned + Clone + Debug + PartialEq + PrimaryKey<'a>, H: Hasher<L>, const HISTORY_LEVEL: u32> SparseMerkleTreeWithHistoryBounded<'a, L, H, HISTORY_LEVEL>

Source

pub const fn new( hashes_ns: &'a str, leafs_ns: &'a str, level_ns: &'a str, root_ns: &'a str, root_history_ns: &'a str, root_index_ns: &'a str, history_index_ns: &'a str, ) -> Self

Source

pub fn update_history_level( &self, storage: &mut dyn Storage, ) -> Result<(), MerkleTreeError>

Remove storage unused and out of range stored root. The removed root might not be the earliest.

Trait Implementations§

Source§

impl<'a, L: Serialize + DeserializeOwned + Clone + Debug + PartialEq + PrimaryKey<'a>, H: Hasher<L>, const HISTORY_LEVEL: u32> MerkleTree<L, H> for SparseMerkleTreeWithHistoryBounded<'a, L, H, HISTORY_LEVEL>

Source§

fn init( &self, storage: &mut dyn Storage, level: u8, default_leaf: L, hasher: &H, ) -> Result<(), MerkleTreeError>

Initize the tree.
Source§

fn is_valid_root( &self, storage: &dyn Storage, root: &L, ) -> Result<bool, MerkleTreeError>

Check if the root is valid for the tree.
Source§

fn insert( &self, storage: &mut dyn Storage, leaf: L, hasher: &H, ) -> Result<(u64, L), MerkleTreeError>

Insert the leaf into the next index slot of the tree. Return the leaf’s index and the updated root.
Source§

fn get_latest_root(&self, storage: &dyn Storage) -> Result<L, MerkleTreeError>

Get the latest root of the tree.

Auto Trait Implementations§

§

impl<'a, L, H, const HISTORY_LEVEL: u32> Freeze for SparseMerkleTreeWithHistoryBounded<'a, L, H, HISTORY_LEVEL>

§

impl<'a, L, H, const HISTORY_LEVEL: u32> RefUnwindSafe for SparseMerkleTreeWithHistoryBounded<'a, L, H, HISTORY_LEVEL>

§

impl<'a, L, H, const HISTORY_LEVEL: u32> Send for SparseMerkleTreeWithHistoryBounded<'a, L, H, HISTORY_LEVEL>
where L: Send, H: Send,

§

impl<'a, L, H, const HISTORY_LEVEL: u32> Sync for SparseMerkleTreeWithHistoryBounded<'a, L, H, HISTORY_LEVEL>
where L: Sync, H: Sync,

§

impl<'a, L, H, const HISTORY_LEVEL: u32> Unpin for SparseMerkleTreeWithHistoryBounded<'a, L, H, HISTORY_LEVEL>
where L: Unpin, H: Unpin,

§

impl<'a, L, H, const HISTORY_LEVEL: u32> UnwindSafe for SparseMerkleTreeWithHistoryBounded<'a, L, H, HISTORY_LEVEL>
where L: UnwindSafe, H: 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<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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> 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.