-
Notifications
You must be signed in to change notification settings - Fork 385
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
Create and Sign PSBTs for spendable outputs #2286
Create and Sign PSBTs for spendable outputs #2286
Conversation
f804d60
to
a079ed4
Compare
I'm not really a fan of pushing every spend of this through the PSBT flow, but having a PSBT flow option is definitely good. If we're gonna do this though we should really support using the PSBT to provide the outputs + change output, in addition to excess inputs. Really maybe we should return a set of PSBT inputs which the user can munge into a PSBT and then we can sign it, I think (or maybe we just need a method to convert a descriptor to a PSBT input)? I admit I'm not super farmiliar with "normal" PSBT flows. |
PSBTs have kinda been bastardized. No one really passes around the individual pieces, normally it is just passing around whole PSBTs with the information you need in them and then merging PSBTs together until you get the transaction you want. PSBTv2 fixes this but hasn't really seen any adoption. |
Yeah I think that could be a good idea, will try and implement that. |
Hmm, this actually is more complicated than expected, most of it isn't too hard but we need to handle the case where the user provides a PSBT with an input (or inputs) that do not have the previous utxo available, if we don't have that information we can't calculate the total input value, change amt, fee rate, etc. We also will be unable to |
Grr, I'd really expect those kinds of utilities to be either in BDK or in rust-bitcoin - we should be able to return the descriptors convert them to psbt inputs, then call one bdk function which munges it all together and applies the right fee...at a minimum I'd like to have such a utility available (that converts descriptors into psbt inputs) and then build something that turns those into a transactions for users and try to upstream it to rust-bitcoin/BDK. That said, we can probably just not support not having the input transaction in the PSBT. |
a079ed4
to
c7ea1ef
Compare
Added a helper function for creating a psbt input. Still think the functions I already had will be useful for the majority of users. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM, I think, its somewhat unrelated to this specific PR, but we really need to move to an error enum here and not just return Err(())
, if you want to do it here I'd appreciate it but if not that's okay. Either way lets get another reviewer.
SpendableOutputDescriptor::StaticOutput { output, .. } => { | ||
// Is a standard P2WPKH, no need for witness script | ||
bitcoin::psbt::Input { | ||
witness_utxo: Some(output.clone()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh these don't have outpoints? Ugh, oh well, still probably useful just annoying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah PSBTv0 has a lot of weird stuff like that
c7ea1ef
to
04ceec8
Compare
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #2286 +/- ##
==========================================
- Coverage 90.94% 90.92% -0.02%
==========================================
Files 104 104
Lines 52760 52799 +39
Branches 52760 52799 +39
==========================================
+ Hits 47983 48008 +25
- Misses 4777 4791 +14
☔ View full report in Codecov by Sentry. |
/// Returns `Err(())` if the output value is greater than the input value minus required fee, | ||
/// if a descriptor was duplicated, or if an output descriptor `script_pubkey` | ||
/// does not match the one we can spend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be cool to enum
erate these.
04ceec8
to
42fbf56
Compare
CI is failing but LGTM otherwise. |
42fbf56
to
334aa20
Compare
One more on the anchors build:
|
334aa20
to
8c0479a
Compare
Closes #2285
The goal here is to be able to better batch spendable outputs with other transactions. This should let you create and sign PSBTs according to your spendable outputs and only needing the KeyManager for signing.