From 6f871ba47df8aafe2f7ec7958e32ad5867f88786 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Thu, 31 Mar 2022 16:29:56 +0200 Subject: [PATCH] Add convenience LeafInfo::depth method Without this method computation of the leaf depth requires cloning due to the requirements of merkle_branch.into_inner() --- src/util/taproot.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/util/taproot.rs b/src/util/taproot.rs index 1ada92fa..ec8c1ca1 100644 --- a/src/util/taproot.rs +++ b/src/util/taproot.rs @@ -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 {