Struct OneshotMerkleTree

Source
pub struct OneshotMerkleTree { /* private fields */ }
Expand description

A Merkle tree that is created once but never modified.

This is useful for per-block data such as transaction lists.

Implementations§

Source§

impl OneshotMerkleTree

Source

pub const EMPTY_HASH: Hash256

Source

pub fn create(data: Vec<Hash256>) -> Self

Creates a new OneshotMerkleTree from the given data.

Source

pub fn create_merkle_proof(&self, key: Hash256) -> Option<MerkleProof>

Creates a Merkle proof for a given data in the tree.

Returns None if the data is not in the tree.

Given a tree [[1, 2, 3], [4, 5], [6]], Merkle proof for 2 is [1, 5] and Merkle proof for 3 is [OnlyChild, 4].

For LeftChild and RightChild, pair hash of the sibling node is given. For OnlyChild, only the instruction is given.

Source

pub fn root(&self) -> Hash256

Returns the root of the tree.

If the tree is empty, this returns a Self::EMPTY_HASH.

Never panics on unwrap because merkle_tree is initialized with vec![hash_list.to_vec()] where hash_list is not empty.

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

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

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

Source§

fn vzip(self) -> V