Since sendtoaddress and sendmany (which use the SendMoney function) create and commit a transaction, they should not do anything when the wallet does not have private keys. Otherwise a valid transaction cannot be made.
Fixes #21104
ACK modulo test coverage. Here's a regression test commit that fails on master and passes with this patch https://github.com/jonatack/bitcoin/commit/15a9bcc75d5447d85b614e2e5595d7a9a8b423a6
414 | @@ -409,7 +415,7 @@ UniValue SendMoney(CWallet* const pwallet, const CCoinControl &coin_control, std 415 | bilingual_str error; 416 | CTransactionRef tx; 417 | FeeCalculation fee_calc_out; 418 | - bool fCreated = pwallet->CreateTransaction(recipients, tx, nFeeRequired, nChangePosRet, error, coin_control, fee_calc_out, !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); 419 | + bool fCreated = pwallet->CreateTransaction(recipients, tx, nFeeRequired, nChangePosRet, error, coin_control, fee_calc_out, true);
nit while touching this line, feel free to ignore
const bool fCreated = pwallet->CreateTransaction(recipients, tx, nFeeRequired, nChangePosRet, error, coin_control, fee_calc_out, true);
Done
ACK 6bfbc97d716faad38c87603ac6049d222236d623
utACK 6bfbc97d716faad38c87603ac6049d222236d623
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
ACK 6bfbc97d716faad38c87603ac6049d222236d623. "Error: Private keys are disabled for this wallet" is definitely a better error message than "Insufficient funds" here. Hopefully change of error code from -6 to -4 doesn't break any software using Bitcoin JSON-RPC API.
You forgot to fix send?
Currently prints error message: 'Transaction needs a change address, but we can't generate it. Please call keypoolrefill first.'.
You forgot to fix
send?Currently prints
error message: 'Transaction needs a change address, but we can't generate it. Please call keypoolrefill first.'.
No, that's intended and expected if there are no change addresses. send is supposed to work when private keys are disabled; in that case, it will create and output a psbt.
Ah, ok thx.
Also, tagged for 0.21.1 backport. Let me know if this shouldn't be backported.
Backported in #20901
Milestone
0.21.1