@@ -451,11 +451,7 @@ where
451
451
452
452
/// Regenerates and broadcasts the spending transaction for any outputs that are pending
453
453
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 | {
459
455
if o. status . is_confirmed ( ) {
460
456
// Don't rebroadcast confirmed txs.
461
457
return false ;
@@ -474,8 +470,17 @@ where
474
470
true
475
471
} ;
476
472
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 ( ) ;
479
484
480
485
if respend_descriptors. is_empty ( ) {
481
486
// Nothing to do.
@@ -499,7 +504,8 @@ where
499
504
500
505
// As we didn't modify the state so far, the same filter_fn yields the same elements as
501
506
// 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) ) ;
503
509
for output_info in respend_outputs {
504
510
if let Some ( filter) = self . chain_data_source . as_ref ( ) {
505
511
let watched_output = output_info. to_watched_output ( cur_hash) ;
0 commit comments