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