@@ -302,19 +302,8 @@ pub(crate) struct InteractiveTxSigningSession {
302302impl InteractiveTxSigningSession {
303303 pub fn received_commitment_signed ( & mut self ) -> Option < TxSignatures > {
304304 self . received_commitment_signed = true ;
305- if self . holder_sends_tx_signatures_first {
306- self . holder_tx_signatures . clone ( )
307- } else {
308- None
309- }
310- }
311305
312- pub fn get_tx_signatures ( & self ) -> Option < TxSignatures > {
313- if self . received_commitment_signed {
314- self . holder_tx_signatures . clone ( )
315- } else {
316- None
317- }
306+ self . get_tx_signatures ( )
318307 }
319308
320309 /// Handles a `tx_signatures` message received from the counterparty.
@@ -337,22 +326,7 @@ impl InteractiveTxSigningSession {
337326 self . unsigned_tx . add_remote_witnesses ( tx_signatures. witnesses . clone ( ) ) ;
338327 self . counterparty_sent_tx_signatures = true ;
339328
340- let holder_tx_signatures = if !self . holder_sends_tx_signatures_first {
341- self . holder_tx_signatures . clone ( )
342- } else {
343- None
344- } ;
345-
346- // Check if the holder has provided its signatures and if so,
347- // return the finalized funding transaction.
348- let funding_tx_opt = if self . holder_tx_signatures . is_some ( ) {
349- Some ( self . finalize_funding_tx ( ) )
350- } else {
351- // This means we're still waiting for the holder to provide their signatures.
352- None
353- } ;
354-
355- Ok ( ( holder_tx_signatures, funding_tx_opt) )
329+ Ok ( ( self . get_tx_signatures ( ) , self . get_finalized_funding_tx ( ) ) )
356330 }
357331
358332 /// Provides the holder witnesses for the unsigned transaction.
@@ -362,7 +336,7 @@ impl InteractiveTxSigningSession {
362336 pub fn provide_holder_witnesses (
363337 & mut self , channel_id : ChannelId , witnesses : Vec < Witness > ,
364338 shared_input_signature : Option < Signature > ,
365- ) -> Result < ( ) , ( ) > {
339+ ) -> Result < ( Option < TxSignatures > , Option < Transaction > ) , ( ) > {
366340 if self . local_inputs_count ( ) != witnesses. len ( ) {
367341 return Err ( ( ) ) ;
368342 }
@@ -375,7 +349,35 @@ impl InteractiveTxSigningSession {
375349 shared_input_signature,
376350 } ) ;
377351
378- Ok ( ( ) )
352+ Ok ( ( self . get_tx_signatures ( ) , self . get_finalized_funding_tx ( ) ) )
353+ }
354+
355+ /// Decide if we need to send `TxSignatures` at this stage or not
356+ fn get_tx_signatures ( & mut self ) -> Option < TxSignatures > {
357+ if self . holder_tx_signatures . is_none ( ) {
358+ return None ; // no local signature yet
359+ }
360+ if !self . received_commitment_signed {
361+ return None ; // no counterparty commitment received yet
362+ }
363+ if ( !self . holder_sends_tx_signatures_first && self . counterparty_sent_tx_signatures )
364+ || ( self . holder_sends_tx_signatures_first && !self . counterparty_sent_tx_signatures )
365+ {
366+ self . holder_tx_signatures . clone ( )
367+ } else {
368+ None
369+ }
370+ }
371+
372+ /// Decide if we have the funding transaction signed from both parties
373+ fn get_finalized_funding_tx ( & mut self ) -> Option < Transaction > {
374+ if self . holder_tx_signatures . is_none ( ) {
375+ return None ; // no local signature yet
376+ }
377+ if !self . counterparty_sent_tx_signatures {
378+ return None ; // no counterparty signature received yet
379+ }
380+ Some ( self . finalize_funding_tx ( ) )
379381 }
380382
381383 pub fn remote_inputs_count ( & self ) -> usize {
0 commit comments