24
24
//! servicing [`ChannelMonitor`] updates from the client.
25
25
26
26
use bitcoin:: blockdata:: block:: { Block , BlockHeader } ;
27
+ use bitcoin:: hash_types:: Txid ;
28
+ use bitcoin:: blockdata:: transaction:: TxOut ;
27
29
28
30
use chain;
29
31
use chain:: { Filter , WatchedOutput } ;
@@ -82,10 +84,43 @@ where C::Target: chain::Filter,
82
84
/// descendants of such transactions. It is not necessary to re-fetch the block to obtain
83
85
/// updated `txdata`.
84
86
pub fn block_connected ( & self , header : & BlockHeader , txdata : & TransactionData , height : u32 ) {
87
+ self . process_transactions ( header, txdata, |monitor, txdata| {
88
+ monitor. block_connected (
89
+ header, txdata, height, & * self . broadcaster , & * self . fee_estimator , & * self . logger )
90
+ } ) ;
91
+ }
92
+
93
+ /// TODO: Write docs.
94
+ pub fn transactions_confirmed ( & self , header : & BlockHeader , txdata : & TransactionData , height : u32 ) {
95
+ self . process_transactions ( header, txdata, |monitor, txdata| {
96
+ monitor. transactions_confirmed (
97
+ header, txdata, height, & * self . broadcaster , & * self . fee_estimator , & * self . logger )
98
+ } ) ;
99
+ }
100
+
101
+ /// TODO: Write docs.
102
+ pub fn update_best_block ( & self , header : & BlockHeader , height : u32 ) {
103
+ self . process_transactions ( header, & [ ] , |monitor, txdata| {
104
+ // Recursive calls can supply txdata when chain::Filter::register_output returns a
105
+ // transaction.
106
+ if txdata. is_empty ( ) {
107
+ monitor. update_best_block (
108
+ header, height, & * self . broadcaster , & * self . fee_estimator , & * self . logger )
109
+ } else {
110
+ monitor. transactions_confirmed (
111
+ header, txdata, height, & * self . broadcaster , & * self . fee_estimator , & * self . logger )
112
+ }
113
+ } ) ;
114
+ }
115
+
116
+ fn process_transactions < FN > ( & self , header : & BlockHeader , txdata : & TransactionData , process : FN )
117
+ where
118
+ FN : Fn ( & ChannelMonitor < ChannelSigner > , & TransactionData ) -> Vec < ( Txid , Vec < ( u32 , TxOut ) > ) >
119
+ {
85
120
let mut dependent_txdata = Vec :: new ( ) ;
86
121
let monitors = self . monitors . read ( ) . unwrap ( ) ;
87
122
for monitor in monitors. values ( ) {
88
- let mut txn_outputs = monitor . block_connected ( header , txdata, height , & * self . broadcaster , & * self . fee_estimator , & * self . logger ) ;
123
+ let mut txn_outputs = process ( monitor , txdata) ;
89
124
90
125
// Register any new outputs with the chain source for filtering, storing any dependent
91
126
// transactions from within the block that previously had not been included in txdata.
@@ -114,7 +149,7 @@ where C::Target: chain::Filter,
114
149
dependent_txdata. sort_unstable_by_key ( |( index, _tx) | * index) ;
115
150
dependent_txdata. dedup_by_key ( |( index, _tx) | * index) ;
116
151
let txdata: Vec < _ > = dependent_txdata. iter ( ) . map ( |( index, tx) | ( * index, tx) ) . collect ( ) ;
117
- self . block_connected ( header, & txdata, height ) ;
152
+ self . process_transactions ( header, & txdata, process ) ;
118
153
}
119
154
}
120
155
@@ -128,6 +163,14 @@ where C::Target: chain::Filter,
128
163
}
129
164
}
130
165
166
+ /// TODO: Write docs.
167
+ pub fn transaction_unconfirmed ( & self , txid : & Txid ) {
168
+ let monitors = self . monitors . read ( ) . unwrap ( ) ;
169
+ for monitor in monitors. values ( ) {
170
+ monitor. transaction_unconfirmed ( txid, & * self . broadcaster , & * self . fee_estimator , & * self . logger ) ;
171
+ }
172
+ }
173
+
131
174
/// Creates a new `ChainMonitor` used to watch on-chain activity pertaining to channels.
132
175
///
133
176
/// When an optional chain source implementing [`chain::Filter`] is provided, the chain monitor
0 commit comments