-
Notifications
You must be signed in to change notification settings - Fork 311
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
Add psbt_signer.rs example #744
Add psbt_signer.rs example #744
Conversation
@vladimirfomene please take a look and see if it works for you. |
0741362
to
470af23
Compare
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.
Tested ACK
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.
Tested ACK
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.
Concept ACK
It looks good to me, I think it should also be added to the Cargo.toml
in the examples section :)
469f9df
to
f320e3c
Compare
I incorporated the suggested changes and also added a list of any unconfirmed tx if the wallet balance is less than the desired 10k sats. Ready to re-review! 🙏 |
f320e3c
to
fa998de
Compare
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.
Looking great!
ACK fa998de
.add_recipient(return_address.script_pubkey(), 9_800) | ||
.enable_rbf() | ||
.fee_rate(FeeRate::from_sat_per_vb(1.0)); |
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.
I would use .drain_wallet().drain_to(return_address.script_pubkey())
to make sure a change is not created. It's also a chance to show that BDK can do more than "just send x to this address".
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.
That's a good idea but I do like having some coin selection and change going on, which I think will be how most new projects will be doing rather than sweeping all funds.
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.
Now that I think about it, the problem of receiving 10_000 and sending 9_800 is that you create a small change (~150 sats?), which will be uneconomical to spend (the fees for spending it are greater than the utxo value) - which BDK's coin selection won't pick, unless it's explicitly instructed to do so.
What this means is: after running this example many times, we might have the wallet full of these rather small utxos which we can't spend, and users will start to see some weird errors: for example, they might see that the balance is 10_000 (~70 utxos, ~150 each), but the coin selection will fail saying that there are not enough funds.
We can prevent this either by sweeping all funds every time, or by asking users to fill the wallet with 10_000 sats, but then spending only a smaller number, like 5_000
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, nevermind, the CS is smart enough that it picks 200 sats as fee, leaving no residue in the wallet :)
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.
Yes I guess also in my testing it used the change for fee and left an empty wallet balance. Yea for BDK coin selection! So we think it's ok to do it this way and not use drain_to
to ensure there's no change?
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.
I think it's fine :)
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 the end result should be the same because the leftover is lower than the dust threshold. I can go ahead and merge it like this, my suggestion was based on what I would have done personally, but it also looks good like this.
I was also about to suggest using the |
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.
ACK fa998de
Description
Adding a simple example of how to create a PSBT with a watch only wallet and then sign it with a signing wallet.
Notes to the reviewers
This example was inspired by a question from a user.
Changelog notice
none.
Checklists
All Submissions:
cargo fmt
andcargo clippy
before committingNew Features:
Bugfixes: