Skip to content

Commit 0997019

Browse files
committed
Disallow sendtoaddress and sendmany when private keys disabled
1 parent 3c9d9d2 commit 0997019

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,12 @@ UniValue SendMoney(CWallet* const pwallet, const CCoinControl &coin_control, std
400400
{
401401
EnsureWalletIsUnlocked(pwallet);
402402

403+
// This function is only used by sendtoaddress and sendmany.
404+
// This should always try to sign, if we don't have private keys, don't try to do anything here.
405+
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
406+
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Private keys are disabled for this wallet");
407+
}
408+
403409
// Shuffle recipient list
404410
std::shuffle(recipients.begin(), recipients.end(), FastRandomContext());
405411

@@ -409,7 +415,7 @@ UniValue SendMoney(CWallet* const pwallet, const CCoinControl &coin_control, std
409415
bilingual_str error;
410416
CTransactionRef tx;
411417
FeeCalculation fee_calc_out;
412-
bool fCreated = pwallet->CreateTransaction(recipients, tx, nFeeRequired, nChangePosRet, error, coin_control, fee_calc_out, !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));
418+
const bool fCreated = pwallet->CreateTransaction(recipients, tx, nFeeRequired, nChangePosRet, error, coin_control, fee_calc_out, true);
413419
if (!fCreated) {
414420
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, error.original);
415421
}

0 commit comments

Comments
 (0)