Skip to content

Commit 06b0f3a

Browse files
committed
feat: expose tx_details
1 parent 24986db commit 06b0f3a

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
@@ -48,7 +48,7 @@ pub enum KeychainKind {
4848
}
4949

5050
/// Represents the observed position of some chain data.
51-
#[derive(Debug, uniffi::Enum)]
51+
#[derive(Debug, uniffi::Enum, Clone)]
5252
pub enum ChainPosition {
5353
/// The chain data is confirmed as it is anchored in the best chain by `A`.
5454
Confirmed {
@@ -966,3 +966,30 @@ impl From<bdk_wallet::ChangeSet> for ChangeSet {
966966
}
967967
}
968968
}
969+
970+
#[derive(uniffi::Record, Debug, Clone)]
971+
pub struct TxDetails {
972+
pub txid: Arc<Txid>,
973+
pub sent: Arc<Amount>,
974+
pub received: Arc<Amount>,
975+
pub fee: Option<Arc<Amount>>,
976+
pub fee_rate: Option<f32>,
977+
pub balance_delta: i64,
978+
pub chain_position: ChainPosition,
979+
pub tx: Arc<Transaction>,
980+
}
981+
982+
impl From<bdk_wallet::TxDetails> for TxDetails {
983+
fn from(details: bdk_wallet::TxDetails) -> Self {
984+
TxDetails {
985+
txid: Arc::new(Txid(details.txid)),
986+
sent: Arc::new(details.sent.into()),
987+
received: Arc::new(details.received.into()),
988+
fee: details.fee.map(|f| Arc::new(f.into())),
989+
fee_rate: details.fee_rate.map(|fr| fr.to_sat_per_vb_ceil() as f32),
990+
balance_delta: details.balance_delta.to_sat(),
991+
chain_position: details.chain_position.into(),
992+
tx: Arc::new(Transaction::from(details.tx.as_ref().clone())),
993+
}
994+
}
995+
}

bdk-ffi/src/wallet.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,13 @@ impl Wallet {
418418
pub fn latest_checkpoint(&self) -> BlockId {
419419
self.get_wallet().latest_checkpoint().block_id().into()
420420
}
421+
422+
/// Get detailed information about a transaction affecting the wallet.
423+
pub fn tx_details(&self, txid: Arc<Txid>) -> Option<crate::types::TxDetails> {
424+
self.get_wallet()
425+
.tx_details(txid.0)
426+
.map(|details| details.into())
427+
}
421428
}
422429

423430
impl Wallet {

0 commit comments

Comments
 (0)