fix(electrum)!: Remove seen_at
param from into_tx_graph
and `into_confirmation_time_tx_graph`, since now it makes sense to use `TxGraph::update_last_seen_unconfirmed`. Also, use `update_last_seen_unconfirmed` in examples for electrum/esplora. We show how to update the last seen 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`.
This commit is contained in:
parent
37fca35dde
commit
a2a64ffb6e
@ -40,15 +40,11 @@ impl RelevantTxids {
|
|||||||
pub fn into_tx_graph(
|
pub fn into_tx_graph(
|
||||||
self,
|
self,
|
||||||
client: &Client,
|
client: &Client,
|
||||||
seen_at: Option<u64>,
|
|
||||||
missing: Vec<Txid>,
|
missing: Vec<Txid>,
|
||||||
) -> Result<TxGraph<ConfirmationHeightAnchor>, Error> {
|
) -> Result<TxGraph<ConfirmationHeightAnchor>, Error> {
|
||||||
let new_txs = client.batch_transaction_get(&missing)?;
|
let new_txs = client.batch_transaction_get(&missing)?;
|
||||||
let mut graph = TxGraph::<ConfirmationHeightAnchor>::new(new_txs);
|
let mut graph = TxGraph::<ConfirmationHeightAnchor>::new(new_txs);
|
||||||
for (txid, anchors) in self.0 {
|
for (txid, anchors) in self.0 {
|
||||||
if let Some(seen_at) = seen_at {
|
|
||||||
let _ = graph.insert_seen_at(txid, seen_at);
|
|
||||||
}
|
|
||||||
for anchor in anchors {
|
for anchor in anchors {
|
||||||
let _ = graph.insert_anchor(txid, anchor);
|
let _ = graph.insert_anchor(txid, anchor);
|
||||||
}
|
}
|
||||||
@ -67,10 +63,9 @@ impl RelevantTxids {
|
|||||||
pub fn into_confirmation_time_tx_graph(
|
pub fn into_confirmation_time_tx_graph(
|
||||||
self,
|
self,
|
||||||
client: &Client,
|
client: &Client,
|
||||||
seen_at: Option<u64>,
|
|
||||||
missing: Vec<Txid>,
|
missing: Vec<Txid>,
|
||||||
) -> Result<TxGraph<ConfirmationTimeHeightAnchor>, Error> {
|
) -> Result<TxGraph<ConfirmationTimeHeightAnchor>, Error> {
|
||||||
let graph = self.into_tx_graph(client, seen_at, missing)?;
|
let graph = self.into_tx_graph(client, missing)?;
|
||||||
|
|
||||||
let relevant_heights = {
|
let relevant_heights = {
|
||||||
let mut visited_heights = HashSet::new();
|
let mut visited_heights = HashSet::new();
|
||||||
|
@ -68,7 +68,7 @@ fn scan_detects_confirmed_tx() -> Result<()> {
|
|||||||
} = client.sync(recv_chain.tip(), [spk_to_track], None, None, 5)?;
|
} = client.sync(recv_chain.tip(), [spk_to_track], None, None, 5)?;
|
||||||
|
|
||||||
let missing = relevant_txids.missing_full_txs(recv_graph.graph());
|
let missing = relevant_txids.missing_full_txs(recv_graph.graph());
|
||||||
let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, None, missing)?;
|
let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, missing)?;
|
||||||
let _ = recv_chain
|
let _ = recv_chain
|
||||||
.apply_update(chain_update)
|
.apply_update(chain_update)
|
||||||
.map_err(|err| anyhow::anyhow!("LocalChain update error: {:?}", err))?;
|
.map_err(|err| anyhow::anyhow!("LocalChain update error: {:?}", err))?;
|
||||||
@ -134,7 +134,7 @@ fn tx_can_become_unconfirmed_after_reorg() -> Result<()> {
|
|||||||
} = client.sync(recv_chain.tip(), [spk_to_track.clone()], None, None, 5)?;
|
} = client.sync(recv_chain.tip(), [spk_to_track.clone()], None, None, 5)?;
|
||||||
|
|
||||||
let missing = relevant_txids.missing_full_txs(recv_graph.graph());
|
let missing = relevant_txids.missing_full_txs(recv_graph.graph());
|
||||||
let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, None, missing)?;
|
let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, missing)?;
|
||||||
let _ = recv_chain
|
let _ = recv_chain
|
||||||
.apply_update(chain_update)
|
.apply_update(chain_update)
|
||||||
.map_err(|err| anyhow::anyhow!("LocalChain update error: {:?}", err))?;
|
.map_err(|err| anyhow::anyhow!("LocalChain update error: {:?}", err))?;
|
||||||
@ -164,8 +164,7 @@ fn tx_can_become_unconfirmed_after_reorg() -> Result<()> {
|
|||||||
} = client.sync(recv_chain.tip(), [spk_to_track.clone()], None, None, 5)?;
|
} = client.sync(recv_chain.tip(), [spk_to_track.clone()], None, None, 5)?;
|
||||||
|
|
||||||
let missing = relevant_txids.missing_full_txs(recv_graph.graph());
|
let missing = relevant_txids.missing_full_txs(recv_graph.graph());
|
||||||
let graph_update =
|
let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, missing)?;
|
||||||
relevant_txids.into_confirmation_time_tx_graph(&client, None, missing)?;
|
|
||||||
let _ = recv_chain
|
let _ = recv_chain
|
||||||
.apply_update(chain_update)
|
.apply_update(chain_update)
|
||||||
.map_err(|err| anyhow::anyhow!("LocalChain update error: {:?}", err))?;
|
.map_err(|err| anyhow::anyhow!("LocalChain update error: {:?}", err))?;
|
||||||
|
@ -299,12 +299,12 @@ fn main() -> anyhow::Result<()> {
|
|||||||
relevant_txids.missing_full_txs(graph.graph())
|
relevant_txids.missing_full_txs(graph.graph())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut graph_update = relevant_txids.into_tx_graph(&client, missing_txids)?;
|
||||||
let now = std::time::UNIX_EPOCH
|
let now = std::time::UNIX_EPOCH
|
||||||
.elapsed()
|
.elapsed()
|
||||||
.expect("must get time")
|
.expect("must get time")
|
||||||
.as_secs();
|
.as_secs();
|
||||||
|
let _ = graph_update.update_last_seen_unconfirmed(now);
|
||||||
let graph_update = relevant_txids.into_tx_graph(&client, Some(now), missing_txids)?;
|
|
||||||
|
|
||||||
let db_changeset = {
|
let db_changeset = {
|
||||||
let mut chain = chain.lock().unwrap();
|
let mut chain = chain.lock().unwrap();
|
||||||
|
@ -189,10 +189,14 @@ fn main() -> anyhow::Result<()> {
|
|||||||
// is reached. It returns a `TxGraph` update (`graph_update`) and a structure that
|
// is reached. It returns a `TxGraph` update (`graph_update`) and a structure that
|
||||||
// represents the last active spk derivation indices of keychains
|
// represents the last active spk derivation indices of keychains
|
||||||
// (`keychain_indices_update`).
|
// (`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)
|
.full_scan(keychain_spks, *stop_gap, scan_options.parallel_requests)
|
||||||
.context("scanning for transactions")?;
|
.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");
|
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
|
// 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
|
// deriviation indices. Usually before a scan you are on a fresh wallet with no
|
||||||
@ -307,9 +311,13 @@ fn main() -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let graph_update =
|
let mut graph_update =
|
||||||
client.sync(spks, txids, outpoints, scan_options.parallel_requests)?;
|
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)
|
graph.lock().unwrap().apply_update(graph_update)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -66,7 +66,9 @@ fn main() -> Result<(), anyhow::Error> {
|
|||||||
println!();
|
println!();
|
||||||
|
|
||||||
let missing = relevant_txids.missing_full_txs(wallet.as_ref());
|
let missing = relevant_txids.missing_full_txs(wallet.as_ref());
|
||||||
let graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, None, missing)?;
|
let mut graph_update = relevant_txids.into_confirmation_time_tx_graph(&client, missing)?;
|
||||||
|
let now = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
|
||||||
|
let _ = graph_update.update_last_seen_unconfirmed(now);
|
||||||
|
|
||||||
let wallet_update = Update {
|
let wallet_update = Update {
|
||||||
last_active_indices: keychain_update,
|
last_active_indices: keychain_update,
|
||||||
|
@ -53,9 +53,12 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||||||
(k, k_spks)
|
(k, k_spks)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let (update_graph, last_active_indices) = client
|
let (mut update_graph, last_active_indices) = client
|
||||||
.full_scan(keychain_spks, STOP_GAP, PARALLEL_REQUESTS)
|
.full_scan(keychain_spks, STOP_GAP, PARALLEL_REQUESTS)
|
||||||
.await?;
|
.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 missing_heights = update_graph.missing_heights(wallet.local_chain());
|
||||||
let chain_update = client.update_local_chain(prev_tip, missing_heights).await?;
|
let chain_update = client.update_local_chain(prev_tip, missing_heights).await?;
|
||||||
let update = Update {
|
let update = Update {
|
||||||
|
@ -53,8 +53,11 @@ fn main() -> Result<(), anyhow::Error> {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let (update_graph, last_active_indices) =
|
let (mut update_graph, last_active_indices) =
|
||||||
client.full_scan(keychain_spks, STOP_GAP, PARALLEL_REQUESTS)?;
|
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 missing_heights = update_graph.missing_heights(wallet.local_chain());
|
||||||
let chain_update = client.update_local_chain(prev_tip, missing_heights)?;
|
let chain_update = client.update_local_chain(prev_tip, missing_heights)?;
|
||||||
let update = Update {
|
let update = Update {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user