Struct MerkleTree

Source
pub struct MerkleTree {
    pub root: B256,
    /* private fields */
}
Expand description

A Merkle tree implementation supporting insertion of leaves, tree construction, proof generation, and proof verification.

Fields§

§root: B256

The root hash of the Merkle tree.

Implementations§

Source§

impl MerkleTree

Source

pub fn new() -> Self

Creates a new empty MerkleTree.

Source

pub fn set_sort(&mut self, sort: bool)

Sets whether the leaves should be sorted before tree construction.

Source

pub fn is_sorted(&self) -> bool

Checks if the leaves are set to be sorted.

Source

pub fn insert(&mut self, leaf: B256)

Inserts a new leaf into the Merkle tree.

Source

pub fn finish(&mut self)

Finalizes the tree construction by building all layers and computing the root hash.

If the tree has already been constructed, this method will do nothing.

Source

pub fn create_proof(&self, leaf: &B256) -> Option<MerkleProof>

Generates a Merkle proof for a given leaf.

An Option containing the MerkleProof if the leaf is found, or None if not.

Source

pub fn verify_proof(proof: &MerkleProof) -> bool

Verifies a Merkle proof against the root hash.

§Parameters
  • proof: The MerkleProof to verify.
§Returns

true if the proof is valid and corresponds to the root hash; otherwise, false.

Trait Implementations§

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

Creates a new empty MerkleTree with default values.

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