@@ -986,7 +986,10 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
986986 secp_ctx. seeded_randomize ( & entropy_source. get_secure_random_bytes ( ) ) ;
987987
988988 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+ }
990993 } else { None } ;
991994
992995 if let Some ( shutdown_scriptpubkey) = & shutdown_scriptpubkey {
@@ -995,6 +998,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
995998 }
996999 }
9971000
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+
9981006 let temporary_channel_id = entropy_source. get_secure_random_bytes ( ) ;
9991007
10001008 Ok ( Channel {
@@ -1021,7 +1029,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
10211029
10221030 holder_signer,
10231031 shutdown_scriptpubkey,
1024- destination_script : signer_provider . get_destination_script ( ) ,
1032+ destination_script,
10251033
10261034 cur_holder_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
10271035 cur_counterparty_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
@@ -1333,7 +1341,10 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
13331341 } else { None } ;
13341342
13351343 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+ }
13371348 } else { None } ;
13381349
13391350 if let Some ( shutdown_scriptpubkey) = & shutdown_scriptpubkey {
@@ -1342,6 +1353,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
13421353 }
13431354 }
13441355
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+
13451361 let mut secp_ctx = Secp256k1 :: new ( ) ;
13461362 secp_ctx. seeded_randomize ( & entropy_source. get_secure_random_bytes ( ) ) ;
13471363
@@ -1368,7 +1384,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
13681384
13691385 holder_signer,
13701386 shutdown_scriptpubkey,
1371- destination_script : signer_provider . get_destination_script ( ) ,
1387+ destination_script,
13721388
13731389 cur_holder_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
13741390 cur_counterparty_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
@@ -4355,7 +4371,10 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
43554371 Some ( _) => false ,
43564372 None => {
43574373 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+ } ;
43594378 if !shutdown_scriptpubkey. is_compatible ( their_features) {
43604379 return Err ( ChannelError :: Close ( format ! ( "Provided a scriptpubkey format not accepted by peer: {}" , shutdown_scriptpubkey) ) ) ;
43614380 }
@@ -6062,7 +6081,10 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
60626081 let update_shutdown_script = match self . shutdown_scriptpubkey {
60636082 Some ( _) => false ,
60646083 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+ } ;
60666088 if !shutdown_scriptpubkey. is_compatible ( their_features) {
60676089 return Err ( APIError :: IncompatibleShutdownScript { script : shutdown_scriptpubkey. clone ( ) } ) ;
60686090 }
@@ -7087,17 +7109,17 @@ mod tests {
70877109
70887110 fn read_chan_signer ( & self , _data : & [ u8 ] ) -> Result < Self :: Signer , DecodeError > { panic ! ( ) ; }
70897111
7090- fn get_destination_script ( & self ) -> Script {
7112+ fn get_destination_script ( & self ) -> Result < Script , ( ) > {
70917113 let secp_ctx = Secp256k1 :: signing_only ( ) ;
70927114 let channel_monitor_claim_key = SecretKey :: from_slice ( & hex:: decode ( "0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ) . unwrap ( ) [ ..] ) . unwrap ( ) ;
70937115 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 ( ) )
70957117 }
70967118
7097- fn get_shutdown_scriptpubkey ( & self ) -> ShutdownScript {
7119+ fn get_shutdown_scriptpubkey ( & self ) -> Result < ShutdownScript , ( ) > {
70987120 let secp_ctx = Secp256k1 :: signing_only ( ) ;
70997121 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) ) )
71017123 }
71027124 }
71037125
0 commit comments