Skip to content

Commit 90b1dbc

Browse files
committed
Use u8::try_from
Currently we use a cast to get the `u8` depth, as suggested by the TODO in the code we can now use `TryFrom` since we bumped the MSRV. Use `u8::try_from.expect("")` since, assuming the code comment is correct, the depth is guaranteed to be less that 127.
1 parent 9ee7b33 commit 90b1dbc

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/util/taproot.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,8 @@ impl ScriptLeaf {
604604
/// Returns the depth of this script leaf in the tap tree.
605605
#[inline]
606606
pub fn depth(&self) -> u8 {
607-
// The depth is guaranteed to be < 127 by the TaprootBuilder type.
608-
// TODO: Following MSRV bump implement via `try_into().expect("")`.
609-
self.merkle_branch.0.len() as u8
607+
// Depth is guarded by TAPROOT_CONTROL_MAX_NODE_COUNT.
608+
u8::try_from(self.merkle_branch.0.len()).expect("depth is guaranteed to fit in a u8")
610609
}
611610

612611
/// Computes a leaf hash for this [`ScriptLeaf`].

0 commit comments

Comments
 (0)