Skip to content

Commit 7860c98

Browse files
committed
wallet: do not encrypt wallets with disabled private keys
1 parent d3a1c25 commit 7860c98

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)