11use std:: collections:: BTreeSet ;
22
33use async_trait:: async_trait;
4+ use bdk_chain:: spk_client:: { FullScanRequest , FullScanResult , SyncRequest , SyncResult } ;
45use bdk_chain:: Anchor ;
56use bdk_chain:: {
67 bitcoin:: { BlockHash , OutPoint , ScriptBuf , TxOut , Txid } ,
@@ -11,7 +12,7 @@ use bdk_chain::{
1112use esplora_client:: { Amount , TxStatus } ;
1213use futures:: { stream:: FuturesOrdered , TryStreamExt } ;
1314
14- use crate :: { anchor_from_status, FullScanUpdate , SyncUpdate } ;
15+ use crate :: anchor_from_status;
1516
1617/// [`esplora_client::Error`]
1718type Error = Box < esplora_client:: Error > ;
@@ -50,14 +51,10 @@ pub trait EsploraAsyncExt {
5051 /// [`LocalChain::tip`]: bdk_chain::local_chain::LocalChain::tip
5152 async fn full_scan < K : Ord + Clone + Send > (
5253 & self ,
53- local_tip : CheckPoint ,
54- keychain_spks : BTreeMap <
55- K ,
56- impl IntoIterator < IntoIter = impl Iterator < Item = ( u32 , ScriptBuf ) > + Send > + Send ,
57- > ,
54+ request : FullScanRequest < K > ,
5855 stop_gap : usize ,
5956 parallel_requests : usize ,
60- ) -> Result < FullScanUpdate < K > , Error > ;
57+ ) -> Result < FullScanResult < K > , Error > ;
6158
6259 /// Sync a set of scripts with the blockchain (via an Esplora client) for the data
6360 /// specified and return a [`TxGraph`].
@@ -75,55 +72,66 @@ pub trait EsploraAsyncExt {
7572 /// [`full_scan`]: EsploraAsyncExt::full_scan
7673 async fn sync (
7774 & self ,
78- local_tip : CheckPoint ,
79- misc_spks : impl IntoIterator < IntoIter = impl Iterator < Item = ScriptBuf > + Send > + Send ,
80- txids : impl IntoIterator < IntoIter = impl Iterator < Item = Txid > + Send > + Send ,
81- outpoints : impl IntoIterator < IntoIter = impl Iterator < Item = OutPoint > + Send > + Send ,
75+ request : SyncRequest ,
8276 parallel_requests : usize ,
83- ) -> Result < SyncUpdate , Error > ;
77+ ) -> Result < SyncResult , Error > ;
8478}
8579
8680#[ cfg_attr( target_arch = "wasm32" , async_trait( ?Send ) ) ]
8781#[ cfg_attr( not( target_arch = "wasm32" ) , async_trait) ]
8882impl EsploraAsyncExt for esplora_client:: AsyncClient {
8983 async fn full_scan < K : Ord + Clone + Send > (
9084 & self ,
91- local_tip : CheckPoint ,
92- keychain_spks : BTreeMap <
93- K ,
94- impl IntoIterator < IntoIter = impl Iterator < Item = ( u32 , ScriptBuf ) > + Send > + Send ,
95- > ,
85+ request : FullScanRequest < K > ,
9686 stop_gap : usize ,
9787 parallel_requests : usize ,
98- ) -> Result < FullScanUpdate < K > , Error > {
88+ ) -> Result < FullScanResult < K > , Error > {
9989 let latest_blocks = fetch_latest_blocks ( self ) . await ?;
100- let ( tx_graph, last_active_indices) =
101- full_scan_for_index_and_graph ( self , keychain_spks, stop_gap, parallel_requests) . await ?;
102- let local_chain =
103- chain_update ( self , & latest_blocks, & local_tip, tx_graph. all_anchors ( ) ) . await ?;
104- Ok ( FullScanUpdate {
105- local_chain,
106- tx_graph,
90+ let ( graph_update, last_active_indices) = full_scan_for_index_and_graph (
91+ self ,
92+ request. spks_by_keychain ,
93+ stop_gap,
94+ parallel_requests,
95+ )
96+ . await ?;
97+ let chain_update = chain_update (
98+ self ,
99+ & latest_blocks,
100+ & request. chain_tip ,
101+ graph_update. all_anchors ( ) ,
102+ )
103+ . await ?;
104+ Ok ( FullScanResult {
105+ chain_update,
106+ graph_update,
107107 last_active_indices,
108108 } )
109109 }
110110
111111 async fn sync (
112112 & self ,
113- local_tip : CheckPoint ,
114- misc_spks : impl IntoIterator < IntoIter = impl Iterator < Item = ScriptBuf > + Send > + Send ,
115- txids : impl IntoIterator < IntoIter = impl Iterator < Item = Txid > + Send > + Send ,
116- outpoints : impl IntoIterator < IntoIter = impl Iterator < Item = OutPoint > + Send > + Send ,
113+ request : SyncRequest ,
117114 parallel_requests : usize ,
118- ) -> Result < SyncUpdate , Error > {
115+ ) -> Result < SyncResult , Error > {
119116 let latest_blocks = fetch_latest_blocks ( self ) . await ?;
120- let tx_graph =
121- sync_for_index_and_graph ( self , misc_spks, txids, outpoints, parallel_requests) . await ?;
122- let local_chain =
123- chain_update ( self , & latest_blocks, & local_tip, tx_graph. all_anchors ( ) ) . await ?;
124- Ok ( SyncUpdate {
125- tx_graph,
126- local_chain,
117+ let graph_update = sync_for_index_and_graph (
118+ self ,
119+ request. spks ,
120+ request. txids ,
121+ request. outpoints ,
122+ parallel_requests,
123+ )
124+ . await ?;
125+ let chain_update = chain_update (
126+ self ,
127+ & latest_blocks,
128+ & request. chain_tip ,
129+ graph_update. all_anchors ( ) ,
130+ )
131+ . await ?;
132+ Ok ( SyncResult {
133+ chain_update,
134+ graph_update,
127135 } )
128136 }
129137}
0 commit comments