Skip to content
Open
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
23 changes: 19 additions & 4 deletions bdk-ffi/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::bitcoin::{
Address, Amount, BlockHash, DescriptorId, HashableOutPoint, OutPoint, Script, Transaction,
TxOut, Txid,
Address, Amount, BlockHash, DescriptorId, FeeRate, HashableOutPoint, OutPoint, Script,
Transaction, TxOut, Txid,
};
use crate::descriptor::Descriptor;
use crate::error::{CreateTxError, RequestBuilderError};
Expand Down Expand Up @@ -1305,15 +1305,30 @@ impl From<bdk_wallet::ChangeSet> for ChangeSet {
}
}

/// Details about a transaction affecting the wallet (relevant and canonical).
#[derive(uniffi::Record, Debug, Clone)]
pub struct TxDetails {
/// The transaction id.
pub txid: Arc<Txid>,
/// The sum of the transaction input amounts that spend from previous outputs tracked by this
/// wallet.
pub sent: Arc<Amount>,
/// The sum of the transaction outputs that send to script pubkeys tracked by this wallet.
pub received: Arc<Amount>,
/// The fee paid for the transaction. Note that to calculate the fee for a transaction with
/// inputs not owned by this wallet you must manually insert the TxOut(s) into the tx graph
/// using the insert_txout function. If those are not available, the field will be `None`.
pub fee: Option<Arc<Amount>>,
pub fee_rate: Option<f32>,
/// The fee rate paid for the transaction. Note that to calculate the fee rate for a
/// transaction with inputs not owned by this wallet you must manually insert the TxOut(s) into
/// the tx graph using the insert_txout function. If those are not available, the field will be
/// `None`.
pub fee_rate: Option<Arc<FeeRate>>,
/// The net effect of the transaction on the balance of the wallet.
pub balance_delta: i64,
/// The position of the transaction in the chain.
pub chain_position: ChainPosition,
/// The complete `Transaction`.
pub tx: Arc<Transaction>,
}

Expand All @@ -1324,7 +1339,7 @@ impl From<bdk_wallet::TxDetails> for TxDetails {
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),
fee_rate: details.fee_rate.map(|fr| Arc::new(fr.into())),
balance_delta: details.balance_delta.to_sat(),
chain_position: details.chain_position.into(),
tx: Arc::new(Transaction::from(details.tx.as_ref().clone())),
Expand Down
Loading