@@ -5,6 +5,7 @@ use bdk_core::{
55 bitcoin:: { BlockHash , OutPoint , ScriptBuf , Txid } ,
66 BlockId , CheckPoint , ConfirmationBlockTime , Indexed , TxUpdate ,
77} ;
8+ use esplora_client:: Sleeper ;
89use futures:: { stream:: FuturesOrdered , TryStreamExt } ;
910
1011use crate :: { insert_anchor_from_status, insert_prevouts} ;
@@ -50,7 +51,11 @@ pub trait EsploraAsyncExt {
5051
5152#[ cfg_attr( target_arch = "wasm32" , async_trait( ?Send ) ) ]
5253#[ 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+ {
5459 async fn full_scan < K : Ord + Clone + Send , R : Into < FullScanRequest < K > > + Send > (
5560 & self ,
5661 request : R ,
@@ -165,8 +170,8 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
165170/// block-based chain-sources). Therefore it's better to be conservative when setting the tip (use
166171/// an earlier tip rather than a later tip) otherwise the caller may accidentally skip blocks when
167172/// 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 > ,
170175) -> Result < BTreeMap < u32 , BlockHash > , Error > {
171176 Ok ( client
172177 . get_blocks ( None )
@@ -179,8 +184,8 @@ async fn fetch_latest_blocks(
179184/// Used instead of [`esplora_client::BlockingClient::get_block_hash`].
180185///
181186/// 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 > ,
184189 latest_blocks : & BTreeMap < u32 , BlockHash > ,
185190 height : u32 ,
186191) -> Result < Option < BlockHash > , Error > {
@@ -205,8 +210,8 @@ async fn fetch_block(
205210///
206211/// We want to have a corresponding checkpoint per anchor height. However, checkpoints fetched
207212/// 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 > ,
210215 latest_blocks : & BTreeMap < u32 , BlockHash > ,
211216 local_tip : & CheckPoint ,
212217 anchors : & BTreeSet < ( ConfirmationBlockTime , Txid ) > ,
@@ -271,13 +276,17 @@ async fn chain_update(
271276/// script pubkey that contains a non-empty transaction history.
272277///
273278/// 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 > ,
276281 inserted_txs : & mut HashSet < Txid > ,
277282 mut keychain_spks : I ,
278283 stop_gap : usize ,
279284 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+ {
281290 type TxsOfSpkIndex = ( u32 , Vec < esplora_client:: Tx > ) ;
282291
283292 let mut update = TxUpdate :: < ConfirmationBlockTime > :: default ( ) ;
@@ -346,14 +355,16 @@ async fn fetch_txs_with_keychain_spks<I: Iterator<Item = Indexed<ScriptBuf>> + S
346355/// HTTP requests to make in parallel.
347356///
348357/// 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 > ,
351360 inserted_txs : & mut HashSet < Txid > ,
352361 spks : I ,
353362 parallel_requests : usize ,
354363) -> Result < TxUpdate < ConfirmationBlockTime > , Error >
355364where
365+ I : IntoIterator < Item = ScriptBuf > + Send ,
356366 I :: IntoIter : Send ,
367+ S : Sleeper + Clone + Send + Sync ,
357368{
358369 fetch_txs_with_keychain_spks (
359370 client,
@@ -372,14 +383,16 @@ where
372383/// `parallel_requests` specifies the maximum number of HTTP requests to make in parallel.
373384///
374385/// 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 > ,
377388 inserted_txs : & mut HashSet < Txid > ,
378389 txids : I ,
379390 parallel_requests : usize ,
380391) -> Result < TxUpdate < ConfirmationBlockTime > , Error >
381392where
393+ I : IntoIterator < Item = Txid > + Send ,
382394 I :: IntoIter : Send ,
395+ S : Sleeper + Clone + Send + Sync ,
383396{
384397 let mut update = TxUpdate :: < ConfirmationBlockTime > :: default ( ) ;
385398 // Only fetch for non-inserted txs.
@@ -421,14 +434,16 @@ where
421434/// `parallel_requests` specifies the maximum number of HTTP requests to make in parallel.
422435///
423436/// 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 > ,
426439 inserted_txs : & mut HashSet < Txid > ,
427440 outpoints : I ,
428441 parallel_requests : usize ,
429442) -> Result < TxUpdate < ConfirmationBlockTime > , Error >
430443where
444+ I : IntoIterator < Item = OutPoint > + Send ,
431445 I :: IntoIter : Send ,
446+ S : Sleeper + Clone + Send + Sync ,
432447{
433448 let outpoints = outpoints. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
434449 let mut update = TxUpdate :: < ConfirmationBlockTime > :: default ( ) ;
0 commit comments