Struct incrementalmerkletree::witness::IncrementalWitness
source · 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>
impl<H, const DEPTH: u8> IncrementalWitness<H, DEPTH>
sourcepub fn from_tree(tree: CommitmentTree<H, DEPTH>) -> Self
pub fn from_tree(tree: CommitmentTree<H, DEPTH>) -> Self
Creates an IncrementalWitness
for the most recent commitment added to the given
CommitmentTree
.
pub fn from_parts( tree: CommitmentTree<H, DEPTH>, filled: Vec<H>, cursor: Option<CommitmentTree<H, DEPTH>> ) -> Self
pub fn tree(&self) -> &CommitmentTree<H, DEPTH>
pub fn filled(&self) -> &Vec<H>
pub fn cursor(&self) -> &Option<CommitmentTree<H, DEPTH>>
sourcepub fn witnessed_position(&self) -> Position
pub fn witnessed_position(&self) -> Position
Returns the position of the witnessed leaf node in the commitment tree.
sourcepub fn tip_position(&self) -> Position
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>
impl<H: Hashable + Clone, const DEPTH: u8> IncrementalWitness<H, DEPTH>
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more