@@ -452,11 +452,7 @@ where
452452
453453 /// Regenerates and broadcasts the spending transaction for any outputs that are pending
454454 pub fn regenerate_and_broadcast_spend_if_necessary ( & self ) -> Result < ( ) , ( ) > {
455- let sweeper_state = & mut self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
456-
457- let cur_height = sweeper_state. best_block . height ;
458- let cur_hash = sweeper_state. best_block . block_hash ;
459- let filter_fn = |o : & TrackedSpendableOutput | {
455+ let filter_fn = |o : & TrackedSpendableOutput , cur_height : u32 | {
460456 if o. status . is_confirmed ( ) {
461457 // Don't rebroadcast confirmed txs.
462458 return false ;
@@ -475,8 +471,17 @@ where
475471 true
476472 } ;
477473
478- let respend_descriptors: Vec < & SpendableOutputDescriptor > =
479- sweeper_state. outputs . iter ( ) . filter ( |o| filter_fn ( * o) ) . map ( |o| & o. descriptor ) . collect ( ) ;
474+ let sweeper_state = & mut self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
475+
476+ let cur_height = sweeper_state. best_block . height ;
477+ let cur_hash = sweeper_state. best_block . block_hash ;
478+
479+ let respend_descriptors: Vec < & SpendableOutputDescriptor > = sweeper_state
480+ . outputs
481+ . iter ( )
482+ . filter ( |o| filter_fn ( * o, cur_height) )
483+ . map ( |o| & o. descriptor )
484+ . collect ( ) ;
480485
481486 if respend_descriptors. is_empty ( ) {
482487 // Nothing to do.
@@ -500,7 +505,8 @@ where
500505
501506 // As we didn't modify the state so far, the same filter_fn yields the same elements as
502507 // above.
503- let respend_outputs = sweeper_state. outputs . iter_mut ( ) . filter ( |o| filter_fn ( & * * o) ) ;
508+ let respend_outputs =
509+ sweeper_state. outputs . iter_mut ( ) . filter ( |o| filter_fn ( & * * o, cur_height) ) ;
504510 for output_info in respend_outputs {
505511 if let Some ( filter) = self . chain_data_source . as_ref ( ) {
506512 let watched_output = output_info. to_watched_output ( cur_hash) ;
0 commit comments