Skip to content

Commit

Permalink
example: Use update_last_seen_unconfirmed in examples
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
ValuedMammal committed Apr 2, 2024
1 parent c551dfb commit b21ea0f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
12 changes: 10 additions & 2 deletions example-crates/example_esplora/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,14 @@ fn main() -> anyhow::Result<()> {
// is reached. It returns a `TxGraph` update (`graph_update`) and a structure that
// represents the last active spk derivation indices of keychains
// (`keychain_indices_update`).
let (graph_update, last_active_indices) = client
let (mut graph_update, last_active_indices) = client
.full_scan(keychain_spks, *stop_gap, scan_options.parallel_requests)
.context("scanning for transactions")?;

// We want to keep track of the latest time a transaction was seen unconfirmed.
let now = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
let _ = graph_update.update_last_seen_unconfirmed(now);

let mut graph = graph.lock().expect("mutex must not be poisoned");
// Because we did a stop gap based scan we are likely to have some updates to our
// deriviation indices. Usually before a scan you are on a fresh wallet with no
Expand Down Expand Up @@ -307,9 +311,13 @@ fn main() -> anyhow::Result<()> {
}
}

let graph_update =
let mut graph_update =
client.sync(spks, txids, outpoints, scan_options.parallel_requests)?;

// Update last seen unconfirmed
let now = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
let _ = graph_update.update_last_seen_unconfirmed(now);

graph.lock().unwrap().apply_update(graph_update)
}
};
Expand Down
5 changes: 4 additions & 1 deletion example-crates/wallet_esplora_async/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ async fn main() -> Result<(), anyhow::Error> {
(k, k_spks)
})
.collect();
let (update_graph, last_active_indices) = client
let (mut update_graph, last_active_indices) = client
.full_scan(keychain_spks, STOP_GAP, PARALLEL_REQUESTS)
.await?;

let now = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
let _ = update_graph.update_last_seen_unconfirmed(now);
let missing_heights = update_graph.missing_heights(wallet.local_chain());
let chain_update = client.update_local_chain(prev_tip, missing_heights).await?;
let update = Update {
Expand Down
5 changes: 4 additions & 1 deletion example-crates/wallet_esplora_blocking/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ fn main() -> Result<(), anyhow::Error> {
})
.collect();

let (update_graph, last_active_indices) =
let (mut update_graph, last_active_indices) =
client.full_scan(keychain_spks, STOP_GAP, PARALLEL_REQUESTS)?;

let now = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
let _ = update_graph.update_last_seen_unconfirmed(now);
let missing_heights = update_graph.missing_heights(wallet.local_chain());
let chain_update = client.update_local_chain(prev_tip, missing_heights)?;
let update = Update {
Expand Down

0 comments on commit b21ea0f

Please sign in to comment.