diff --git a/bdk-ffi/Cargo.lock b/bdk-ffi/Cargo.lock index 300c6644..0177b6db 100644 --- a/bdk-ffi/Cargo.lock +++ b/bdk-ffi/Cargo.lock @@ -151,7 +151,7 @@ dependencies = [ [[package]] name = "bdk-ffi" -version = "1.0.0-beta.7" +version = "1.2.0-dev" dependencies = [ "assert_matches", "bdk_core", diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 48e7aea6..b808713b 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -737,8 +737,14 @@ interface Wallet { [Throws=SqliteError] boolean persist(Connection connection); + + /// Apply relevant unconfirmed transactions to the wallet. + /// Transactions that are not relevant are filtered out. + void apply_unconfirmed_txs(sequence unconfirmed_txs); }; +typedef dictionary UnconfirmedTx; + interface Update {}; interface Policy { diff --git a/bdk-ffi/src/lib.rs b/bdk-ffi/src/lib.rs index 6cf28d3a..fd23f620 100644 --- a/bdk-ffi/src/lib.rs +++ b/bdk-ffi/src/lib.rs @@ -87,6 +87,7 @@ use crate::types::SyncRequestBuilder; use crate::types::SyncScriptInspector; use crate::types::Tx; use crate::types::TxStatus; +use crate::types::UnconfirmedTx; use crate::types::Update; use crate::wallet::Wallet; diff --git a/bdk-ffi/src/types.rs b/bdk-ffi/src/types.rs index 5002f857..84b0f00e 100644 --- a/bdk-ffi/src/types.rs +++ b/bdk-ffi/src/types.rs @@ -592,3 +592,11 @@ impl From for Tx { } } } + +/// This type replaces the Rust tuple `(tx, last_seen)` used in the Wallet::apply_unconfirmed_txs` method, +/// where `last_seen` is the timestamp of when the transaction `tx` was last seen in the mempool. +#[derive(uniffi::Record)] +pub struct UnconfirmedTx { + pub tx: Arc, + pub last_seen: u64, +} diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index 9b2ab8e4..76bed28e 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -7,7 +7,7 @@ use crate::error::{ use crate::store::Connection; use crate::types::{ AddressInfo, Balance, CanonicalTx, FullScanRequestBuilder, KeychainAndIndex, LocalOutput, - Policy, SentAndReceivedValues, SignOptions, SyncRequestBuilder, Update, + Policy, SentAndReceivedValues, SignOptions, SyncRequestBuilder, UnconfirmedTx, Update, }; use bdk_wallet::bitcoin::{Network, Txid}; @@ -130,6 +130,14 @@ impl Wallet { .map_err(CannotConnectError::from) } + pub fn apply_unconfirmed_txs(&self, unconfirmed_txs: Vec) { + self.get_wallet().apply_unconfirmed_txs( + unconfirmed_txs + .into_iter() + .map(|utx| (Arc::new(utx.tx.as_ref().into()), utx.last_seen)), + ) + } + pub(crate) fn derivation_index(&self, keychain: KeychainKind) -> Option { self.get_wallet().derivation_index(keychain) }