Closed icota closed 1 year ago
Good idea, rather than complicating the broadcast
command with the extra options finalize
has I'd prefer to give a nicer error if someone tries to broadcast a non-finalized psbt.
bdk-cli wallet help finalize_psbt
bdk-cli-wallet-finalize_psbt 0.4.0
Finalizes a PSBT
USAGE:
bdk-cli wallet finalize_psbt [OPTIONS] --psbt <BASE64_PSBT>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
--psbt <BASE64_PSBT> Sets the PSBT to finalize
--assume_height <HEIGHT> Assume the blockchain has reached a specific height
--trust_witness_utxo <WITNESS> Whether the signer should trust the witness_utxo, if the non_witness_utxo hasn’t been provided
@notmandatory TBH before I opened this issue I didn't even realise there is a finalize_psbt
(with the options) in the CLI. In that case it's obviously better to improve the error - I've changed the title to reflect that.
Do the changes in https://github.com/bitcoindevkit/bdk/pull/621 solve your issue if we bring that into bdk-cli?
I don't see how? My issue came about from trying to broadcast an unfinalized transaction and getting confused by the error message.
Are you saying changes in https://github.com/bitcoindevkit/bdk/pull/621 would make it less likely for the user to forget to finalize?
Yes my thinking is for the sign
command to always finalize
(if possible), and then add a --no-finalize
for those who don't want to finalize for some reason. The result of sign already lets the user know if the PSBT is in fact finalized. The problem with doing an automatic finalize
on broadcast
(and then throwing an error if that fails) is the user would have to repeat the signing options they may have already used when signing the PSBT.
My flow was from outside (hardware device) coming in (to bdk-cli
).
But also I agree with what you say @notmandatory, in all cases broadcast
shouldn't finalize
. That's why I changed the title to merely suggest to the user to finalize.
non-mandatory-script-verify-flag (Witness program hash mismatch)
was way too cryptic for me.
Would be great to say something like "WARNING: trying to broadcast a non-finalized transaction" beforehand.
When using the command broadcast --psbt I get the following error, I don't know how to solve it, any idea. [2022-07-20T15:04:04Z ERROR bdk_cli] Electrum(Protocol(String("sendrawtransaction RPC error: {\"code\":-26,\"message\":\"non-mandatory-script-verify-flag (Witness program hash mismatch)\"}")))
@w2k31984 It seems you might of forgot to sign the psbt. You need to sign the PSBT using the
sign --psbt $UNSIGNED_PSBT
command.
Creating a transaction usingbdk-cli
looks something like this...
create_tx --to addressgoeshere:amountSats
sign --psbt $UNSIGNED_PSBT
brodcast --psbt $SIGNED
bdk-cli wallet -w mywalletName --descriptor "wpkh($XPRV_GoesHere/84'/0'/0'/0/*)" broadcast --psbt $SIGNED_PSBT
.One final note: The instance when I got the error message seen below was when I did not sign the PSBT
ERROR bdk_cli] Electrum(Protocol(String("sendrawtransaction RPC error: {\"code\":-26,\"message\":\"non-mandatory-script-verify-flag (Witness program hash mismatch)\"}")))
When using the command broadcast --psbt I get the following error, I don't know how to solve it, any idea. [2022-07-20T15:04:04Z ERROR bdk_cli] Electrum(Protocol(String("sendrawtransaction RPC error: {"code":-26,"message":"non-mandatory-script-verify-flag (Witness program hash mismatch)"}")))
Hmm.. This seems like a possible improvement.. The "Witness program hash moissmatch" is not really enlightening.. Its should say something more friendly than that..
Putting this down in my todos..
This one is up for grab btw.. If we don't get anyone on this in few weeks I will take it up..
@notmandatory I am adding back the good first issue for this one in case someone wanna try this on. This doesn't seem like a pressing need but surely a nice thing to have..
When trying to
broadcast
a PSBT such asthe transaction gets (rightfully) rejected by the network
due to not being
finalize
d.To avoid user confusion I think the user should be either instructed to finalize the PSBT or have this be done automatically (which would be in line with what other wallets are doing).