Skip to content

Commit 3c5fa0b

Browse files
committed
feat(wallet): Add method apply_evicted_txs
1 parent a247215 commit 3c5fa0b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

wallet/src/wallet/mod.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,6 +2249,11 @@ impl Wallet {
22492249
Ok(())
22502250
}
22512251

2252+
/// Stages the given `changeset`.
2253+
fn stage(&mut self, changeset: impl Into<ChangeSet>) {
2254+
self.stage.merge(changeset.into());
2255+
}
2256+
22522257
/// Get a reference of the staged [`ChangeSet`] that is yet to be committed (if any).
22532258
pub fn staged(&self) -> Option<&ChangeSet> {
22542259
if self.stage.is_empty() {
@@ -2367,6 +2372,35 @@ impl Wallet {
23672372
self.stage.merge(indexed_graph_changeset.into());
23682373
}
23692374

2375+
/// Apply evictions of the given txids with their associated timestamps.
2376+
///
2377+
/// This means that any pending unconfirmed tx in this set will no longer be canonical by
2378+
/// default. Note that an evicted tx can become canonical if it is later seen again or
2379+
/// observed on-chain.
2380+
///
2381+
/// This stages the changes which need to be persisted.
2382+
pub fn apply_evicted_txs(&mut self, evicted_txs: impl IntoIterator<Item = (Txid, u64)>) {
2383+
let chain = &self.chain;
2384+
let canon_txids: Vec<Txid> = self
2385+
.indexed_graph
2386+
.graph()
2387+
.list_canonical_txs(
2388+
chain,
2389+
chain.tip().block_id(),
2390+
CanonicalizationParams::default(),
2391+
)
2392+
.map(|c| c.tx_node.txid)
2393+
.collect();
2394+
2395+
let changeset = self.indexed_graph.batch_insert_relevant_evicted_at(
2396+
evicted_txs
2397+
.into_iter()
2398+
.filter(|(txid, _)| canon_txids.contains(txid)),
2399+
);
2400+
2401+
self.stage(changeset);
2402+
}
2403+
23702404
/// Used internally to ensure that all methods requiring a [`KeychainKind`] will use a
23712405
/// keychain with an associated descriptor. For example in case the wallet was created
23722406
/// with only one keychain, passing [`KeychainKind::Internal`] here will instead return

0 commit comments

Comments
 (0)