Skip to content

Commit 70289aa

Browse files
committed
Merge rust-bitcoin/rust-bitcoin#1121: Use u8::try_from
517059e Use u8::try_from (Tobin C. Harding) Pull request description: 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 depth (node count) is guarded by `TAPROOT_CONTROL_MAX_NODE_COUNT`. ACKs for top commit: Kixunil: ACK 517059e apoelstra: ACK 517059e Tree-SHA512: 98e58617247a05025ec13ad3d00a464cb2351c98c6d871be43b252d3982e291b7187e25780e7fe367f5a3a64fa20f3b328876a8901af4da09e675f50727a26cf
2 parents e9939e9 + 90b1dbc commit 70289aa

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
@@ -610,9 +610,8 @@ impl ScriptLeaf {
610610
/// Returns the depth of this script leaf in the tap tree.
611611
#[inline]
612612
pub fn depth(&self) -> u8 {
613-
// The depth is guaranteed to be < 127 by the TaprootBuilder type.
614-
// TODO: Following MSRV bump implement via `try_into().expect("")`.
615-
self.merkle_branch.0.len() as u8
613+
// Depth is guarded by TAPROOT_CONTROL_MAX_NODE_COUNT.
614+
u8::try_from(self.merkle_branch.0.len()).expect("depth is guaranteed to fit in a u8")
616615
}
617616

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

0 commit comments

Comments
 (0)