From 517059e1489d51fd40f0d58876fb992446f6eac4 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 22 Jul 2022 13:39:54 +1000 Subject: [PATCH] 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. --- src/util/taproot.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/util/taproot.rs b/src/util/taproot.rs index eb1ca806..11d23b81 100644 --- a/src/util/taproot.rs +++ b/src/util/taproot.rs @@ -604,9 +604,8 @@ impl ScriptLeaf { /// 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 + // Depth is guarded by TAPROOT_CONTROL_MAX_NODE_COUNT. + u8::try_from(self.merkle_branch.0.len()).expect("depth is guaranteed to fit in a u8") } /// Computes a leaf hash for this [`ScriptLeaf`].