@@ -356,50 +356,50 @@ pub fn complete_interactive_funding_negotiation_for_both<'a, 'b, 'c, 'd>(
356356 ( Vec :: new ( ) , Vec :: new ( ) )
357357 } ;
358358
359- let mut acceptor_sent_tx_complete = false ;
360359 let mut initiator_sent_tx_complete;
360+ let mut acceptor_sent_tx_complete = false ;
361361 loop {
362362 // Initiator's turn: send TxAddInput, TxAddOutput, or TxComplete
363- if !expected_initiator_inputs. is_empty ( ) {
364- let tx_add_input =
365- get_event_msg ! ( initiator, MessageSendEvent :: SendTxAddInput , node_id_acceptor) ;
366- let input_prevout = BitcoinOutPoint {
367- txid : tx_add_input
368- . prevtx
369- . as_ref ( )
370- . map ( |prevtx| prevtx. compute_txid ( ) )
371- . or ( tx_add_input. shared_input_txid )
372- . unwrap ( ) ,
373- vout : tx_add_input. prevtx_out ,
374- } ;
375- expected_initiator_inputs. remove (
376- expected_initiator_inputs. iter ( ) . position ( |input| * input == input_prevout) . unwrap ( ) ,
377- ) ;
378- acceptor. node . handle_tx_add_input ( node_id_initiator, & tx_add_input) ;
379- initiator_sent_tx_complete = false ;
380- } else if !expected_initiator_scripts. is_empty ( ) {
381- let tx_add_output =
382- get_event_msg ! ( initiator, MessageSendEvent :: SendTxAddOutput , node_id_acceptor) ;
383- expected_initiator_scripts. remove (
384- expected_initiator_scripts
385- . iter ( )
386- . position ( |script| * script == tx_add_output. script )
387- . unwrap ( ) ,
388- ) ;
389- acceptor. node . handle_tx_add_output ( node_id_initiator, & tx_add_output) ;
390- initiator_sent_tx_complete = false ;
391- } else {
392- let msg_events = initiator. node . get_and_clear_pending_msg_events ( ) ;
393- assert_eq ! ( msg_events. len( ) , 1 , "{msg_events:?}" ) ;
394- if let MessageSendEvent :: SendTxComplete { ref msg, .. } = & msg_events[ 0 ] {
363+ let msg_events = initiator. node . get_and_clear_pending_msg_events ( ) ;
364+ assert_eq ! ( msg_events. len( ) , 1 , "{msg_events:?}" ) ;
365+ match & msg_events[ 0 ] {
366+ MessageSendEvent :: SendTxAddInput { msg, .. } => {
367+ let input_prevout = BitcoinOutPoint {
368+ txid : msg
369+ . prevtx
370+ . as_ref ( )
371+ . map ( |prevtx| prevtx. compute_txid ( ) )
372+ . or ( msg. shared_input_txid )
373+ . unwrap ( ) ,
374+ vout : msg. prevtx_out ,
375+ } ;
376+ expected_initiator_inputs. remove (
377+ expected_initiator_inputs
378+ . iter ( )
379+ . position ( |input| * input == input_prevout)
380+ . unwrap ( ) ,
381+ ) ;
382+ acceptor. node . handle_tx_add_input ( node_id_initiator, msg) ;
383+ initiator_sent_tx_complete = false ;
384+ } ,
385+ MessageSendEvent :: SendTxAddOutput { msg, .. } => {
386+ expected_initiator_scripts. remove (
387+ expected_initiator_scripts
388+ . iter ( )
389+ . position ( |script| * script == msg. script )
390+ . unwrap ( ) ,
391+ ) ;
392+ acceptor. node . handle_tx_add_output ( node_id_initiator, msg) ;
393+ initiator_sent_tx_complete = false ;
394+ } ,
395+ MessageSendEvent :: SendTxComplete { msg, .. } => {
395396 acceptor. node . handle_tx_complete ( node_id_initiator, msg) ;
396- } else {
397- panic ! ( ) ;
398- }
399- initiator_sent_tx_complete = true ;
400- if acceptor_sent_tx_complete {
401- break ;
402- }
397+ initiator_sent_tx_complete = true ;
398+ if acceptor_sent_tx_complete {
399+ break ;
400+ }
401+ } ,
402+ _ => panic ! ( "Unexpected message event: {:?}" , msg_events[ 0 ] ) ,
403403 }
404404
405405 // Acceptor's turn: send TxAddInput, TxAddOutput, or TxComplete
@@ -446,6 +446,8 @@ pub fn complete_interactive_funding_negotiation_for_both<'a, 'b, 'c, 'd>(
446446 }
447447 }
448448
449+ assert ! ( expected_initiator_inputs. is_empty( ) , "Not all initiator inputs were sent" ) ;
450+ assert ! ( expected_initiator_scripts. is_empty( ) , "Not all initiator outputs were sent" ) ;
449451 assert ! ( expected_acceptor_inputs. is_empty( ) , "Not all acceptor inputs were sent" ) ;
450452 assert ! ( expected_acceptor_scripts. is_empty( ) , "Not all acceptor outputs were sent" ) ;
451453}
0 commit comments