Struct zcash_history::Tree

source ·
pub struct Tree<V: Version> { /* private fields */ }
Expand description

Represents partially loaded tree.

Some kind of “view” into the array representation of the MMR tree. With only some of the leaves/nodes pre-loaded / pre-generated. Exact amount of the loaded data can be calculated by the constructing party, depending on the length of the tree and maximum amount of operations that are going to happen after construction. Tree should not be used as self-contained data structure, since it’s internal state can grow indefinitely after serial operations. Intended use of this Tree is to instantiate it based on partially loaded data (see example how to pick right nodes from the array representation of MMR Tree), perform several operations (append-s/delete-s) and then drop it.

Implementations§

source§

impl<V: Version> Tree<V>

Resolve link originated from this tree

source

pub fn new( length: u32, peaks: Vec<(u32, Entry<V>)>, extra: Vec<(u32, Entry<V>)> ) -> Self

New view into the the tree array representation

length is total length of the array representation (is generally not a sum of peaks.len + extra.len) peaks is peaks of the mmr tree extra is some extra nodes that calculated to be required during next one or more operations on the tree.

§Panics

Will panic if peaks is empty.

source

pub fn append_leaf( &mut self, new_leaf: V::NodeData ) -> Result<Vec<EntryLink>, Error>

Append one leaf to the tree.

Returns links to actual nodes that has to be persisted as the result of the append. If completed without error, at least one link to the appended node (with metadata provided in new_leaf) will be returned.

source

pub fn truncate_leaf(&mut self) -> Result<u32, Error>

Truncate one leaf from the end of the tree.

Returns actual number of nodes that should be removed by the caller from the end of the array representation.

source

pub fn len(&self) -> u32

Length of array representation of the tree.

source

pub fn root(&self) -> EntryLink

Link to the root node

source

pub fn root_node(&self) -> Result<IndexedNode<'_, V>, Error>

Reference to the root node.

source

pub fn is_empty(&self) -> bool

If this tree is empty.

Auto Trait Implementations§

§

impl<V> RefUnwindSafe for Tree<V>

§

impl<V> Send for Tree<V>
where <V as Version>::NodeData: Send,

§

impl<V> Sync for Tree<V>
where <V as Version>::NodeData: Sync,

§

impl<V> Unpin for Tree<V>
where <V as Version>::NodeData: Unpin,

§

impl<V> UnwindSafe for Tree<V>
where <V as Version>::NodeData: 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, 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.