Skip to content

Commit d499050

Browse files
authored
feat(wallet): apply evicted transactions
1 parent 155566e commit d499050

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

bdk-ffi/src/types.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,15 @@ pub struct UnconfirmedTx {
777777
pub last_seen: u64,
778778
}
779779

780+
/// This type replaces the Rust tuple `(txid, evicted_at)` used in the Wallet::apply_evicted_txs` method,
781+
/// where `evicted_at` is the timestamp of when the transaction `txid` was evicted from the mempool.
782+
/// Transactions may be evicted for paying a low fee rate or having invalid scripts.
783+
#[derive(uniffi::Record)]
784+
pub struct EvictedTx {
785+
pub txid: Arc<Txid>,
786+
pub evicted_at: u64,
787+
}
788+
780789
/// Mapping of descriptors to their last revealed index.
781790
#[derive(Debug, Clone, uniffi::Record)]
782791
pub struct IndexerChangeSet {

bdk-ffi/src/wallet.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use crate::error::{
66
};
77
use crate::store::{PersistenceType, Persister};
88
use crate::types::{
9-
AddressInfo, Balance, BlockId, CanonicalTx, FullScanRequestBuilder, KeychainAndIndex,
10-
LocalOutput, Policy, SentAndReceivedValues, SignOptions, SyncRequestBuilder, UnconfirmedTx,
11-
Update,
9+
AddressInfo, Balance, BlockId, CanonicalTx, EvictedTx, FullScanRequestBuilder,
10+
KeychainAndIndex, LocalOutput, Policy, SentAndReceivedValues, SignOptions, SyncRequestBuilder,
11+
UnconfirmedTx, Update,
1212
};
1313

1414
use bdk_wallet::bitcoin::Network;
@@ -223,6 +223,19 @@ impl Wallet {
223223
)
224224
}
225225

226+
/// Apply transactions that have been evicted from the mempool.
227+
/// Transactions may be evicted for paying too-low fee, or for being malformed.
228+
/// Irrelevant transactions are ignored.
229+
///
230+
/// For more information: https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.Wallet.html#method.apply_evicted_txs
231+
pub fn apply_evicted_txs(&self, evicted_txs: Vec<EvictedTx>) {
232+
self.get_wallet().apply_evicted_txs(
233+
evicted_txs
234+
.into_iter()
235+
.map(|etx| (etx.txid.0, etx.evicted_at)),
236+
);
237+
}
238+
226239
/// The derivation index of this wallet. It will return `None` if it has not derived any addresses.
227240
/// Otherwise, it will return the index of the highest address it has derived.
228241
pub fn derivation_index(&self, keychain: KeychainKind) -> Option<u32> {

0 commit comments

Comments
 (0)