-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider returning TransactionDetails from TxBuilder finish() method #179
Comments
I would concur with this. Im working on a Swift wallet prototype and absolutely need this functionality to make the user aware of how much they are transferring with. |
We definitely need this functionality in our app as well. Any timeline on adding the details to finish? |
I'm looking into it now, and I think the first step of this is to decide what we need to expose at the bindings level. For example our current // bindings
pub struct TransactionDetails {
pub fee: Option<u64>,
pub received: u64,
pub sent: u64,
pub txid: String,
}
// Rust BDK
pub struct TransactionDetails {
pub transaction: Option<Transaction>,
pub txid: Txid,
pub received: u64,
pub sent: u64,
pub fee: Option<u64>,
pub confirmation_time: Option<BlockTime>,
} This These are good API discussions, so I just want to bring @notmandatory into this. |
@thunderbiscuit you are asking the right question, it's a bit tedious but not hard to expose the whole |
Some more details on why Transaction details are needed in https://github.com/bitcoindevkit/bdk-swift/issues/27, which is to show received to / sent to information for transactions inputs/outputs. |
Yup, I posted that a bit back. I ended up closing it today because I felt like maybe it should be in this repo, but I also noticed that there was a deprecation to vout's At any rate, with that issue I was trying to get at the send/receive address's from the already broadcasted transaction. I understand that sometimes It can be hard to reason about those, but it just seems like fundamental data to be included in the transaction data. This would at least allow the consumer to parse those and display. |
@thunderbiscuit yep, we need it primarily for calculating fees prior to broadcasting |
@ismyhc I added this as a discussion point for the next bindings dev call. Looking for the addresses in this case will be more about exposing the underlying rust-bitcoin library. I'm looking into it right now and here is how I think one would go about it:
pub struct Transaction {
pub version: i32,
pub lock_time: u32,
pub input: Vec<TxIn>,
pub output: Vec<TxOut>,
}
pub struct TxOut {
pub value: u64,
pub script_pubkey: Script,
}
@allisonmoyer I'll open a draft PR adding just the feerate to the |
As per bitcoindevkit/bdk#524, the fee rate cannot currently be calculated before the transaction is signed (because the tx doesn't have witness data at this point). This means we won't be able to return it on the |
Returning it from |
Yep we'll be able to have a txid with it for sure. In fact it will probably be just an extra method on the PartiallySignedBitcoinTransaction struct. My only question at the moment is how to handle the situation where the psbt is not yet signed. |
I created a draft PR to add some new functions to |
The draft looks great to me! |
ab41679 Add fee_amount() and fee_rate() functions to PsbtUtils trait (Steve Myers) Pull request description: ### Description The purpose of the PR is to provide a more convenient way to calculate the transaction fee amount and fee rate for a PSBT. This PR adds `fee_amount` and `fee_rate` functions to the existing `PsbtUtils` trait and implements them for `PartiallySignedBitcoinTransaction`. The `fee_rate` value is only valid if the PSBT it is called on is fully signed and finalized. See related discussion: bitcoindevkit/bdk-ffi#179 ### Changelog Added - PsbtUtils.fee_amount(), calculates the PSBT total transaction fee amount in Sats. - PsbtUtils.fee_rate(), calculates the PSBT FeeRate, the value is only accurate AFTER the PSBT is finalized. ### Notes to the reviewers Ideally I'd like `fee_rate` to return an `Option` and return `None` if the PSBT isn't finalized. But I'm not quite sure how to determine if a PSBT is finalized without having a `Wallet` and running it through the finalize code first. Or there might be a way to fill in missing signatures with properly sized fake data prior to calculating the fee rate. For now I think it's enough to do this simple approach with usage warning in the rust docs. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### New Features: * [x] I've added tests for the new feature * [x] I've added docs for the new feature ACKs for top commit: afilini: ACK ab41679 Tree-SHA512: 5386109c9ffcf63160f18b4c51eb2c582f4121b669c7276aaba489d186cf9b97343d46f887469b1407ccd7a24448b5e7aee4c6832d86768239b21f4e68054a0f
I screwed up and didn't make the new psbt module in bdk public , so we'll need these three PRs before we can get transaction details and fee rates on finalized PSBTs:
I've moved this to release 0.11.0 so we don't hold up (late) release 0.10.0. |
In case anyone is finding this issue through search, as of #307 you'll be able to get addresses for all inputs and outputs that were used in a transaction through pulling the list of transactions the wallet knows about using |
The
finish()
method on the `TxBuilder on the Rust side of BDK has the following signature:Whereas the
finish()
method in the bindings only returns aPartiallySignedBitcoinTransaction
.This, among other things, makes it impossible to get the total fees that the transaction will require and display them to the user before broadcasting (the
broadcast()
method returns theTransactionDetails
we want).cc @ismyhc
The text was updated successfully, but these errors were encountered: