diff options
author | Andrew Chow <achow101-github@achow101.com> | 2019-01-25 14:38:34 -0500 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2019-01-31 14:29:28 -0500 |
commit | e6c58d3b014ab8ef5cca4be68764af4b79685fcb (patch) | |
tree | 9039a4523e7f7f6035271a849c0385e2e3c18dfe /src/wallet/rpcdump.cpp | |
parent | b5c5021b644731d14a6ef04961320a99466f035a (diff) |
Do not import private keys to wallets with private keys disabled
Diffstat (limited to 'src/wallet/rpcdump.cpp')
-rw-r--r-- | src/wallet/rpcdump.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index c65db8ac85..02cd0584df 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -133,6 +133,9 @@ UniValue importprivkey(const JSONRPCRequest& request) + HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false") ); + if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { + throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import private keys to a wallet with private keys disabled"); + } WalletRescanReserver reserver(pwallet); bool fRescan = true; @@ -617,6 +620,11 @@ UniValue importwallet(const JSONRPCRequest& request) } } file.close(); + // We now know whether we are importing private keys, so we can error if private keys are disabled + if (keys.size() > 0 && pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { + uiInterface.ShowProgress("", 100, false); // hide progress dialog in GUI + throw JSONRPCError(RPC_WALLET_ERROR, "Importing wallets is disabled when private keys are disabled"); + } double total = (double)(keys.size() + scripts.size()); double progress = 0; for (const auto& key_tuple : keys) { @@ -967,6 +975,11 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con const bool watchOnly = data.exists("watchonly") ? data["watchonly"].get_bool() : false; const std::string& label = data.exists("label") ? data["label"].get_str() : ""; + // If private keys are disabled, abort if private keys are being imported + if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && !keys.isNull()) { + throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import private keys to a wallet with private keys disabled"); + } + // Generate the script and destination for the scriptPubKey provided CScript script; CTxDestination dest; |