Skip to content

feat: apply_unconfirmed_txs on wallet #704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bdk-ffi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnconfirmedTx> unconfirmed_txs);
};

typedef dictionary UnconfirmedTx;

interface Update {};

interface Policy {
Expand Down
1 change: 1 addition & 0 deletions bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions bdk-ffi/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,11 @@ impl From<BdkTx> 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go with the proc macros proposed above, a little bit of API docs to describe this type might be nice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a UnconfirmedTx type, similar to how we needed to create a SentAndReceivedValues type instead of returning a tuple. Totally open to naming it something different, but just needed a type instead of a tuple.

Since it's not a 1-for-1 of a type I didn't add docs (but would have liked to! just wasn't sure if/how to do it best since its not 1-for-1), what are you thinking for a little bit of API docs? Here's the method docs https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.Wallet.html#method.apply_unconfirmed_txs let me know what you think and I'll def add!

Copy link
Member

@thunderbiscuit thunderbiscuit Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like this?

/// 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect, updated

pub tx: Arc<Transaction>,
pub last_seen: u64,
}
10 changes: 9 additions & 1 deletion bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -130,6 +130,14 @@ impl Wallet {
.map_err(CannotConnectError::from)
}

pub fn apply_unconfirmed_txs(&self, unconfirmed_txs: Vec<UnconfirmedTx>) {
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<u32> {
self.get_wallet().derivation_index(keychain)
}
Expand Down
Loading