@@ -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 time, 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 : Option < 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 : Option < 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 : Option < 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,11 @@ 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+ if let Some ( seen_at) = time {
204+ let _ = graph. insert_seen_at ( tx. txid , seen_at) ;
205+ }
206+ }
197207
198208 let previous_outputs = tx. vin . iter ( ) . filter_map ( |vin| {
199209 let prevout = vin. prevout . as_ref ( ) ?;
@@ -240,6 +250,7 @@ impl EsploraExt for esplora_client::BlockingClient {
240250 txids : impl IntoIterator < Item = Txid > ,
241251 outpoints : impl IntoIterator < Item = OutPoint > ,
242252 parallel_requests : usize ,
253+ time : Option < u64 > ,
243254 ) -> Result < TxGraph < ConfirmationTimeHeightAnchor > , Error > {
244255 let mut graph = self
245256 . full_scan (
@@ -253,6 +264,7 @@ impl EsploraExt for esplora_client::BlockingClient {
253264 . into ( ) ,
254265 usize:: MAX ,
255266 parallel_requests,
267+ time,
256268 )
257269 . map ( |( g, _) | g) ?;
258270
@@ -284,10 +296,16 @@ impl EsploraExt for esplora_client::BlockingClient {
284296 if let Some ( anchor) = anchor_from_status ( & status) {
285297 let _ = graph. insert_anchor ( txid, anchor) ;
286298 }
299+ if !status. confirmed {
300+ if let Some ( seen_at) = time {
301+ let _ = graph. insert_seen_at ( txid, seen_at) ;
302+ }
303+ }
287304 }
288305 }
289306
290307 for op in outpoints {
308+ // get tx for this outpoint
291309 if graph. get_tx ( op. txid ) . is_none ( ) {
292310 if let Some ( tx) = self . get_tx ( & op. txid ) ? {
293311 let _ = graph. insert_tx ( tx) ;
@@ -296,8 +314,14 @@ impl EsploraExt for esplora_client::BlockingClient {
296314 if let Some ( anchor) = anchor_from_status ( & status) {
297315 let _ = graph. insert_anchor ( op. txid , anchor) ;
298316 }
317+ if !status. confirmed {
318+ if let Some ( seen_at) = time {
319+ let _ = graph. insert_seen_at ( op. txid , seen_at) ;
320+ }
321+ }
299322 }
300323
324+ // get spending status of this outpoint
301325 if let Some ( op_status) = self . get_output_status ( & op. txid , op. vout as _ ) ? {
302326 if let Some ( txid) = op_status. txid {
303327 if graph. get_tx ( txid) . is_none ( ) {
@@ -308,6 +332,11 @@ impl EsploraExt for esplora_client::BlockingClient {
308332 if let Some ( anchor) = anchor_from_status ( & status) {
309333 let _ = graph. insert_anchor ( txid, anchor) ;
310334 }
335+ if !status. confirmed {
336+ if let Some ( seen_at) = time {
337+ let _ = graph. insert_seen_at ( txid, seen_at) ;
338+ }
339+ }
311340 }
312341 }
313342 }
0 commit comments