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