@@ -5,6 +5,7 @@ use bdk_core::{
5
5
bitcoin:: { BlockHash , OutPoint , ScriptBuf , Txid } ,
6
6
BlockId , CheckPoint , ConfirmationBlockTime , Indexed , TxUpdate ,
7
7
} ;
8
+ use esplora_client:: Sleeper ;
8
9
use futures:: { stream:: FuturesOrdered , TryStreamExt } ;
9
10
10
11
use crate :: { insert_anchor_from_status, insert_prevouts} ;
@@ -50,7 +51,11 @@ pub trait EsploraAsyncExt {
50
51
51
52
#[ cfg_attr( target_arch = "wasm32" , async_trait( ?Send ) ) ]
52
53
#[ cfg_attr( not( target_arch = "wasm32" ) , async_trait) ]
53
- impl EsploraAsyncExt for esplora_client:: AsyncClient {
54
+ impl < S > EsploraAsyncExt for esplora_client:: AsyncClient < S >
55
+ where
56
+ S : Sleeper + Clone + Send + Sync ,
57
+ S :: Sleep : Send ,
58
+ {
54
59
async fn full_scan < K : Ord + Clone + Send , R : Into < FullScanRequest < K > > + Send > (
55
60
& self ,
56
61
request : R ,
@@ -165,8 +170,8 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
165
170
/// block-based chain-sources). Therefore it's better to be conservative when setting the tip (use
166
171
/// an earlier tip rather than a later tip) otherwise the caller may accidentally skip blocks when
167
172
/// alternating between chain-sources.
168
- async fn fetch_latest_blocks (
169
- client : & esplora_client:: AsyncClient ,
173
+ async fn fetch_latest_blocks < S : Sleeper > (
174
+ client : & esplora_client:: AsyncClient < S > ,
170
175
) -> Result < BTreeMap < u32 , BlockHash > , Error > {
171
176
Ok ( client
172
177
. get_blocks ( None )
@@ -179,8 +184,8 @@ async fn fetch_latest_blocks(
179
184
/// Used instead of [`esplora_client::BlockingClient::get_block_hash`].
180
185
///
181
186
/// This first checks the previously fetched `latest_blocks` before fetching from Esplora again.
182
- async fn fetch_block (
183
- client : & esplora_client:: AsyncClient ,
187
+ async fn fetch_block < S : Sleeper > (
188
+ client : & esplora_client:: AsyncClient < S > ,
184
189
latest_blocks : & BTreeMap < u32 , BlockHash > ,
185
190
height : u32 ,
186
191
) -> Result < Option < BlockHash > , Error > {
@@ -205,8 +210,8 @@ async fn fetch_block(
205
210
///
206
211
/// We want to have a corresponding checkpoint per anchor height. However, checkpoints fetched
207
212
/// should not surpass `latest_blocks`.
208
- async fn chain_update (
209
- client : & esplora_client:: AsyncClient ,
213
+ async fn chain_update < S : Sleeper > (
214
+ client : & esplora_client:: AsyncClient < S > ,
210
215
latest_blocks : & BTreeMap < u32 , BlockHash > ,
211
216
local_tip : & CheckPoint ,
212
217
anchors : & BTreeSet < ( ConfirmationBlockTime , Txid ) > ,
@@ -271,13 +276,17 @@ async fn chain_update(
271
276
/// script pubkey that contains a non-empty transaction history.
272
277
///
273
278
/// Refer to [crate-level docs](crate) for more.
274
- async fn fetch_txs_with_keychain_spks < I : Iterator < Item = Indexed < ScriptBuf > > + Send > (
275
- client : & esplora_client:: AsyncClient ,
279
+ async fn fetch_txs_with_keychain_spks < I , S > (
280
+ client : & esplora_client:: AsyncClient < S > ,
276
281
inserted_txs : & mut HashSet < Txid > ,
277
282
mut keychain_spks : I ,
278
283
stop_gap : usize ,
279
284
parallel_requests : usize ,
280
- ) -> Result < ( TxUpdate < ConfirmationBlockTime > , Option < u32 > ) , Error > {
285
+ ) -> Result < ( TxUpdate < ConfirmationBlockTime > , Option < u32 > ) , Error >
286
+ where
287
+ I : Iterator < Item = Indexed < ScriptBuf > > + Send ,
288
+ S : Sleeper + Clone + Send + Sync ,
289
+ {
281
290
type TxsOfSpkIndex = ( u32 , Vec < esplora_client:: Tx > ) ;
282
291
283
292
let mut update = TxUpdate :: < ConfirmationBlockTime > :: default ( ) ;
@@ -346,14 +355,16 @@ async fn fetch_txs_with_keychain_spks<I: Iterator<Item = Indexed<ScriptBuf>> + S
346
355
/// HTTP requests to make in parallel.
347
356
///
348
357
/// Refer to [crate-level docs](crate) for more.
349
- async fn fetch_txs_with_spks < I : IntoIterator < Item = ScriptBuf > + Send > (
350
- client : & esplora_client:: AsyncClient ,
358
+ async fn fetch_txs_with_spks < I , S > (
359
+ client : & esplora_client:: AsyncClient < S > ,
351
360
inserted_txs : & mut HashSet < Txid > ,
352
361
spks : I ,
353
362
parallel_requests : usize ,
354
363
) -> Result < TxUpdate < ConfirmationBlockTime > , Error >
355
364
where
365
+ I : IntoIterator < Item = ScriptBuf > + Send ,
356
366
I :: IntoIter : Send ,
367
+ S : Sleeper + Clone + Send + Sync ,
357
368
{
358
369
fetch_txs_with_keychain_spks (
359
370
client,
@@ -372,14 +383,16 @@ where
372
383
/// `parallel_requests` specifies the maximum number of HTTP requests to make in parallel.
373
384
///
374
385
/// Refer to [crate-level docs](crate) for more.
375
- async fn fetch_txs_with_txids < I : IntoIterator < Item = Txid > + Send > (
376
- client : & esplora_client:: AsyncClient ,
386
+ async fn fetch_txs_with_txids < I , S > (
387
+ client : & esplora_client:: AsyncClient < S > ,
377
388
inserted_txs : & mut HashSet < Txid > ,
378
389
txids : I ,
379
390
parallel_requests : usize ,
380
391
) -> Result < TxUpdate < ConfirmationBlockTime > , Error >
381
392
where
393
+ I : IntoIterator < Item = Txid > + Send ,
382
394
I :: IntoIter : Send ,
395
+ S : Sleeper + Clone + Send + Sync ,
383
396
{
384
397
let mut update = TxUpdate :: < ConfirmationBlockTime > :: default ( ) ;
385
398
// Only fetch for non-inserted txs.
@@ -421,14 +434,16 @@ where
421
434
/// `parallel_requests` specifies the maximum number of HTTP requests to make in parallel.
422
435
///
423
436
/// Refer to [crate-level docs](crate) for more.
424
- async fn fetch_txs_with_outpoints < I : IntoIterator < Item = OutPoint > + Send > (
425
- client : & esplora_client:: AsyncClient ,
437
+ async fn fetch_txs_with_outpoints < I , S > (
438
+ client : & esplora_client:: AsyncClient < S > ,
426
439
inserted_txs : & mut HashSet < Txid > ,
427
440
outpoints : I ,
428
441
parallel_requests : usize ,
429
442
) -> Result < TxUpdate < ConfirmationBlockTime > , Error >
430
443
where
444
+ I : IntoIterator < Item = OutPoint > + Send ,
431
445
I :: IntoIter : Send ,
446
+ S : Sleeper + Clone + Send + Sync ,
432
447
{
433
448
let outpoints = outpoints. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
434
449
let mut update = TxUpdate :: < ConfirmationBlockTime > :: default ( ) ;
0 commit comments