pub struct IncrementalWitness<H, const DEPTH: u8> { /* private fields */ }
Available on crate feature legacy-api only.
Expand description

An updatable witness to a path from a position in a particular CommitmentTree.

Appending the same commitments in the same order to both the original CommitmentTree and this IncrementalWitness will result in a witness to the path from the target position to the root of the updated tree.

§Examples

use incrementalmerkletree::{
    frontier::{CommitmentTree, testing::TestNode},
    witness::IncrementalWitness,
    Position
};

let mut tree = CommitmentTree::<TestNode, 8>::empty();

tree.append(TestNode(0));
tree.append(TestNode(1));
let mut witness = IncrementalWitness::from_tree(tree.clone());
assert_eq!(witness.witnessed_position(), Position::from(1));
assert_eq!(tree.root(), witness.root());

let next = TestNode(2);
tree.append(next.clone());
witness.append(next);
assert_eq!(tree.root(), witness.root());

Implementations§

source§

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

source

pub fn from_tree(tree: CommitmentTree<H, DEPTH>) -> Self

Creates an IncrementalWitness for the most recent commitment added to the given CommitmentTree.

source

pub fn from_parts( tree: CommitmentTree<H, DEPTH>, filled: Vec<H>, cursor: Option<CommitmentTree<H, DEPTH>> ) -> Self

source

pub fn tree(&self) -> &CommitmentTree<H, DEPTH>

source

pub fn filled(&self) -> &Vec<H>

source

pub fn cursor(&self) -> &Option<CommitmentTree<H, DEPTH>>

source

pub fn witnessed_position(&self) -> Position

Returns the position of the witnessed leaf node in the commitment tree.

source

pub fn tip_position(&self) -> Position

Returns the position of the last leaf appended to the witness.

source§

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

source

pub fn append(&mut self, node: H) -> Result<(), ()>

Tracks a leaf node that has been added to the underlying tree.

Returns an error if the tree is full.

source

pub fn root(&self) -> H

Returns the current root of the tree corresponding to the witness.

source

pub fn path(&self) -> Option<MerklePath<H, DEPTH>>

Returns the current witness, or None if the tree is empty.

Trait Implementations§

source§

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

source§

fn clone(&self) -> IncrementalWitness<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 IncrementalWitness<H, DEPTH>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<H, const DEPTH: u8> UnwindSafe for IncrementalWitness<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