Skip to content

Commit c94f27b

Browse files
committed
example: Use update_last_seen_unconfirmed in examples crates
We can update the last seen unconfirmed time for transactions by calling `update_last_seen_unconfirmed` on the graph update returned from a blockchain source, passing in the current time, before applying it to another `TxGraph`.
1 parent f673f70 commit c94f27b

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

example-crates/example_esplora/src/main.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,14 @@ fn main() -> anyhow::Result<()> {
189189
// is reached. It returns a `TxGraph` update (`graph_update`) and a structure that
190190
// represents the last active spk derivation indices of keychains
191191
// (`keychain_indices_update`).
192-
let (graph_update, last_active_indices) = client
192+
let (mut graph_update, last_active_indices) = client
193193
.full_scan(keychain_spks, *stop_gap, scan_options.parallel_requests)
194194
.context("scanning for transactions")?;
195195

196+
// We want to keep track of the latest time a transaction was seen unconfirmed.
197+
let now = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
198+
let _ = graph_update.update_last_seen_unconfirmed(now);
199+
196200
let mut graph = graph.lock().expect("mutex must not be poisoned");
197201
// Because we did a stop gap based scan we are likely to have some updates to our
198202
// deriviation indices. Usually before a scan you are on a fresh wallet with no
@@ -307,9 +311,13 @@ fn main() -> anyhow::Result<()> {
307311
}
308312
}
309313

310-
let graph_update =
314+
let mut graph_update =
311315
client.sync(spks, txids, outpoints, scan_options.parallel_requests)?;
312316

317+
// Update last seen unconfirmed
318+
let now = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
319+
let _ = graph_update.update_last_seen_unconfirmed(now);
320+
313321
graph.lock().unwrap().apply_update(graph_update)
314322
}
315323
};

example-crates/wallet_electrum/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ fn main() -> Result<(), anyhow::Error> {
6666
println!();
6767

6868
let missing = relevant_txids.missing_full_txs(wallet.as_ref());
69-
let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, None, missing)?;
69+
let mut graph_update =
70+
relevant_txids.into_confirmation_time_tx_graph(&client, None, missing)?;
71+
let now = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
72+
let _ = graph_update.update_last_seen_unconfirmed(now);
7073

7174
let wallet_update = Update {
7275
last_active_indices: keychain_update,

example-crates/wallet_esplora_async/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ async fn main() -> Result<(), anyhow::Error> {
5353
(k, k_spks)
5454
})
5555
.collect();
56-
let (update_graph, last_active_indices) = client
56+
let (mut update_graph, last_active_indices) = client
5757
.full_scan(keychain_spks, STOP_GAP, PARALLEL_REQUESTS)
5858
.await?;
59+
60+
let now = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
61+
let _ = update_graph.update_last_seen_unconfirmed(now);
5962
let missing_heights = update_graph.missing_heights(wallet.local_chain());
6063
let chain_update = client.update_local_chain(prev_tip, missing_heights).await?;
6164
let update = Update {

example-crates/wallet_esplora_blocking/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ fn main() -> Result<(), anyhow::Error> {
5353
})
5454
.collect();
5555

56-
let (update_graph, last_active_indices) =
56+
let (mut update_graph, last_active_indices) =
5757
client.full_scan(keychain_spks, STOP_GAP, PARALLEL_REQUESTS)?;
58+
59+
let now = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
60+
let _ = update_graph.update_last_seen_unconfirmed(now);
5861
let missing_heights = update_graph.missing_heights(wallet.local_chain());
5962
let chain_update = client.update_local_chain(prev_tip, missing_heights)?;
6063
let update = Update {

0 commit comments

Comments
 (0)