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:: ser:: { Readable , Writeable , Writer } ;
1313
1414use crate :: io;
@@ -28,7 +28,7 @@ pub struct InvalidShutdownScript {
2828 /// The script that did not meet the requirements from [BOLT #2].
2929 ///
3030 /// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
31- pub script : ScriptBuf
31+ pub script : ScriptBuf ,
3232}
3333
3434#[ derive( Clone , PartialEq , Eq ) ]
@@ -82,7 +82,9 @@ impl ShutdownScript {
8282 /// # Errors
8383 ///
8484 /// 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 > {
85+ pub fn new_witness_program (
86+ witness_program : & WitnessProgram ,
87+ ) -> Result < Self , InvalidShutdownScript > {
8688 Self :: try_from ( ScriptBuf :: new_witness_program ( witness_program) )
8789 }
8890
@@ -128,7 +130,10 @@ impl TryFrom<ScriptBuf> for ShutdownScript {
128130 type Error = InvalidShutdownScript ;
129131
130132 fn try_from ( script : ScriptBuf ) -> Result < Self , Self :: Error > {
131- Self :: try_from ( ( script, & channelmanager:: provided_init_features ( & crate :: util:: config:: UserConfig :: default ( ) ) ) )
133+ Self :: try_from ( (
134+ script,
135+ & channelmanager:: provided_init_features ( & crate :: util:: config:: UserConfig :: default ( ) ) ,
136+ ) )
132137 }
133138}
134139
@@ -149,14 +154,15 @@ impl TryFrom<(ScriptBuf, &InitFeatures)> for ShutdownScript {
149154impl Into < ScriptBuf > for ShutdownScript {
150155 fn into ( self ) -> ScriptBuf {
151156 match self . 0 {
152- ShutdownScriptImpl :: Legacy ( pubkey) =>
153- ScriptBuf :: new_p2wpkh ( & WPubkeyHash :: hash ( & pubkey. serialize ( ) ) ) ,
157+ ShutdownScriptImpl :: Legacy ( pubkey) => {
158+ ScriptBuf :: new_p2wpkh ( & WPubkeyHash :: hash ( & pubkey. serialize ( ) ) )
159+ } ,
154160 ShutdownScriptImpl :: Bolt2 ( script_pubkey) => script_pubkey,
155161 }
156162 }
157163}
158164
159- impl core:: fmt:: Display for ShutdownScript {
165+ impl core:: fmt:: Display for ShutdownScript {
160166 fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
161167 match & self . 0 {
162168 ShutdownScriptImpl :: Legacy ( _) => self . clone ( ) . into_inner ( ) . fmt ( f) ,
@@ -169,18 +175,22 @@ impl core::fmt::Display for ShutdownScript{
169175mod shutdown_script_tests {
170176 use super :: ShutdownScript ;
171177
172- use bitcoin:: { WitnessProgram , WitnessVersion } ;
173178 use bitcoin:: opcodes;
174179 use bitcoin:: script:: { Builder , ScriptBuf } ;
175180 use bitcoin:: secp256k1:: Secp256k1 ;
176181 use bitcoin:: secp256k1:: { PublicKey , SecretKey } ;
182+ use bitcoin:: { WitnessProgram , WitnessVersion } ;
177183
178- use crate :: types:: features:: InitFeatures ;
179184 use crate :: prelude:: * ;
185+ use crate :: types:: features:: InitFeatures ;
180186
181187 fn pubkey ( ) -> bitcoin:: key:: PublicKey {
182188 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 ( ) ;
189+ let secret_key = SecretKey :: from_slice ( & [
190+ 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 ,
191+ 0 , 0 , 1 ,
192+ ] )
193+ . unwrap ( ) ;
184194 bitcoin:: key:: PublicKey :: new ( PublicKey :: from_secret_key ( & secp_ctx, & secret_key) )
185195 }
186196
0 commit comments