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 ;
1212use crate :: util:: config:: UserConfig ;
1313use crate :: util:: ser:: { Readable , Writeable , Writer } ;
1414
@@ -29,7 +29,7 @@ pub struct InvalidShutdownScript {
2929 /// The script that did not meet the requirements from [BOLT #2].
3030 ///
3131 /// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
32- pub script : ScriptBuf
32+ pub script : ScriptBuf ,
3333}
3434
3535#[ derive( Clone , PartialEq , Eq ) ]
@@ -83,7 +83,9 @@ impl ShutdownScript {
8383 /// # Errors
8484 ///
8585 /// This function may return an error if `program` is invalid for the segwit `version`.
86- 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 > {
8789 Self :: try_from ( ScriptBuf :: new_witness_program ( witness_program) )
8890 }
8991
@@ -151,14 +153,15 @@ impl TryFrom<(ScriptBuf, &InitFeatures)> for ShutdownScript {
151153impl Into < ScriptBuf > for ShutdownScript {
152154 fn into ( self ) -> ScriptBuf {
153155 match self . 0 {
154- ShutdownScriptImpl :: Legacy ( pubkey) =>
155- ScriptBuf :: new_p2wpkh ( & WPubkeyHash :: hash ( & pubkey. serialize ( ) ) ) ,
156+ ShutdownScriptImpl :: Legacy ( pubkey) => {
157+ ScriptBuf :: new_p2wpkh ( & WPubkeyHash :: hash ( & pubkey. serialize ( ) ) )
158+ } ,
156159 ShutdownScriptImpl :: Bolt2 ( script_pubkey) => script_pubkey,
157160 }
158161 }
159162}
160163
161- impl core:: fmt:: Display for ShutdownScript {
164+ impl core:: fmt:: Display for ShutdownScript {
162165 fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
163166 match & self . 0 {
164167 ShutdownScriptImpl :: Legacy ( _) => self . clone ( ) . into_inner ( ) . fmt ( f) ,
@@ -171,18 +174,22 @@ impl core::fmt::Display for ShutdownScript{
171174mod shutdown_script_tests {
172175 use super :: ShutdownScript ;
173176
174- use bitcoin:: { WitnessProgram , WitnessVersion } ;
175177 use bitcoin:: opcodes;
176178 use bitcoin:: script:: { Builder , ScriptBuf } ;
177179 use bitcoin:: secp256k1:: Secp256k1 ;
178180 use bitcoin:: secp256k1:: { PublicKey , SecretKey } ;
181+ use bitcoin:: { WitnessProgram , WitnessVersion } ;
179182
180- use crate :: types:: features:: InitFeatures ;
181183 use crate :: prelude:: * ;
184+ use crate :: types:: features:: InitFeatures ;
182185
183186 fn pubkey ( ) -> bitcoin:: key:: PublicKey {
184187 let secp_ctx = Secp256k1 :: signing_only ( ) ;
185- 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 ( ) ;
186193 bitcoin:: key:: PublicKey :: new ( PublicKey :: from_secret_key ( & secp_ctx, & secret_key) )
187194 }
188195
0 commit comments