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