@@ -49,12 +49,14 @@ pub trait EsploraExt {
4949 ///
5050 /// The full scan for each keychain stops after a gap of `stop_gap` script pubkeys with no associated
5151 /// transactions. `parallel_requests` specifies the max number of HTTP requests to make in
52- /// parallel.
52+ /// parallel. `time` is the current time, typically a UNIX timestamp, used only when setting
53+ /// the time a transaction was last seen unconfirmed.
5354 fn full_scan < K : Ord + Clone > (
5455 & self ,
5556 keychain_spks : BTreeMap < K , impl IntoIterator < Item = ( u32 , ScriptBuf ) > > ,
5657 stop_gap : usize ,
5758 parallel_requests : usize ,
59+ time : u64 ,
5860 ) -> Result < ( TxGraph < ConfirmationTimeHeightAnchor > , BTreeMap < K , u32 > ) , Error > ;
5961
6062 /// Sync a set of scripts with the blockchain (via an Esplora client) for the data
@@ -64,6 +66,7 @@ pub trait EsploraExt {
6466 /// * `txids`: transactions for which we want updated [`ConfirmationTimeHeightAnchor`]s
6567 /// * `outpoints`: transactions associated with these outpoints (residing, spending) that we
6668 /// want to include in the update
69+ /// * `time`: UNIX timestamp used to set the time a transaction was last seen unconfirmed
6770 ///
6871 /// If the scripts to sync are unknown, such as when restoring or importing a keychain that
6972 /// may include scripts that have been used, use [`full_scan`] with the keychain.
@@ -75,6 +78,7 @@ pub trait EsploraExt {
7578 txids : impl IntoIterator < Item = Txid > ,
7679 outpoints : impl IntoIterator < Item = OutPoint > ,
7780 parallel_requests : usize ,
81+ time : u64 ,
7882 ) -> Result < TxGraph < ConfirmationTimeHeightAnchor > , Error > ;
7983}
8084
@@ -144,6 +148,7 @@ impl EsploraExt for esplora_client::BlockingClient {
144148 keychain_spks : BTreeMap < K , impl IntoIterator < Item = ( u32 , ScriptBuf ) > > ,
145149 stop_gap : usize ,
146150 parallel_requests : usize ,
151+ time : u64 ,
147152 ) -> Result < ( TxGraph < ConfirmationTimeHeightAnchor > , BTreeMap < K , u32 > ) , Error > {
148153 type TxsOfSpkIndex = ( u32 , Vec < esplora_client:: Tx > ) ;
149154 let parallel_requests = Ord :: max ( parallel_requests, 1 ) ;
@@ -194,6 +199,9 @@ impl EsploraExt for esplora_client::BlockingClient {
194199 if let Some ( anchor) = anchor_from_status ( & tx. status ) {
195200 let _ = graph. insert_anchor ( tx. txid , anchor) ;
196201 }
202+ if !tx. status . confirmed {
203+ let _ = graph. insert_seen_at ( tx. txid , time) ;
204+ }
197205
198206 let previous_outputs = tx. vin . iter ( ) . filter_map ( |vin| {
199207 let prevout = vin. prevout . as_ref ( ) ?;
@@ -240,6 +248,7 @@ impl EsploraExt for esplora_client::BlockingClient {
240248 txids : impl IntoIterator < Item = Txid > ,
241249 outpoints : impl IntoIterator < Item = OutPoint > ,
242250 parallel_requests : usize ,
251+ time : u64 ,
243252 ) -> Result < TxGraph < ConfirmationTimeHeightAnchor > , Error > {
244253 let mut graph = self
245254 . full_scan (
@@ -253,6 +262,7 @@ impl EsploraExt for esplora_client::BlockingClient {
253262 . into ( ) ,
254263 usize:: MAX ,
255264 parallel_requests,
265+ time,
256266 )
257267 . map ( |( g, _) | g) ?;
258268
@@ -284,10 +294,14 @@ impl EsploraExt for esplora_client::BlockingClient {
284294 if let Some ( anchor) = anchor_from_status ( & status) {
285295 let _ = graph. insert_anchor ( txid, anchor) ;
286296 }
297+ if !status. confirmed {
298+ let _ = graph. insert_seen_at ( txid, time) ;
299+ }
287300 }
288301 }
289302
290303 for op in outpoints {
304+ // get tx for this outpoint
291305 if graph. get_tx ( op. txid ) . is_none ( ) {
292306 if let Some ( tx) = self . get_tx ( & op. txid ) ? {
293307 let _ = graph. insert_tx ( tx) ;
@@ -296,8 +310,12 @@ impl EsploraExt for esplora_client::BlockingClient {
296310 if let Some ( anchor) = anchor_from_status ( & status) {
297311 let _ = graph. insert_anchor ( op. txid , anchor) ;
298312 }
313+ if !status. confirmed {
314+ let _ = graph. insert_seen_at ( op. txid , time) ;
315+ }
299316 }
300317
318+ // get spending status of this outpoint
301319 if let Some ( op_status) = self . get_output_status ( & op. txid , op. vout as _ ) ? {
302320 if let Some ( txid) = op_status. txid {
303321 if graph. get_tx ( txid) . is_none ( ) {
@@ -308,6 +326,9 @@ impl EsploraExt for esplora_client::BlockingClient {
308326 if let Some ( anchor) = anchor_from_status ( & status) {
309327 let _ = graph. insert_anchor ( txid, anchor) ;
310328 }
329+ if !status. confirmed {
330+ let _ = graph. insert_seen_at ( txid, time) ;
331+ }
311332 }
312333 }
313334 }
0 commit comments