Struct CommitTree

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

Encapsulates a Merkle tree and provides functions for generating and comparing proofs.

Implementations§

Source§

impl CommitTree

Source

pub fn new() -> Self

Create a new empty commit tree.

Source

pub fn hash(data: &[u8]) -> TreeHash

Compute the Sha256 hash of some data.

Source

pub fn len(&self) -> usize

Number of leaves in the tree.

Source

pub fn is_empty(&self) -> bool

Determine if this commit tree is empty.

Source

pub fn insert(&mut self, hash: TreeHash) -> &mut Self

Insert a commit hash into the tree,

Source

pub fn append(&mut self, hashes: &mut Vec<TreeHash>) -> &mut Self

Append a collections of commit hashes to the tree.

Source

pub fn commit(&mut self)

Commit changes to the tree to compute the root.

Source

pub fn rollback(&mut self)

Revert changes to the tree.

Source

pub fn leaves(&self) -> Option<Vec<TreeHash>>

Leaves of the tree.

Source

pub fn head(&self) -> Result<CommitProof, Error>

Root hash and a proof of the last leaf node.

Source

pub fn proof(&self, leaf_indices: &[usize]) -> Result<CommitProof, Error>

Proof for the given indices.

Source

pub fn compare(&self, proof: &CommitProof) -> Result<Comparison, Error>

Compare this tree against another root hash and merkle proof.

Source

pub fn first_commit(&self) -> Result<CommitState, Error>

Compute the first commit state.

Must have at least one commit.

Source

pub fn last_commit(&self) -> Option<CommitHash>

Last commit hash in the underlying merkle tree.

Source

pub fn commit_state(&self) -> Result<CommitState, Error>

Commit state of this tree.

The tree must already have some commits.

Source

pub fn root(&self) -> Option<CommitHash>

Root hash of the underlying merkle tree.

Source

pub fn root_hex(&self) -> Option<String>

Root hash of the underlying merkle tree as hexadecimal.

Source

pub fn contains( &self, other_proof: &CommitProof, ) -> Result<Option<CommitProof>, Error>

Given a proof from another tree determine if this tree contains the other proof.

Trait Implementations§

Source§

impl Default for CommitTree

Source§

fn default() -> CommitTree

Returns the “default value” for a type. Read more

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

Source§

impl<T> ErasedDestructor for T
where T: 'static,