1
1
//! Abstractions for scripts used in the Lightning Network.
2
2
3
- use bitcoin:: { WitnessProgram , WPubkeyHash , WScriptHash } ;
3
+ use bitcoin:: hashes :: Hash ;
4
4
use bitcoin:: opcodes:: all:: OP_PUSHBYTES_0 as SEGWIT_V0 ;
5
5
use bitcoin:: script:: { Script , ScriptBuf } ;
6
- use bitcoin:: hashes:: Hash ;
7
6
use bitcoin:: secp256k1:: PublicKey ;
7
+ use bitcoin:: { WPubkeyHash , WScriptHash , WitnessProgram } ;
8
8
9
9
use crate :: ln:: channelmanager;
10
- use crate :: types:: features:: InitFeatures ;
11
10
use crate :: ln:: msgs:: DecodeError ;
11
+ use crate :: types:: features:: InitFeatures ;
12
12
use crate :: util:: ser:: { Readable , Writeable , Writer } ;
13
13
14
14
use crate :: io;
@@ -28,7 +28,7 @@ pub struct InvalidShutdownScript {
28
28
/// The script that did not meet the requirements from [BOLT #2].
29
29
///
30
30
/// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
31
- pub script : ScriptBuf
31
+ pub script : ScriptBuf ,
32
32
}
33
33
34
34
#[ derive( Clone , PartialEq , Eq ) ]
@@ -82,7 +82,9 @@ impl ShutdownScript {
82
82
/// # Errors
83
83
///
84
84
/// 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 > {
86
88
Self :: try_from ( ScriptBuf :: new_witness_program ( witness_program) )
87
89
}
88
90
@@ -128,7 +130,10 @@ impl TryFrom<ScriptBuf> for ShutdownScript {
128
130
type Error = InvalidShutdownScript ;
129
131
130
132
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
+ ) )
132
137
}
133
138
}
134
139
@@ -149,14 +154,15 @@ impl TryFrom<(ScriptBuf, &InitFeatures)> for ShutdownScript {
149
154
impl Into < ScriptBuf > for ShutdownScript {
150
155
fn into ( self ) -> ScriptBuf {
151
156
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
+ } ,
154
160
ShutdownScriptImpl :: Bolt2 ( script_pubkey) => script_pubkey,
155
161
}
156
162
}
157
163
}
158
164
159
- impl core:: fmt:: Display for ShutdownScript {
165
+ impl core:: fmt:: Display for ShutdownScript {
160
166
fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
161
167
match & self . 0 {
162
168
ShutdownScriptImpl :: Legacy ( _) => self . clone ( ) . into_inner ( ) . fmt ( f) ,
@@ -169,18 +175,22 @@ impl core::fmt::Display for ShutdownScript{
169
175
mod shutdown_script_tests {
170
176
use super :: ShutdownScript ;
171
177
172
- use bitcoin:: { WitnessProgram , WitnessVersion } ;
173
178
use bitcoin:: opcodes;
174
179
use bitcoin:: script:: { Builder , ScriptBuf } ;
175
180
use bitcoin:: secp256k1:: Secp256k1 ;
176
181
use bitcoin:: secp256k1:: { PublicKey , SecretKey } ;
182
+ use bitcoin:: { WitnessProgram , WitnessVersion } ;
177
183
178
- use crate :: types:: features:: InitFeatures ;
179
184
use crate :: prelude:: * ;
185
+ use crate :: types:: features:: InitFeatures ;
180
186
181
187
fn pubkey ( ) -> bitcoin:: key:: PublicKey {
182
188
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 ( ) ;
184
194
bitcoin:: key:: PublicKey :: new ( PublicKey :: from_secret_key ( & secp_ctx, & secret_key) )
185
195
}
186
196
0 commit comments