@@ -34,54 +34,42 @@ pub trait EsploraExt {
3434 request_heights : impl IntoIterator < Item = u32 > ,
3535 ) -> Result < local_chain:: Update , Error > ;
3636
37- /// Scan Esplora for the data specified and return a [`TxGraph`] and a map of last active
38- /// indices.
37+ /// Full scan the keychain scripts specified with the blockchain (via an Esplora client) and
38+ /// returns a [`TxGraph`] and a map of last active indices.
3939 ///
4040 /// * `keychain_spks`: keychains that we want to scan transactions for
41- /// * `txids`: transactions for which we want updated [`ConfirmationTimeHeightAnchor`]s
42- /// * `outpoints`: transactions associated with these outpoints (residing, spending) that we
43- /// want to include in the update
4441 ///
45- /// The scan for each keychain stops after a gap of `stop_gap` script pubkeys with no associated
42+ /// The full scan for each keychain stops after a gap of `stop_gap` script pubkeys with no associated
4643 /// transactions. `parallel_requests` specifies the max number of HTTP requests to make in
4744 /// parallel.
4845 #[ allow( clippy:: result_large_err) ]
49- fn scan_txs_with_keychains < K : Ord + Clone > (
46+ fn full_scan < K : Ord + Clone > (
5047 & self ,
5148 keychain_spks : BTreeMap < K , impl IntoIterator < Item = ( u32 , ScriptBuf ) > > ,
52- txids : impl IntoIterator < Item = Txid > ,
53- outpoints : impl IntoIterator < Item = OutPoint > ,
5449 stop_gap : usize ,
5550 parallel_requests : usize ,
5651 ) -> Result < ( TxGraph < ConfirmationTimeHeightAnchor > , BTreeMap < K , u32 > ) , Error > ;
5752
58- /// Convenience method to call [`scan_txs_with_keychains`] without requiring a keychain.
53+ /// Sync a set of scripts with with the blockchain (via an Esplora client) for the data
54+ /// specified and return a [`TxGraph`] and a map of last active indices.
5955 ///
60- /// [`scan_txs_with_keychains`]: EsploraExt::scan_txs_with_keychains
56+ /// * `misc_spks`: scripts that we want to sync transactions for
57+ /// * `txids`: transactions for which we want updated [`ConfirmationTimeHeightAnchor`]s
58+ /// * `outpoints`: transactions associated with these outpoints (residing, spending) that we
59+ /// want to include in the update
60+ ///
61+ /// If the scripts to sync are unknown, such as when restoring or importing a keychain that
62+ /// may include scripts that have been used, use [`full_scan`] with the keychain.
63+ ///
64+ /// [`full_scan`]: EsploraExt::full_scan
6165 #[ allow( clippy:: result_large_err) ]
62- fn scan_txs (
66+ fn sync (
6367 & self ,
6468 misc_spks : impl IntoIterator < Item = ScriptBuf > ,
6569 txids : impl IntoIterator < Item = Txid > ,
6670 outpoints : impl IntoIterator < Item = OutPoint > ,
6771 parallel_requests : usize ,
68- ) -> Result < TxGraph < ConfirmationTimeHeightAnchor > , Error > {
69- self . scan_txs_with_keychains (
70- [ (
71- ( ) ,
72- misc_spks
73- . into_iter ( )
74- . enumerate ( )
75- . map ( |( i, spk) | ( i as u32 , spk) ) ,
76- ) ]
77- . into ( ) ,
78- txids,
79- outpoints,
80- usize:: MAX ,
81- parallel_requests,
82- )
83- . map ( |( g, _) | g)
84- }
72+ ) -> Result < TxGraph < ConfirmationTimeHeightAnchor > , Error > ;
8573}
8674
8775impl EsploraExt for esplora_client:: BlockingClient {
@@ -190,11 +178,9 @@ impl EsploraExt for esplora_client::BlockingClient {
190178 } )
191179 }
192180
193- fn scan_txs_with_keychains < K : Ord + Clone > (
181+ fn full_scan < K : Ord + Clone > (
194182 & self ,
195183 keychain_spks : BTreeMap < K , impl IntoIterator < Item = ( u32 , ScriptBuf ) > > ,
196- txids : impl IntoIterator < Item = Txid > ,
197- outpoints : impl IntoIterator < Item = OutPoint > ,
198184 stop_gap : usize ,
199185 parallel_requests : usize ,
200186 ) -> Result < ( TxGraph < ConfirmationTimeHeightAnchor > , BTreeMap < K , u32 > ) , Error > {
@@ -266,6 +252,31 @@ impl EsploraExt for esplora_client::BlockingClient {
266252 }
267253 }
268254
255+ Ok ( ( graph, last_active_indexes) )
256+ }
257+
258+ fn sync (
259+ & self ,
260+ misc_spks : impl IntoIterator < Item = ScriptBuf > ,
261+ txids : impl IntoIterator < Item = Txid > ,
262+ outpoints : impl IntoIterator < Item = OutPoint > ,
263+ parallel_requests : usize ,
264+ ) -> Result < TxGraph < ConfirmationTimeHeightAnchor > , Error > {
265+ let mut graph = self
266+ . full_scan (
267+ [ (
268+ ( ) ,
269+ misc_spks
270+ . into_iter ( )
271+ . enumerate ( )
272+ . map ( |( i, spk) | ( i as u32 , spk) ) ,
273+ ) ]
274+ . into ( ) ,
275+ usize:: MAX ,
276+ parallel_requests,
277+ )
278+ . map ( |( g, _) | g) ?;
279+
269280 let mut txids = txids. into_iter ( ) ;
270281 loop {
271282 let handles = txids
@@ -292,7 +303,7 @@ impl EsploraExt for esplora_client::BlockingClient {
292303 }
293304 }
294305
295- for op in outpoints. into_iter ( ) {
306+ for op in outpoints {
296307 if graph. get_tx ( op. txid ) . is_none ( ) {
297308 if let Some ( tx) = self . get_tx ( & op. txid ) ? {
298309 let _ = graph. insert_tx ( tx) ;
@@ -317,7 +328,6 @@ impl EsploraExt for esplora_client::BlockingClient {
317328 }
318329 }
319330 }
320-
321- Ok ( ( graph, last_active_indexes) )
331+ Ok ( graph)
322332 }
323333}
0 commit comments