1
1
use crate :: error:: { TxSyncError , InternalError } ;
2
+ use crate :: types:: { SyncState , FilterQueue , ConfirmedTx } ;
2
3
3
4
use lightning:: util:: logger:: Logger ;
4
5
use lightning:: { log_error, log_given_level, log_info, log_internal, log_debug, log_trace} ;
5
6
use lightning:: chain:: WatchedOutput ;
6
7
use lightning:: chain:: { Confirm , Filter } ;
7
8
8
- use bitcoin:: { BlockHash , BlockHeader , Script , Transaction , Txid } ;
9
+ use bitcoin:: { BlockHash , Script , Txid } ;
9
10
10
11
use esplora_client:: Builder ;
11
12
#[ cfg( feature = "async-interface" ) ]
@@ -327,68 +328,6 @@ where
327
328
}
328
329
}
329
330
330
- // Represents the current state.
331
- struct SyncState {
332
- // Transactions that were previously processed, but must not be forgotten
333
- // yet since they still need to be monitored for confirmation on-chain.
334
- watched_transactions : HashSet < Txid > ,
335
- // Outputs that were previously processed, but must not be forgotten yet as
336
- // as we still need to monitor any spends on-chain.
337
- watched_outputs : HashSet < WatchedOutput > ,
338
- // The tip hash observed during our last sync.
339
- last_sync_hash : Option < BlockHash > ,
340
- // Indicates whether we need to resync, e.g., after encountering an error.
341
- pending_sync : bool ,
342
- }
343
-
344
- impl SyncState {
345
- fn new ( ) -> Self {
346
- Self {
347
- watched_transactions : HashSet :: new ( ) ,
348
- watched_outputs : HashSet :: new ( ) ,
349
- last_sync_hash : None ,
350
- pending_sync : false ,
351
- }
352
- }
353
- }
354
-
355
- // A queue that is to be filled by `Filter` and drained during the next syncing round.
356
- struct FilterQueue {
357
- // Transactions that were registered via the `Filter` interface and have to be processed.
358
- transactions : HashSet < Txid > ,
359
- // Outputs that were registered via the `Filter` interface and have to be processed.
360
- outputs : HashSet < WatchedOutput > ,
361
- }
362
-
363
- impl FilterQueue {
364
- fn new ( ) -> Self {
365
- Self {
366
- transactions : HashSet :: new ( ) ,
367
- outputs : HashSet :: new ( ) ,
368
- }
369
- }
370
-
371
- // Processes the transaction and output queues and adds them to the given [`SyncState`].
372
- //
373
- // Returns `true` if new items had been registered.
374
- fn process_queues ( & mut self , sync_state : & mut SyncState ) -> bool {
375
- let mut pending_registrations = false ;
376
-
377
- if !self . transactions . is_empty ( ) {
378
- pending_registrations = true ;
379
-
380
- sync_state. watched_transactions . extend ( self . transactions . drain ( ) ) ;
381
- }
382
-
383
- if !self . outputs . is_empty ( ) {
384
- pending_registrations = true ;
385
-
386
- sync_state. watched_outputs . extend ( self . outputs . drain ( ) ) ;
387
- }
388
- pending_registrations
389
- }
390
- }
391
-
392
331
#[ cfg( feature = "async-interface" ) ]
393
332
type MutexType < I > = futures:: lock:: Mutex < I > ;
394
333
#[ cfg( not( feature = "async-interface" ) ) ]
@@ -401,13 +340,6 @@ pub type EsploraClientType = AsyncClient;
401
340
pub type EsploraClientType = BlockingClient ;
402
341
403
342
404
- struct ConfirmedTx {
405
- tx : Transaction ,
406
- block_header : BlockHeader ,
407
- block_height : u32 ,
408
- pos : usize ,
409
- }
410
-
411
343
impl < L : Deref > Filter for EsploraSyncClient < L >
412
344
where
413
345
L :: Target : Logger ,
0 commit comments