-
Notifications
You must be signed in to change notification settings - Fork 68
Description
Since the purpose of the bdk_wallet crate is to provide useful/opinionated ways to perform standard wallet tasks, it feels to me like a simple-to-use "get me all important—nicely bundled if you don't mind—info about this wallet's transactions" method is missing from our API.
The data is there, but currently requires multiple round trips to bundle it all together, yet that data is what all user interfaces will need for one of the most common use cases, a transactions history screen. Note that this type of data object is what we previously had with the TransactionDetails struct.
The exact data that might be useful here is up for discussion, but let us assume a structure like this one would suffice for most use cases:
pub struct TxDetails<'a> {
pub received: u64,
pub sent: u64,
pub fee: u64,
pub fee_rate: FeeRate,
pub txid: Txid,
pub chain_position: ChainPosition<&'a ConfirmationTimeHeightAnchor>,
}The current way to bundle this up ready for UI consumption is something like this:
let transactions = wallet.transactions();
let tx_details: Vec<TxDetails> = transactions.map(|tx| {
let (sent, received) = wallet.sent_and_received(tx.tx_node.tx);
let fee = wallet.calculate_fee(tx.tx_node.tx).unwrap();
let fee_rate = wallet.calculate_fee_rate(tx.tx_node.tx).unwrap();
let txid = tx.tx_node.txid;
let chain_position = tx.chain_position.clone();
TxDetails {
received,
sent,
fee,
fee_rate,
txid,
chain_position,
}
})
.collect();
for tx in &tx_details {
let ui_details = format!(
"Received: {}\nSent: {}\nTotal fee: {} sat\nFee rate: {} sat/vbyte\nTxid: {}\nChain position: {:?}\n",
tx.received,
tx.sent,
tx.fee,
tx.fee_rate.to_sat_per_vb_ceil(),
tx.txid,
tx.chain_position
);
println!("{}", ui_details);
}Notice the individual calls to the wallet for for fee, fee_rate, and sent_and_received values, as well as the pulling out of the txid. It gets even more unruly if you want to build fields like confirmed: Boolean, confirmation_block: Option<u64>, confirmation_timestamp: Option<u64> instead of using the ChainPosition type, etc.
I propose we add a method (name tbd, but maybe something like get_txs_details(), which would take care of building such a data structure for the user, instead of making all users develop their utility method on top of wallet.transactions().
Metadata
Metadata
Assignees
Labels
Type
Projects
Status