Skip to content

Commit 52ec4c6

Browse files
committed
Merge #16144: wallet: do not encrypt wallets with disabled private keys
7860c98 wallet: do not encrypt wallets with disabled private keys (whythat) Pull request description: Fix for #15635. Throw an `RPC_WALLET_ENCRYPTION_FAILED` error when attempting to encrypt wallet with disabled private keys. Changed `test/function/wallet_createwallet.py` to test new behavior. ACKs for commit 7860c9: achow101: utACK 7860c98 meshcollider: utACK bitcoin/bitcoin@7860c98 Tree-SHA512: d0cc40efd303a00d0b4d3cb2de59d8d2d7dd35647e7f3fe9d4a8986589499c1f567c5780c83a129e1ab8dbe601279c459c6ebce3b48b1d81d47a28616ef4a369
2 parents 5d37c1b + 7860c98 commit 52ec4c6

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,10 @@ static UniValue encryptwallet(const JSONRPCRequest& request)
21242124
auto locked_chain = pwallet->chain().lock();
21252125
LOCK(pwallet->cs_wallet);
21262126

2127+
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
2128+
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: wallet does not contain private keys, nothing to encrypt.");
2129+
}
2130+
21272131
if (pwallet->IsCrypted()) {
21282132
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called.");
21292133
}

test/functional/wallet_createwallet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def run_test(self):
9292
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w5.getnewaddress)
9393
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w5.getrawchangeaddress)
9494
# Encrypt the wallet
95-
w5.encryptwallet('pass')
95+
assert_raises_rpc_error(-16, "Error: wallet does not contain private keys, nothing to encrypt.", w5.encryptwallet, 'pass')
9696
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w5.getnewaddress)
9797
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w5.getrawchangeaddress)
9898

0 commit comments

Comments
 (0)