517059e148 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 517059e148
  apoelstra:
    ACK 517059e148

Tree-SHA512: 98e58617247a05025ec13ad3d00a464cb2351c98c6d871be43b252d3982e291b7187e25780e7fe367f5a3a64fa20f3b328876a8901af4da09e675f50727a26cf
This commit is contained in:
Andrew Poelstra 2022-07-24 22:29:45 +00:00
commit 9f0ff6f0a4
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 2 additions and 3 deletions

View File

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