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