Add convenience LeafInfo::depth method

Without this method computation of the leaf depth requires cloning due
to the requirements of merkle_branch.into_inner()
This commit is contained in:
Dr Maxim Orlovsky 2022-03-31 16:29:56 +02:00
parent 3c502ffc2d
commit 6f871ba47d
No known key found for this signature in database
GPG Key ID: FFC0250947E5C6F7
1 changed files with 8 additions and 0 deletions

View File

@ -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 {