pub struct MerkleTree {
    pub root: Tree,
    pub height: usize,
    pub count: usize,
    pub nodes_count: usize,
}
Expand description

A Merkle tree is a binary tree, with values of type T at the leafs, and where every internal node holds the hash of the concatenation of the hashes of its children nodes.

Fields§

§root: Tree

The root of the inner binary tree

§height: usize

The height of the tree

§count: usize

The number of leaf nodes in the tree

§nodes_count: usize

The number of nodes in the tree

Implementations§

source§

impl MerkleTree

source

pub fn from_vec(values: Vec<Vec<u8>>) -> Result<Self, ValidationError>

Constructs a Merkle Tree from a vector of data blocks. Returns None if values is empty.

source

pub fn root_hash(&self) -> &Vec<u8>

Returns the root hash of Merkle tree

source

pub fn root_hash_hex(&self) -> String

Returns the hex root hash of Merkle tree

source

pub fn height(&self) -> usize

Returns the height of Merkle tree

source

pub fn count(&self) -> usize

Returns the number of leaves in the Merkle tree

source

pub fn is_empty(&self) -> bool

Returns whether the Merkle tree is empty or not

source

pub fn gen_proof( &self, value: Vec<u8> ) -> Result<Option<Proof>, ValidationError>

Generate an inclusion proof for the given value. Returns None if the given value is not found in the tree.

source

pub fn iter(&self) -> LeavesIterator<'_>

Creates an Iterator over the values contained in this Merkle tree.

source§

impl MerkleTree

source

pub fn find_hash<'a>( from: &'a Tree, required_hash: &Vec<u8> ) -> Option<&'a Tree>

source

pub fn consistency_proof( &self, new_root_hash: &Vec<u8>, new_size: usize, proof: &[Vec<u8>] ) -> Result<bool, ValidationError>

source

pub fn append(&mut self, node: Vec<u8>) -> Result<(), ValidationError>

source

pub fn check_inclusion_proof( root_hash: &[u8], leaf_value: &Vec<u8>, path: &[Positioned<Vec<u8>>] ) -> Result<bool, ValidationError>

Trait Implementations§

source§

impl Clone for MerkleTree

source§

fn clone(&self) -> MerkleTree

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for MerkleTree

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for MerkleTree

source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for MerkleTree

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'a> IntoIterator for &'a MerkleTree

source§

fn into_iter(self) -> Self::IntoIter

Creates a borrowing Iterator over the values contained in this Merkle tree.

§

type Item = &'a Vec<u8>

The type of the elements being iterated over.
§

type IntoIter = LeavesIterator<'a>

Which kind of iterator are we turning this into?
source§

impl IntoIterator for MerkleTree

source§

fn into_iter(self) -> Self::IntoIter

Creates a consuming iterator, that is, one that moves each value out of the Merkle tree. The tree cannot be used after calling this.

§

type Item = Vec<u8>

The type of the elements being iterated over.
§

type IntoIter = LeavesIntoIterator

Which kind of iterator are we turning this into?
source§

impl Serialize for MerkleTree

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,