NamespaceMerkleTree

Struct NamespaceMerkleTree 

Source
pub struct NamespaceMerkleTree<Db, M: MerkleHash, const NS_ID_SIZE: usize> { /* private fields */ }
Expand description

A namespaced merkle tree, implemented as a wrapper around a simple merkle tree.

Implementations§

Source§

impl<Db, M, const NS_ID_SIZE: usize> NamespaceMerkleTree<Db, M, NS_ID_SIZE>
where Db: PreimageDb<M::Output>, M: NamespaceMerkleHasher<NS_ID_SIZE, Output = NamespacedHash<NS_ID_SIZE>> + Default,

Source

pub fn new() -> Self

Creates a new tree with the default hasher

Source§

impl<Db, M, const NS_ID_SIZE: usize> NamespaceMerkleTree<Db, M, NS_ID_SIZE>
where Db: PreimageDb<M::Output>, M: NamespaceMerkleHasher<NS_ID_SIZE, Output = NamespacedHash<NS_ID_SIZE>>,

Source

pub fn with_hasher(hasher: M) -> Self

Creates a new nmt with the provided hasher

Source

pub fn push_leaf( &mut self, raw_data: &[u8], namespace: NamespaceId<NS_ID_SIZE>, ) -> Result<(), &'static str>

Adds a leaf to the namespaced merkle tree. Leaves must be pushed in namespace order.

Source

pub fn root(&mut self) -> NamespacedHash<NS_ID_SIZE>

Returns the root of the tree, computing it if necessary. Repeated calls return a cached root.

Source

pub fn build_range_proof(&mut self, leaf_range: Range<usize>) -> Proof<M>

Creates a range proof providing the sibling hashes required to show that a set of values really does occur in the merkle tree at some half-open range of indices. Intermediate hashes are identified by an in-order traversal and are returned in that same order. Panics if the range to prove is larger than the tree’s leaf array.

Example: consider the following merkle tree with leaves [C, D, E, F]

         root
       /      \
      A        B
     / \      /  \
    C   D    E    F

A range proof of build_range_proof(1..3) would return the vector [C, F], since those two hashes, together with the two leaves in the range, are sufficient to reconstruct the tree

Source

pub fn get_range_with_proof( &mut self, leaf_range: Range<usize>, ) -> (Vec<Vec<u8>>, NamespaceProof<M, NS_ID_SIZE>)

Fetch a range of leaves from the tree, along with a proof of their inclusion.

Source

pub fn get_index_with_proof(&mut self, idx: usize) -> (Vec<u8>, Proof<M>)

Get the leaf at a given index in the tree, along with a proof of its inclusion.

Source

pub fn get_namespace_with_proof( &mut self, namespace: NamespaceId<NS_ID_SIZE>, ) -> (Vec<Vec<u8>>, NamespaceProof<M, NS_ID_SIZE>)

Get an entire namespace from the tree, along with an inclusion proof for that range.

Source

pub fn leaves(&self) -> &[LeafWithHash<M>]

Return all the leaves from the tree.

Source

pub fn get_namespace_proof( &mut self, namespace: NamespaceId<NS_ID_SIZE>, ) -> NamespaceProof<M, NS_ID_SIZE>

Get a proof for the given namespace.

Trait Implementations§

Source§

impl<Db, M, const NS_ID_SIZE: usize> Default for NamespaceMerkleTree<Db, M, NS_ID_SIZE>
where Db: PreimageDb<M::Output>, M: MerkleHash + Default,

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<Db, M, const NS_ID_SIZE: usize> Freeze for NamespaceMerkleTree<Db, M, NS_ID_SIZE>
where Db: Freeze, M: Freeze, <M as MerkleHash>::Output: Freeze,

§

impl<Db, M, const NS_ID_SIZE: usize> !RefUnwindSafe for NamespaceMerkleTree<Db, M, NS_ID_SIZE>

§

impl<Db, M, const NS_ID_SIZE: usize> Send for NamespaceMerkleTree<Db, M, NS_ID_SIZE>
where Db: Send, M: Send, <M as MerkleHash>::Output: Send,

§

impl<Db, M, const NS_ID_SIZE: usize> Sync for NamespaceMerkleTree<Db, M, NS_ID_SIZE>
where Db: Sync, M: Sync, <M as MerkleHash>::Output: Sync,

§

impl<Db, M, const NS_ID_SIZE: usize> Unpin for NamespaceMerkleTree<Db, M, NS_ID_SIZE>
where Db: Unpin, M: Unpin, <M as MerkleHash>::Output: Unpin,

§

impl<Db, M, const NS_ID_SIZE: usize> !UnwindSafe for NamespaceMerkleTree<Db, M, NS_ID_SIZE>

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