use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::hashes::Hash;
use bitcoin::hash_types::WPubkeyHash;
- use core::num::NonZeroU8;
use bitcoin::bech32::u5;
+ use bitcoin::util::address::WitnessVersion;
use prelude::*;
struct TestFeeEstimator {
fn upfront_shutdown_script_incompatibility() {
let features = InitFeatures::known().clear_shutdown_anysegwit();
let non_v0_segwit_shutdown_script =
- ShutdownScript::new_witness_program(NonZeroU8::new(16).unwrap(), &[0, 40]).unwrap();
+ ShutdownScript::new_witness_program(WitnessVersion::V16, &[0, 40]).unwrap();
let seed = [42; 32];
let network = Network::Testnet;
use bitcoin::hashes::Hash;
use bitcoin::hash_types::{WPubkeyHash, WScriptHash};
use bitcoin::secp256k1::PublicKey;
+use bitcoin::util::address::WitnessVersion;
use ln::features::InitFeatures;
use ln::msgs::DecodeError;
use util::ser::{Readable, Writeable, Writer};
use core::convert::TryFrom;
-use core::num::NonZeroU8;
use io;
/// A script pubkey for shutting down a channel as defined by [BOLT #2].
/// # Errors
///
/// This function may return an error if `program` is invalid for the segwit `version`.
- pub fn new_witness_program(version: NonZeroU8, program: &[u8]) -> Result<Self, InvalidShutdownScript> {
+ pub fn new_witness_program(version: WitnessVersion, program: &[u8]) -> Result<Self, InvalidShutdownScript> {
let script = Builder::new()
- .push_int(version.get().into())
+ .push_int(version as i64)
.push_slice(&program)
.into_script();
Self::try_from(script)
use bitcoin::secp256k1::{PublicKey, SecretKey};
use ln::features::InitFeatures;
use core::convert::TryFrom;
- use core::num::NonZeroU8;
use bitcoin::util::address::WitnessVersion;
fn pubkey() -> bitcoin::util::key::PublicKey {
#[test]
fn generates_segwit_from_non_v0_witness_program() {
let witness_program = Script::new_witness_program(WitnessVersion::V16, &[0; 40]);
-
- let version = NonZeroU8::new(WitnessVersion::V16 as u8).unwrap();
- let shutdown_script = ShutdownScript::new_witness_program(version, &[0; 40]).unwrap();
+ let shutdown_script = ShutdownScript::new_witness_program(WitnessVersion::V16, &[0; 40]).unwrap();
assert!(shutdown_script.is_compatible(&InitFeatures::known()));
assert!(!shutdown_script.is_compatible(&InitFeatures::known().clear_shutdown_anysegwit()));
assert_eq!(shutdown_script.into_inner(), witness_program);
assert!(ShutdownScript::try_from(op_return).is_err());
}
- #[test]
- fn fails_from_invalid_segwit_version() {
- let version = NonZeroU8::new(17).unwrap();
- assert!(ShutdownScript::new_witness_program(version, &[0; 40]).is_err());
- }
-
#[test]
fn fails_from_invalid_segwit_v0_witness_program() {
let witness_program = Script::new_witness_program(WitnessVersion::V0, &[0; 2]);
let witness_program = Script::new_witness_program(WitnessVersion::V16, &[0; 42]);
assert!(ShutdownScript::try_from(witness_program).is_err());
- let version = NonZeroU8::new(WitnessVersion::V16 as u8).unwrap();
- assert!(ShutdownScript::new_witness_program(version, &[0; 42]).is_err());
+ assert!(ShutdownScript::new_witness_program(WitnessVersion::V16, &[0; 42]).is_err());
}
}
use bitcoin::blockdata::script::Builder;
use bitcoin::blockdata::opcodes;
use bitcoin::network::constants::Network;
+use bitcoin::util::address::WitnessVersion;
use regex;
use core::default::Default;
-use core::num::NonZeroU8;
use ln::functional_test_utils::*;
use ln::msgs::OptionalField::Present;
// Check that using an unsupported shutdown script fails and a supported one succeeds.
let supported_shutdown_script = chanmon_cfgs[1].keys_manager.get_shutdown_scriptpubkey();
let unsupported_shutdown_script =
- ShutdownScript::new_witness_program(NonZeroU8::new(16).unwrap(), &[0, 40]).unwrap();
+ ShutdownScript::new_witness_program(WitnessVersion::V16, &[0, 40]).unwrap();
chanmon_cfgs[1].keys_manager
.expect(OnGetShutdownScriptpubkey { returns: unsupported_shutdown_script.clone() })
.expect(OnGetShutdownScriptpubkey { returns: supported_shutdown_script });