1
- use lightning:: chain:: { Confirm , WatchedOutput } ;
2
- use lightning:: chain:: channelmonitor:: ANTI_REORG_DELAY ;
3
- use bitcoin:: { Txid , BlockHash , Transaction , OutPoint } ;
4
1
use bitcoin:: block:: Header ;
2
+ use bitcoin:: { BlockHash , OutPoint , Transaction , Txid } ;
3
+ use lightning:: chain:: channelmonitor:: ANTI_REORG_DELAY ;
4
+ use lightning:: chain:: { Confirm , WatchedOutput } ;
5
5
6
- use std:: collections:: { HashSet , HashMap } ;
7
-
6
+ use std:: collections:: { HashMap , HashSet } ;
7
+ use std :: ops :: Deref ;
8
8
9
9
// Represents the current state.
10
10
pub ( crate ) struct SyncState {
@@ -33,10 +33,11 @@ impl SyncState {
33
33
pending_sync : false ,
34
34
}
35
35
}
36
- pub fn sync_unconfirmed_transactions (
37
- & mut self , confirmables : & Vec < & ( dyn Confirm + Sync + Send ) > ,
38
- unconfirmed_txs : Vec < Txid > ,
39
- ) {
36
+ pub fn sync_unconfirmed_transactions < C : Deref > (
37
+ & mut self , confirmables : & Vec < C > , unconfirmed_txs : Vec < Txid > ,
38
+ ) where
39
+ C :: Target : Confirm ,
40
+ {
40
41
for txid in unconfirmed_txs {
41
42
for c in confirmables {
42
43
c. transaction_unconfirmed ( & txid) ;
@@ -46,21 +47,24 @@ impl SyncState {
46
47
47
48
// If a previously-confirmed output spend is unconfirmed, re-add the watched output to
48
49
// the tracking map.
49
- self . outputs_spends_pending_threshold_conf . retain ( |( conf_txid, _, prev_outpoint, output) | {
50
- if txid == * conf_txid {
51
- self . watched_outputs . insert ( * prev_outpoint, output. clone ( ) ) ;
52
- false
53
- } else {
54
- true
55
- }
56
- } )
50
+ self . outputs_spends_pending_threshold_conf . retain (
51
+ |( conf_txid, _, prev_outpoint, output) | {
52
+ if txid == * conf_txid {
53
+ self . watched_outputs . insert ( * prev_outpoint, output. clone ( ) ) ;
54
+ false
55
+ } else {
56
+ true
57
+ }
58
+ } ,
59
+ )
57
60
}
58
61
}
59
62
60
- pub fn sync_confirmed_transactions (
61
- & mut self , confirmables : & Vec < & ( dyn Confirm + Sync + Send ) > ,
62
- confirmed_txs : Vec < ConfirmedTx >
63
- ) {
63
+ pub fn sync_confirmed_transactions < C : Deref > (
64
+ & mut self , confirmables : & Vec < C > , confirmed_txs : Vec < ConfirmedTx > ,
65
+ ) where
66
+ C :: Target : Confirm ,
67
+ {
64
68
for ctx in confirmed_txs {
65
69
for c in confirmables {
66
70
c. transactions_confirmed (
@@ -74,20 +78,19 @@ impl SyncState {
74
78
75
79
for input in & ctx. tx . input {
76
80
if let Some ( output) = self . watched_outputs . remove ( & input. previous_output ) {
77
- self . outputs_spends_pending_threshold_conf . push ( ( ctx. tx . txid ( ) , ctx. block_height , input. previous_output , output) ) ;
81
+ let spent = ( ctx. tx . txid ( ) , ctx. block_height , input. previous_output , output) ;
82
+ self . outputs_spends_pending_threshold_conf . push ( spent) ;
78
83
}
79
84
}
80
85
}
81
86
}
82
87
83
88
pub fn prune_output_spends ( & mut self , cur_height : u32 ) {
84
- self . outputs_spends_pending_threshold_conf . retain ( |( _, conf_height, _, _) | {
85
- cur_height < conf_height + ANTI_REORG_DELAY - 1
86
- } ) ;
89
+ self . outputs_spends_pending_threshold_conf
90
+ . retain ( |( _, conf_height, _, _) | cur_height < conf_height + ANTI_REORG_DELAY - 1 ) ;
87
91
}
88
92
}
89
93
90
-
91
94
// A queue that is to be filled by `Filter` and drained during the next syncing round.
92
95
pub ( crate ) struct FilterQueue {
93
96
// Transactions that were registered via the `Filter` interface and have to be processed.
@@ -98,10 +101,7 @@ pub(crate) struct FilterQueue {
98
101
99
102
impl FilterQueue {
100
103
pub fn new ( ) -> Self {
101
- Self {
102
- transactions : HashSet :: new ( ) ,
103
- outputs : HashMap :: new ( ) ,
104
- }
104
+ Self { transactions : HashSet :: new ( ) , outputs : HashMap :: new ( ) }
105
105
}
106
106
107
107
// Processes the transaction and output queues and adds them to the given [`SyncState`].
0 commit comments