X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fscript.rs;h=dc733dd25a1f0ca154c773f1987d4861e4d30a23;hb=3eb61f7e9b55531626936cf84c57cd7530a878a4;hp=079416eae77d29dcca818256950451a4b835eb7a;hpb=5d187f65b993cc4862f37f6fceaa6cccd6561dc9;p=rust-lightning diff --git a/lightning/src/ln/script.rs b/lightning/src/ln/script.rs index 079416ea..dc733dd2 100644 --- a/lightning/src/ln/script.rs +++ b/lightning/src/ln/script.rs @@ -1,11 +1,11 @@ //! Abstractions for scripts used in the Lightning Network. use bitcoin::blockdata::opcodes::all::OP_PUSHBYTES_0 as SEGWIT_V0; -use bitcoin::blockdata::script::{Builder, Script}; +use bitcoin::blockdata::script::{Script, ScriptBuf}; use bitcoin::hashes::Hash; use bitcoin::hash_types::{WPubkeyHash, WScriptHash}; use bitcoin::secp256k1::PublicKey; -use bitcoin::util::address::WitnessVersion; +use bitcoin::address::WitnessProgram; use crate::ln::channelmanager; use crate::ln::features::InitFeatures; @@ -21,13 +21,13 @@ use crate::io; #[derive(Clone, PartialEq, Eq)] pub struct ShutdownScript(ShutdownScriptImpl); -/// An error occurring when converting from [`Script`] to [`ShutdownScript`]. +/// An error occurring when converting from [`ScriptBuf`] to [`ShutdownScript`]. #[derive(Clone, Debug)] pub struct InvalidShutdownScript { /// The script that did not meet the requirements from [BOLT #2]. /// /// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md - pub script: Script + pub script: ScriptBuf } #[derive(Clone, PartialEq, Eq)] @@ -36,8 +36,8 @@ enum ShutdownScriptImpl { /// serialization. Legacy(PublicKey), - /// [`Script`] adhering to a script pubkey format specified in BOLT #2. - Bolt2(Script), + /// [`ScriptBuf`] adhering to a script pubkey format specified in BOLT #2. + Bolt2(ScriptBuf), } impl Writeable for ShutdownScript { @@ -65,12 +65,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_p2wpkh(pubkey_hash))) + Self(ShutdownScriptImpl::Bolt2(ScriptBuf::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_p2wsh(script_hash))) + Self(ShutdownScriptImpl::Bolt2(ScriptBuf::new_v0_p2wsh(script_hash))) } /// Generates a witness script pubkey from the given segwit version and program. @@ -81,16 +81,12 @@ impl ShutdownScript { /// # Errors /// /// This function may return an error if `program` is invalid for the segwit `version`. - pub fn new_witness_program(version: WitnessVersion, program: &[u8]) -> Result { - let script = Builder::new() - .push_int(version as i64) - .push_slice(&program) - .into_script(); - Self::try_from(script) + pub fn new_witness_program(witness_program: &WitnessProgram) -> Result { + Self::try_from(ScriptBuf::new_witness_program(witness_program)) } - /// Converts the shutdown script into the underlying [`Script`]. - pub fn into_inner(self) -> Script { + /// Converts the shutdown script into the underlying [`ScriptBuf`]. + pub fn into_inner(self) -> ScriptBuf { self.into() } @@ -127,20 +123,20 @@ pub(crate) fn is_bolt2_compliant(script: &Script, features: &InitFeatures) -> bo // Note that this is only for our own shutdown scripts. Counterparties are still allowed to send us // non-witness shutdown scripts which this rejects. -impl TryFrom