From f1414fb0d3fe0b9b8e377ef31d669b852fac9b96 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 2 Jun 2025 13:41:57 -0500 Subject: [PATCH] feat: expose tx_details --- bdk-ffi/src/types.rs | 29 ++++++++++++++++++++++++++++- bdk-ffi/src/wallet.rs | 7 +++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/bdk-ffi/src/types.rs b/bdk-ffi/src/types.rs index f6bf7d01..98d59909 100644 --- a/bdk-ffi/src/types.rs +++ b/bdk-ffi/src/types.rs @@ -49,7 +49,7 @@ pub enum KeychainKind { } /// Represents the observed position of some chain data. -#[derive(Debug, uniffi::Enum)] +#[derive(Debug, uniffi::Enum, Clone)] pub enum ChainPosition { /// The chain data is confirmed as it is anchored in the best chain by `A`. Confirmed { @@ -1094,3 +1094,30 @@ impl From for ChangeSet { } } } + +#[derive(uniffi::Record, Debug, Clone)] +pub struct TxDetails { + pub txid: Arc, + pub sent: Arc, + pub received: Arc, + pub fee: Option>, + pub fee_rate: Option, + pub balance_delta: i64, + pub chain_position: ChainPosition, + pub tx: Arc, +} + +impl From for TxDetails { + fn from(details: bdk_wallet::TxDetails) -> Self { + TxDetails { + txid: Arc::new(Txid(details.txid)), + sent: Arc::new(details.sent.into()), + received: Arc::new(details.received.into()), + fee: details.fee.map(|f| Arc::new(f.into())), + fee_rate: details.fee_rate.map(|fr| fr.to_sat_per_vb_ceil() as f32), + balance_delta: details.balance_delta.to_sat(), + chain_position: details.chain_position.into(), + tx: Arc::new(Transaction::from(details.tx.as_ref().clone())), + } + } +} diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index 40aa694b..cfdc8146 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -426,6 +426,13 @@ impl Wallet { pub fn latest_checkpoint(&self) -> BlockId { self.get_wallet().latest_checkpoint().block_id().into() } + + /// Get the [`TxDetails`] of a wallet transaction. + pub fn tx_details(&self, txid: Arc) -> Option { + self.get_wallet() + .tx_details(txid.0) + .map(|details| details.into()) + } } impl Wallet {