@@ -986,7 +986,10 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
986
986
secp_ctx. seeded_randomize ( & entropy_source. get_secure_random_bytes ( ) ) ;
987
987
988
988
let shutdown_scriptpubkey = if config. channel_handshake_config . commit_upfront_shutdown_pubkey {
989
- Some ( signer_provider. get_shutdown_scriptpubkey ( ) )
989
+ match signer_provider. get_shutdown_scriptpubkey ( ) {
990
+ Ok ( scriptpubkey) => Some ( scriptpubkey) ,
991
+ Err ( _) => return Err ( APIError :: ChannelUnavailable { err : "Failed to get shutdown scriptpubkey" . to_owned ( ) } ) ,
992
+ }
990
993
} else { None } ;
991
994
992
995
if let Some ( shutdown_scriptpubkey) = & shutdown_scriptpubkey {
@@ -995,6 +998,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
995
998
}
996
999
}
997
1000
1001
+ let destination_script = match signer_provider. get_destination_script ( ) {
1002
+ Ok ( script) => script,
1003
+ Err ( _) => return Err ( APIError :: ChannelUnavailable { err : "Failed to get destination script" . to_owned ( ) } ) ,
1004
+ } ;
1005
+
998
1006
let temporary_channel_id = entropy_source. get_secure_random_bytes ( ) ;
999
1007
1000
1008
Ok ( Channel {
@@ -1021,7 +1029,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1021
1029
1022
1030
holder_signer,
1023
1031
shutdown_scriptpubkey,
1024
- destination_script : signer_provider . get_destination_script ( ) ,
1032
+ destination_script,
1025
1033
1026
1034
cur_holder_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
1027
1035
cur_counterparty_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
@@ -1333,7 +1341,10 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1333
1341
} else { None } ;
1334
1342
1335
1343
let shutdown_scriptpubkey = if config. channel_handshake_config . commit_upfront_shutdown_pubkey {
1336
- Some ( signer_provider. get_shutdown_scriptpubkey ( ) )
1344
+ match signer_provider. get_shutdown_scriptpubkey ( ) {
1345
+ Ok ( scriptpubkey) => Some ( scriptpubkey) ,
1346
+ Err ( _) => return Err ( ChannelError :: Close ( "Failed to get upfront shutdown scriptpubkey" . to_owned ( ) ) ) ,
1347
+ }
1337
1348
} else { None } ;
1338
1349
1339
1350
if let Some ( shutdown_scriptpubkey) = & shutdown_scriptpubkey {
@@ -1342,6 +1353,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1342
1353
}
1343
1354
}
1344
1355
1356
+ let destination_script = match signer_provider. get_destination_script ( ) {
1357
+ Ok ( script) => script,
1358
+ Err ( _) => return Err ( ChannelError :: Close ( "Failed to get destination script" . to_owned ( ) ) ) ,
1359
+ } ;
1360
+
1345
1361
let mut secp_ctx = Secp256k1 :: new ( ) ;
1346
1362
secp_ctx. seeded_randomize ( & entropy_source. get_secure_random_bytes ( ) ) ;
1347
1363
@@ -1368,7 +1384,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1368
1384
1369
1385
holder_signer,
1370
1386
shutdown_scriptpubkey,
1371
- destination_script : signer_provider . get_destination_script ( ) ,
1387
+ destination_script,
1372
1388
1373
1389
cur_holder_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
1374
1390
cur_counterparty_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
@@ -4355,7 +4371,10 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
4355
4371
Some ( _) => false ,
4356
4372
None => {
4357
4373
assert ! ( send_shutdown) ;
4358
- let shutdown_scriptpubkey = signer_provider. get_shutdown_scriptpubkey ( ) ;
4374
+ let shutdown_scriptpubkey = match signer_provider. get_shutdown_scriptpubkey ( ) {
4375
+ Ok ( scriptpubkey) => scriptpubkey,
4376
+ Err ( _) => return Err ( ChannelError :: Close ( "Failed to get shutdown scriptpubkey" . to_owned ( ) ) ) ,
4377
+ } ;
4359
4378
if !shutdown_scriptpubkey. is_compatible ( their_features) {
4360
4379
return Err ( ChannelError :: Close ( format ! ( "Provided a scriptpubkey format not accepted by peer: {}" , shutdown_scriptpubkey) ) ) ;
4361
4380
}
@@ -6062,7 +6081,10 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
6062
6081
let update_shutdown_script = match self . shutdown_scriptpubkey {
6063
6082
Some ( _) => false ,
6064
6083
None if !chan_closed => {
6065
- let shutdown_scriptpubkey = signer_provider. get_shutdown_scriptpubkey ( ) ;
6084
+ let shutdown_scriptpubkey = match signer_provider. get_shutdown_scriptpubkey ( ) {
6085
+ Ok ( scriptpubkey) => scriptpubkey,
6086
+ Err ( _) => return Err ( APIError :: ChannelUnavailable { err : "Failed to get shutdown scriptpubkey" . to_owned ( ) } ) ,
6087
+ } ;
6066
6088
if !shutdown_scriptpubkey. is_compatible ( their_features) {
6067
6089
return Err ( APIError :: IncompatibleShutdownScript { script : shutdown_scriptpubkey. clone ( ) } ) ;
6068
6090
}
@@ -7087,17 +7109,17 @@ mod tests {
7087
7109
7088
7110
fn read_chan_signer ( & self , _data : & [ u8 ] ) -> Result < Self :: Signer , DecodeError > { panic ! ( ) ; }
7089
7111
7090
- fn get_destination_script ( & self ) -> Script {
7112
+ fn get_destination_script ( & self ) -> Result < Script , ( ) > {
7091
7113
let secp_ctx = Secp256k1 :: signing_only ( ) ;
7092
7114
let channel_monitor_claim_key = SecretKey :: from_slice ( & hex:: decode ( "0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ) . unwrap ( ) [ ..] ) . unwrap ( ) ;
7093
7115
let channel_monitor_claim_key_hash = WPubkeyHash :: hash ( & PublicKey :: from_secret_key ( & secp_ctx, & channel_monitor_claim_key) . serialize ( ) ) ;
7094
- Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 ) . push_slice ( & channel_monitor_claim_key_hash[ ..] ) . into_script ( )
7116
+ Ok ( Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 ) . push_slice ( & channel_monitor_claim_key_hash[ ..] ) . into_script ( ) )
7095
7117
}
7096
7118
7097
- fn get_shutdown_scriptpubkey ( & self ) -> ShutdownScript {
7119
+ fn get_shutdown_scriptpubkey ( & self ) -> Result < ShutdownScript , ( ) > {
7098
7120
let secp_ctx = Secp256k1 :: signing_only ( ) ;
7099
7121
let channel_close_key = SecretKey :: from_slice ( & hex:: decode ( "0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ) . unwrap ( ) [ ..] ) . unwrap ( ) ;
7100
- ShutdownScript :: new_p2wpkh_from_pubkey ( PublicKey :: from_secret_key ( & secp_ctx, & channel_close_key) )
7122
+ Ok ( ShutdownScript :: new_p2wpkh_from_pubkey ( PublicKey :: from_secret_key ( & secp_ctx, & channel_close_key) ) )
7101
7123
}
7102
7124
}
7103
7125
0 commit comments