Skip to content

Commit

Permalink
Add convenience LeafInfo::depth method
Browse files Browse the repository at this point in the history
Without this method computation of the leaf depth requires cloning due
to the requirements of merkle_branch.into_inner()
  • Loading branch information
dr-orlovsky committed Apr 19, 2022
1 parent 3c502ff commit 6f871ba
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/util/taproot.rs
Expand Up @@ -627,6 +627,14 @@ impl LeafInfo {
}
}

/// Returns the depth of this script leaf in the tap tree.
#[inline]
pub fn depth(&self) -> u8 {
// The depth is guaranteed to be < 127 by the TaprootBuilder type.
// TODO: Following MSRV bump implement via `try_into().expect("")`.
self.merkle_branch.0.len() as u8
}

/// Computes a leaf hash for this [`LeafInfo`].
#[inline]
pub fn leaf_hash(&self) -> TapLeafHash {
Expand Down

0 comments on commit 6f871ba

Please sign in to comment.