11//! Abstractions for scripts used in the Lightning Network.
22
3- use bitcoin:: { WitnessProgram , WPubkeyHash , WScriptHash } ;
3+ use bitcoin:: hashes :: Hash ;
44use bitcoin:: opcodes:: all:: OP_PUSHBYTES_0 as SEGWIT_V0 ;
55use bitcoin:: script:: { Script , ScriptBuf } ;
6- use bitcoin:: hashes:: Hash ;
76use bitcoin:: secp256k1:: PublicKey ;
7+ use bitcoin:: { WPubkeyHash , WScriptHash , WitnessProgram } ;
88
99use crate :: ln:: channelmanager;
10- use crate :: types:: features:: InitFeatures ;
1110use crate :: ln:: msgs:: DecodeError ;
11+ use crate :: types:: features:: InitFeatures ;
12+ use crate :: util:: config:: UserConfig ;
1213use crate :: util:: ser:: { Readable , Writeable , Writer } ;
1314
1415use crate :: io;
@@ -28,7 +29,7 @@ pub struct InvalidShutdownScript {
2829 /// The script that did not meet the requirements from [BOLT #2].
2930 ///
3031 /// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
31- pub script : ScriptBuf
32+ pub script : ScriptBuf ,
3233}
3334
3435#[ derive( Clone , PartialEq , Eq ) ]
@@ -82,7 +83,9 @@ impl ShutdownScript {
8283 /// # Errors
8384 ///
8485 /// This function may return an error if `program` is invalid for the segwit `version`.
85- pub fn new_witness_program ( witness_program : & WitnessProgram ) -> Result < Self , InvalidShutdownScript > {
86+ pub fn new_witness_program (
87+ witness_program : & WitnessProgram ,
88+ ) -> Result < Self , InvalidShutdownScript > {
8689 Self :: try_from ( ScriptBuf :: new_witness_program ( witness_program) )
8790 }
8891
@@ -128,7 +131,8 @@ impl TryFrom<ScriptBuf> for ShutdownScript {
128131 type Error = InvalidShutdownScript ;
129132
130133 fn try_from ( script : ScriptBuf ) -> Result < Self , Self :: Error > {
131- Self :: try_from ( ( script, & channelmanager:: provided_init_features ( & crate :: util:: config:: UserConfig :: default ( ) ) ) )
134+ let features = channelmanager:: provided_init_features ( & UserConfig :: default ( ) ) ;
135+ Self :: try_from ( ( script, & features) )
132136 }
133137}
134138
@@ -149,14 +153,15 @@ impl TryFrom<(ScriptBuf, &InitFeatures)> for ShutdownScript {
149153impl Into < ScriptBuf > for ShutdownScript {
150154 fn into ( self ) -> ScriptBuf {
151155 match self . 0 {
152- ShutdownScriptImpl :: Legacy ( pubkey) =>
153- ScriptBuf :: new_p2wpkh ( & WPubkeyHash :: hash ( & pubkey. serialize ( ) ) ) ,
156+ ShutdownScriptImpl :: Legacy ( pubkey) => {
157+ ScriptBuf :: new_p2wpkh ( & WPubkeyHash :: hash ( & pubkey. serialize ( ) ) )
158+ } ,
154159 ShutdownScriptImpl :: Bolt2 ( script_pubkey) => script_pubkey,
155160 }
156161 }
157162}
158163
159- impl core:: fmt:: Display for ShutdownScript {
164+ impl core:: fmt:: Display for ShutdownScript {
160165 fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
161166 match & self . 0 {
162167 ShutdownScriptImpl :: Legacy ( _) => self . clone ( ) . into_inner ( ) . fmt ( f) ,
@@ -169,18 +174,22 @@ impl core::fmt::Display for ShutdownScript{
169174mod shutdown_script_tests {
170175 use super :: ShutdownScript ;
171176
172- use bitcoin:: { WitnessProgram , WitnessVersion } ;
173177 use bitcoin:: opcodes;
174178 use bitcoin:: script:: { Builder , ScriptBuf } ;
175179 use bitcoin:: secp256k1:: Secp256k1 ;
176180 use bitcoin:: secp256k1:: { PublicKey , SecretKey } ;
181+ use bitcoin:: { WitnessProgram , WitnessVersion } ;
177182
178- use crate :: types:: features:: InitFeatures ;
179183 use crate :: prelude:: * ;
184+ use crate :: types:: features:: InitFeatures ;
180185
181186 fn pubkey ( ) -> bitcoin:: key:: PublicKey {
182187 let secp_ctx = Secp256k1 :: signing_only ( ) ;
183- let secret_key = SecretKey :: from_slice ( & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ] ) . unwrap ( ) ;
188+ let secret_key = SecretKey :: from_slice ( & [
189+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
190+ 0 , 0 , 1 ,
191+ ] )
192+ . unwrap ( ) ;
184193 bitcoin:: key:: PublicKey :: new ( PublicKey :: from_secret_key ( & secp_ctx, & secret_key) )
185194 }
186195
0 commit comments