Skip to content

Commit cc02be0

Browse files
committed
feat: expose tx_details
1 parent 1a5545b commit cc02be0

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

bdk-ffi/src/types.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub enum KeychainKind {
4949
}
5050

5151
/// Represents the observed position of some chain data.
52-
#[derive(Debug, uniffi::Enum)]
52+
#[derive(Debug, uniffi::Enum, Clone)]
5353
pub enum ChainPosition {
5454
/// The chain data is confirmed as it is anchored in the best chain by `A`.
5555
Confirmed {
@@ -1094,3 +1094,30 @@ impl From<bdk_wallet::ChangeSet> for ChangeSet {
10941094
}
10951095
}
10961096
}
1097+
1098+
#[derive(uniffi::Record, Debug, Clone)]
1099+
pub struct TxDetails {
1100+
pub txid: Arc<Txid>,
1101+
pub sent: Arc<Amount>,
1102+
pub received: Arc<Amount>,
1103+
pub fee: Option<Arc<Amount>>,
1104+
pub fee_rate: Option<f32>,
1105+
pub balance_delta: i64,
1106+
pub chain_position: ChainPosition,
1107+
pub tx: Arc<Transaction>,
1108+
}
1109+
1110+
impl From<bdk_wallet::TxDetails> for TxDetails {
1111+
fn from(details: bdk_wallet::TxDetails) -> Self {
1112+
TxDetails {
1113+
txid: Arc::new(Txid(details.txid)),
1114+
sent: Arc::new(details.sent.into()),
1115+
received: Arc::new(details.received.into()),
1116+
fee: details.fee.map(|f| Arc::new(f.into())),
1117+
fee_rate: details.fee_rate.map(|fr| fr.to_sat_per_vb_ceil() as f32),
1118+
balance_delta: details.balance_delta.to_sat(),
1119+
chain_position: details.chain_position.into(),
1120+
tx: Arc::new(Transaction::from(details.tx.as_ref().clone())),
1121+
}
1122+
}
1123+
}

bdk-ffi/src/wallet.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,13 @@ impl Wallet {
426426
pub fn latest_checkpoint(&self) -> BlockId {
427427
self.get_wallet().latest_checkpoint().block_id().into()
428428
}
429+
430+
/// Get the [`TxDetails`] of a wallet transaction.
431+
pub fn tx_details(&self, txid: Arc<Txid>) -> Option<crate::types::TxDetails> {
432+
self.get_wallet()
433+
.tx_details(txid.0)
434+
.map(|details| details.into())
435+
}
429436
}
430437

431438
impl Wallet {

0 commit comments

Comments
 (0)