Skip to content

Commit

Permalink
Merge bitcoin#16144: wallet: do not encrypt wallets with disabled pri…
Browse files Browse the repository at this point in the history
…vate keys

7860c98 wallet: do not encrypt wallets with disabled private keys (whythat)

Pull request description:

  Fix for bitcoin#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@7860c98

Tree-SHA512: d0cc40efd303a00d0b4d3cb2de59d8d2d7dd35647e7f3fe9d4a8986589499c1f567c5780c83a129e1ab8dbe601279c459c6ebce3b48b1d81d47a28616ef4a369
  • Loading branch information
laanwj committed Jun 5, 2019
2 parents 5d37c1b + 7860c98 commit 52ec4c6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/wallet/rpcwallet.cpp
Expand Up @@ -2124,6 +2124,10 @@ static UniValue encryptwallet(const JSONRPCRequest& request)
auto locked_chain = pwallet->chain().lock();
LOCK(pwallet->cs_wallet);

if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: wallet does not contain private keys, nothing to encrypt.");
}

if (pwallet->IsCrypted()) {
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called.");
}
Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_createwallet.py
Expand Up @@ -92,7 +92,7 @@ def run_test(self):
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w5.getnewaddress)
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w5.getrawchangeaddress)
# Encrypt the wallet
w5.encryptwallet('pass')
assert_raises_rpc_error(-16, "Error: wallet does not contain private keys, nothing to encrypt.", w5.encryptwallet, 'pass')
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w5.getnewaddress)
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w5.getrawchangeaddress)

Expand Down

0 comments on commit 52ec4c6

Please sign in to comment.