pub struct Frontier<H, const DEPTH: u8> { /* private fields */ }
Expand description

A possibly-empty Merkle frontier.

Implementations§

source§

impl<H, const DEPTH: u8> Frontier<H, DEPTH>

source

pub fn empty() -> Self

Constructs a new empty frontier.

source

pub fn from_parts( position: Position, leaf: H, ommers: Vec<H> ) -> Result<Self, FrontierError>

Constructs a new frontier from its constituent parts.

Returns an error if the new frontier would exceed the maximum allowed depth or if the list of ommers provided is not consistent with the position of the leaf.

source

pub fn value(&self) -> Option<&NonEmptyFrontier<H>>

Return the wrapped NonEmptyFrontier reference, or None if the frontier is empty.

source

pub fn take(self) -> Option<NonEmptyFrontier<H>>

Consumes this wrapper and returns the underlying Option<NonEmptyFrontier>

source

pub fn dynamic_memory_usage(&self) -> usize

Returns the amount of memory dynamically allocated for ommer values within the frontier.

source

pub fn tree_size(&self) -> u64

Returns the size of the Merkle tree that this frontier corresponds to.

source§

impl<H: Hashable + Clone, const DEPTH: u8> Frontier<H, DEPTH>

source

pub fn append(&mut self, value: H) -> bool

Appends a new value to the frontier at the next available slot. Returns true if successful and false if the frontier would exceed the maximum allowed depth.

source

pub fn root(&self) -> H

Obtains the current root of this Merkle frontier by hashing against empty nodes up to the maximum height of the pruned tree that the frontier represents.

source

pub fn witness<F>( &self, complement_nodes: F ) -> Result<Option<MerklePath<H, DEPTH>>, Address>
where F: Fn(Address) -> Option<H>,

Constructs a MerklePath to the leaf at the tip of this frontier, given a source of node values that complement this frontier.

If the complement_nodes function returns None when the value is requested at a given tree address, the address at which the failure occurs will be returned as an error.

Returns Ok(Some(MerklePath)) if successful, Ok(None) if the frontier is empty, or an error containing the address of the failure.

source§

impl<H: Hashable + Clone, const DEPTH: u8> Frontier<H, DEPTH>

source

pub fn random_of_size<R: RngCore>(rng: &mut R, tree_size: u64) -> Self

Generates a random frontier of a Merkle tree having the specified size.

source

pub fn random_with_prior_subtree_roots<R: RngCore>( rng: &mut R, tree_size: u64, subtree_depth: NonZeroU8 ) -> (Vec<H>, Self)

Trait Implementations§

source§

impl<H: Clone, const DEPTH: u8> Clone for Frontier<H, DEPTH>

source§

fn clone(&self) -> Frontier<H, DEPTH>

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<H: Debug, const DEPTH: u8> Debug for Frontier<H, DEPTH>

source§

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

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

impl<H: Hashable + Clone, const DEPTH: u8> Frontier<H> for Frontier<H, DEPTH>

source§

fn append(&mut self, value: H) -> bool

Available on crate feature test-dependencies only.
Appends a new value to the frontier at the next available slot. Returns true if successful and false if the frontier would exceed the maximum allowed depth.
source§

fn root(&self) -> H

Available on crate feature test-dependencies only.
Obtains the current root of this Merkle frontier by hashing against empty nodes up to the maximum height of the pruned tree that the frontier represents.
source§

impl<H: PartialEq, const DEPTH: u8> PartialEq for Frontier<H, DEPTH>

source§

fn eq(&self, other: &Frontier<H, DEPTH>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<H, const DEPTH: u8> TryFrom<NonEmptyFrontier<H>> for Frontier<H, DEPTH>

§

type Error = FrontierError

The type returned in the event of a conversion error.
source§

fn try_from(f: NonEmptyFrontier<H>) -> Result<Self, FrontierError>

Performs the conversion.
source§

impl<H: Eq, const DEPTH: u8> Eq for Frontier<H, DEPTH>

source§

impl<H, const DEPTH: u8> StructuralPartialEq for Frontier<H, DEPTH>

Auto Trait Implementations§

§

impl<H, const DEPTH: u8> Freeze for Frontier<H, DEPTH>
where H: Freeze,

§

impl<H, const DEPTH: u8> RefUnwindSafe for Frontier<H, DEPTH>
where H: RefUnwindSafe,

§

impl<H, const DEPTH: u8> Send for Frontier<H, DEPTH>
where H: Send,

§

impl<H, const DEPTH: u8> Sync for Frontier<H, DEPTH>
where H: Sync,

§

impl<H, const DEPTH: u8> Unpin for Frontier<H, DEPTH>
where H: Unpin,

§

impl<H, const DEPTH: u8> UnwindSafe for Frontier<H, DEPTH>
where 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<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> 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.
source§

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

source§

fn vzip(self) -> V