From: Jeffrey Czyz Date: Fri, 30 Jul 2021 21:03:01 +0000 (-0500) Subject: f - Accept only non-v0 witness programs X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=a21abe2b5ab67228a820cde7ce9b1c59970ca75d;p=rust-lightning f - Accept only non-v0 witness programs --- diff --git a/lightning/src/ln/script.rs b/lightning/src/ln/script.rs index c2987f739..589c3f311 100644 --- a/lightning/src/ln/script.rs +++ b/lightning/src/ln/script.rs @@ -10,6 +10,7 @@ use bitcoin::secp256k1::key::PublicKey; use ln::features::InitFeatures; use std::convert::TryFrom; +use core::num::NonZeroU8; /// A script pubkey for shutting down a channel as defined by [BOLT #2]. /// @@ -60,7 +61,8 @@ impl ShutdownScript { /// # Panics /// /// This function may panic if given a segwit program with an invalid length. - pub fn new_witness_program(version: u5, program: &[u8]) -> Self { + pub fn new_witness_program(version: NonZeroU8, program: &[u8]) -> Self { + let version = u5::try_from_u8(version.get()).expect("Invalid segwit version"); let script = Script::new_witness_program(version, program); Self::try_from(script).expect("Invalid segwit program") }