X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fscript.rs;h=6c1d2102400786d41a124eafd26db70903bb82d2;hb=783e8188a7bd6470d5926bf5d1bae1350996801a;hp=0c060e4523374b71f569c5a4338d617177dfe6ba;hpb=13e4fd586ed0c8439dcada150c4fffa33fa67db9;p=rust-lightning diff --git a/lightning/src/ln/script.rs b/lightning/src/ln/script.rs index 0c060e45..6c1d2102 100644 --- a/lightning/src/ln/script.rs +++ b/lightning/src/ln/script.rs @@ -4,32 +4,33 @@ use bitcoin::blockdata::opcodes::all::OP_PUSHBYTES_0 as SEGWIT_V0; use bitcoin::blockdata::script::{Builder, Script}; use bitcoin::hashes::Hash; use bitcoin::hash_types::{WPubkeyHash, WScriptHash}; -use bitcoin::secp256k1::key::PublicKey; +use bitcoin::secp256k1::PublicKey; +use bitcoin::util::address::WitnessVersion; -use ln::features::InitFeatures; -use ln::msgs::DecodeError; -use util::ser::{Readable, Writeable, Writer}; +use crate::ln::channelmanager; +use crate::ln::features::InitFeatures; +use crate::ln::msgs::DecodeError; +use crate::util::ser::{Readable, Writeable, Writer}; use core::convert::TryFrom; -use core::num::NonZeroU8; -use io; +use crate::io; /// A script pubkey for shutting down a channel as defined by [BOLT #2]. /// -/// [BOLT #2]: https://github.com/lightningnetwork/lightning-rfc/blob/master/02-peer-protocol.md -#[derive(Clone, PartialEq)] +/// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md +#[derive(Clone, PartialEq, Eq)] pub struct ShutdownScript(ShutdownScriptImpl); /// An error occurring when converting from [`Script`] to [`ShutdownScript`]. -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct InvalidShutdownScript { /// The script that did not meet the requirements from [BOLT #2]. /// - /// [BOLT #2]: https://github.com/lightningnetwork/lightning-rfc/blob/master/02-peer-protocol.md + /// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md pub script: Script } -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] enum ShutdownScriptImpl { /// [`PublicKey`] used to form a P2WPKH script pubkey. Used to support backward-compatible /// serialization. @@ -68,12 +69,12 @@ impl ShutdownScript { /// Generates a P2WPKH script pubkey from the given [`WPubkeyHash`]. pub fn new_p2wpkh(pubkey_hash: &WPubkeyHash) -> Self { - Self(ShutdownScriptImpl::Bolt2(Script::new_v0_wpkh(pubkey_hash))) + Self(ShutdownScriptImpl::Bolt2(Script::new_v0_p2wpkh(pubkey_hash))) } /// Generates a P2WSH script pubkey from the given [`WScriptHash`]. pub fn new_p2wsh(script_hash: &WScriptHash) -> Self { - Self(ShutdownScriptImpl::Bolt2(Script::new_v0_wsh(script_hash))) + Self(ShutdownScriptImpl::Bolt2(Script::new_v0_p2wsh(script_hash))) } /// Generates a witness script pubkey from the given segwit version and program. @@ -84,9 +85,9 @@ impl ShutdownScript { /// # 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 { + pub fn new_witness_program(version: WitnessVersion, program: &[u8]) -> Result { let script = Builder::new() - .push_int(version.get().into()) + .push_int(version as i64) .push_slice(&program) .into_script(); Self::try_from(script) @@ -122,7 +123,7 @@ pub(crate) fn is_bolt2_compliant(script: &Script, features: &InitFeatures) -> bo if script.is_p2pkh() || script.is_p2sh() || script.is_v0_p2wpkh() || script.is_v0_p2wsh() { true } else if features.supports_shutdown_anysegwit() { - script.is_witness_program() && script.as_bytes()[0] != SEGWIT_V0.into_u8() + script.is_witness_program() && script.as_bytes()[0] != SEGWIT_V0.to_u8() } else { false } @@ -134,7 +135,7 @@ impl TryFrom