45
45
last_sync_hash : std:: sync:: Mutex < Option < BlockHash > > ,
46
46
#[ cfg( feature = "async-interface" ) ]
47
47
last_sync_hash : futures:: lock:: Mutex < Option < BlockHash > > ,
48
- #[ cfg( not( feature = "async-interface" ) ) ]
49
- client : BlockingClient ,
50
- #[ cfg( feature = "async-interface" ) ]
51
- client : AsyncClient ,
48
+ client : EsploraClientType ,
52
49
logger : L ,
53
50
}
54
51
@@ -150,6 +147,17 @@ where
150
147
151
148
/// Returns a new [`EsploraSyncClient`] object.
152
149
pub fn new ( server_url : String , logger : L ) -> Self {
150
+ let builder = Builder :: new ( & server_url) ;
151
+ #[ cfg( not( feature = "async-interface" ) ) ]
152
+ let client = builder. build_blocking ( ) . unwrap ( ) ;
153
+ #[ cfg( feature = "async-interface" ) ]
154
+ let client = builder. build_async ( ) . unwrap ( ) ;
155
+
156
+ EsploraSyncClient :: from_client ( client, logger)
157
+ }
158
+
159
+ /// Returns a new [`EsploraSyncClient`] object using the given esplora client.
160
+ pub fn from_client ( client : EsploraClientType , logger : L ) -> Self {
153
161
let watched_transactions = Mutex :: new ( HashSet :: new ( ) ) ;
154
162
let queued_transactions = Mutex :: new ( HashSet :: new ( ) ) ;
155
163
let watched_outputs = Mutex :: new ( HashSet :: new ( ) ) ;
@@ -159,11 +167,6 @@ where
159
167
let last_sync_hash = Mutex :: new ( None ) ;
160
168
#[ cfg( feature = "async-interface" ) ]
161
169
let last_sync_hash = futures:: lock:: Mutex :: new ( None ) ;
162
- let builder = Builder :: new ( & server_url) ;
163
- #[ cfg( not( feature = "async-interface" ) ) ]
164
- let client = builder. build_blocking ( ) . unwrap ( ) ;
165
- #[ cfg( feature = "async-interface" ) ]
166
- let client = builder. build_async ( ) . unwrap ( ) ;
167
170
Self {
168
171
queued_transactions,
169
172
watched_transactions,
@@ -370,8 +373,20 @@ where
370
373
371
374
Ok ( ( ) )
372
375
}
376
+
377
+ /// Returns a reference to the underlying esplora client.
378
+ pub fn client ( & self ) -> & EsploraClientType {
379
+ & self . client
380
+ }
373
381
}
374
382
383
+ /// The underlying client type.
384
+ #[ cfg( feature = "async-interface" ) ]
385
+ pub type EsploraClientType = AsyncClient ;
386
+ #[ cfg( not( feature = "async-interface" ) ) ]
387
+ pub type EsploraClientType = BlockingClient ;
388
+
389
+
375
390
struct ConfirmedTx {
376
391
tx : Transaction ,
377
392
block_header : BlockHeader ,
0 commit comments