Skip to content

Commit 8247d16

Browse files
committed
Add convenience LeafInfo::depth method
Without this method computation of the leaf depth requires cloning due to the requirements of merkle_branch.into_inner()
1 parent 0d2a834 commit 8247d16

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/util/taproot.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,14 @@ impl LeafInfo {
627627
}
628628
}
629629

630+
/// Returns the depth of this script leaf in the tap tree.
631+
#[inline]
632+
pub fn depth(&self) -> u8 {
633+
// The depth is guaranteed to be < 127 by the TaprootBuilder type.
634+
// TODO: Following MSRV bump implement via `try_into().expect("")`.
635+
self.merkle_branch.0.len() as u8
636+
}
637+
630638
/// Computes a leaf hash for this [`LeafInfo`].
631639
#[inline]
632640
pub fn leaf_hash(&self) -> TapLeafHash {

0 commit comments

Comments
 (0)