98
98
}
99
99
100
100
match maybe_await ! ( self . get_confirmed_transactions( ) ) {
101
- Ok ( ( confirmed_txs, unconfirmed_registered_txs , unspent_registered_outputs ) ) => {
101
+ Ok ( ( confirmed_txs, spent_outputs ) ) => {
102
102
// Double-check tip hash. If something changed, restart last-minute.
103
103
let check_tip_hash = maybe_await ! ( self . client. get_tip_hash( ) ) ?;
104
104
if check_tip_hash != tip_hash {
@@ -109,8 +109,7 @@ where
109
109
self . sync_confirmed_transactions (
110
110
& confirmables,
111
111
confirmed_txs,
112
- unconfirmed_registered_txs,
113
- unspent_registered_outputs,
112
+ spent_outputs,
114
113
) ;
115
114
}
116
115
Err ( TxSyncError :: Inconsistency ) => {
@@ -206,9 +205,9 @@ where
206
205
207
206
fn sync_confirmed_transactions (
208
207
& self , confirmables : & Vec < & ( dyn Confirm + Sync + Send ) > , confirmed_txs : Vec < ConfirmedTx > ,
209
- unconfirmed_registered_txs : HashSet < Txid > ,
210
- unspent_registered_outputs : HashSet < WatchedOutput > ,
208
+ spent_outputs : HashSet < WatchedOutput > ,
211
209
) {
210
+ let mut locked_watched_transactions = self . watched_transactions . lock ( ) . unwrap ( ) ;
212
211
for ctx in confirmed_txs {
213
212
for c in confirmables {
214
213
c. transactions_confirmed (
@@ -217,16 +216,18 @@ where
217
216
ctx. block_height ,
218
217
) ;
219
218
}
219
+
220
+ locked_watched_transactions. remove ( & ctx. tx . txid ( ) ) ;
220
221
}
221
222
222
- * self . watched_transactions . lock ( ) . unwrap ( ) = unconfirmed_registered_txs ;
223
- * self . watched_outputs . lock ( ) . unwrap ( ) = unspent_registered_outputs ;
223
+ let mut locked_watched_outputs = self . watched_outputs . lock ( ) . unwrap ( ) ;
224
+ * locked_watched_outputs = & * locked_watched_outputs - & spent_outputs ;
224
225
}
225
226
226
227
#[ maybe_async]
227
228
fn get_confirmed_transactions (
228
229
& self ,
229
- ) -> Result < ( Vec < ConfirmedTx > , HashSet < Txid > , HashSet < WatchedOutput > ) , TxSyncError > {
230
+ ) -> Result < ( Vec < ConfirmedTx > , HashSet < WatchedOutput > ) , TxSyncError > {
230
231
231
232
// First, check the confirmation status of registered transactions as well as the
232
233
// status of dependent transactions of registered outputs.
@@ -237,22 +238,17 @@ where
237
238
// previous iterations.
238
239
let registered_txs = self . watched_transactions . lock ( ) . unwrap ( ) . clone ( ) ;
239
240
240
- // Remember all registered but unconfirmed transactions for future processing.
241
- let mut unconfirmed_registered_txs = HashSet :: new ( ) ;
242
-
243
241
for txid in registered_txs {
244
242
if let Some ( confirmed_tx) = maybe_await ! ( self . get_confirmed_tx( & txid, None , None ) ) ? {
245
243
confirmed_txs. push ( confirmed_tx) ;
246
- } else {
247
- unconfirmed_registered_txs. insert ( txid) ;
248
244
}
249
245
}
250
246
251
247
// Check all registered outputs for dependent spending transactions.
252
248
let registered_outputs = self . watched_outputs . lock ( ) . unwrap ( ) . clone ( ) ;
253
249
254
- // Remember all registered outputs that haven't been spent for future processing .
255
- let mut unspent_registered_outputs = HashSet :: new ( ) ;
250
+ // Remember all registered outputs that have been spent.
251
+ let mut spent_outputs = HashSet :: new ( ) ;
256
252
257
253
for output in registered_outputs {
258
254
if let Some ( output_status) = maybe_await ! ( self . client
@@ -268,12 +264,12 @@ where
268
264
) ) ?
269
265
{
270
266
confirmed_txs. push ( confirmed_tx) ;
267
+ spent_outputs. insert ( output) ;
271
268
continue ;
272
269
}
273
270
}
274
271
}
275
272
}
276
- unspent_registered_outputs. insert ( output) ;
277
273
}
278
274
279
275
// Sort all confirmed transactions first by block height, then by in-block
@@ -282,7 +278,7 @@ where
282
278
tx1. block_height . cmp ( & tx2. block_height ) . then_with ( || tx1. pos . cmp ( & tx2. pos ) )
283
279
} ) ;
284
280
285
- Ok ( ( confirmed_txs, unconfirmed_registered_txs , unspent_registered_outputs ) )
281
+ Ok ( ( confirmed_txs, spent_outputs ) )
286
282
}
287
283
288
284
#[ maybe_async]
@@ -336,7 +332,6 @@ where
336
332
. flat_map ( |c| c. get_relevant_txids ( ) )
337
333
. collect :: < HashSet < ( Txid , Option < BlockHash > ) > > ( ) ;
338
334
339
- let mut locked_watched_transactions = self . watched_transactions . lock ( ) . unwrap ( ) ;
340
335
for ( txid, block_hash_opt) in relevant_txids {
341
336
if let Some ( block_hash) = block_hash_opt {
342
337
let block_status = maybe_await ! ( self . client. get_block_status( & block_hash) ) ?;
@@ -350,7 +345,7 @@ where
350
345
c. transaction_unconfirmed ( & txid) ;
351
346
}
352
347
353
- locked_watched_transactions . insert ( txid) ;
348
+ self . watched_transactions . lock ( ) . unwrap ( ) . insert ( txid) ;
354
349
}
355
350
356
351
Ok ( ( ) )
0 commit comments