diff options
author | John Newbery <john@johnnewbery.com> | 2019-01-11 16:47:52 -0500 |
---|---|---|
committer | MeshCollider <dobsonsa68@gmail.com> | 2019-02-05 19:41:24 +1300 |
commit | d2b381cc91b2c4e74abe11e5bd66af647b70dafb (patch) | |
tree | 740ad8c0b6b43501b287762b6bd1a9f1a82b0a0c /src/wallet/rpcdump.cpp | |
parent | 4cac0ddd258bc82258ccc99568d02d3b2415339d (diff) |
[wallet] Refactor ProcessImport() to call ProcessImportLegacy()
This is almost entirely a move-only commit.
Reviewer hint: use --color-moved=zebra for review.
Diffstat (limited to 'src/wallet/rpcdump.cpp')
-rw-r--r-- | src/wallet/rpcdump.cpp | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 58dad78502..f91d545a3b 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -967,29 +967,6 @@ static std::string RecurseImportData(const CScript& script, ImportData& import_d static UniValue ProcessImportLegacy(ImportData& import_data, std::map<CKeyID, CPubKey>& pubkey_map, std::map<CKeyID, CKey>& privkey_map, std::set<CScript>& script_pub_keys, bool& have_solving_data, const UniValue& data) { UniValue warnings(UniValue::VARR); - return warnings; -} - -static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) -{ - UniValue warnings(UniValue::VARR); - UniValue result(UniValue::VOBJ); - - try { - const bool internal = data.exists("internal") ? data["internal"].get_bool() : false; - // Internal addresses should not have a label - if (internal && data.exists("label")) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Internal addresses should not have a label"); - } - const std::string& label = data.exists("label") ? data["label"].get_str() : ""; - - ImportData import_data; - std::map<CKeyID, CPubKey> pubkey_map; - std::map<CKeyID, CKey> privkey_map; - std::set<CScript> script_pub_keys; - bool have_solving_data; - - warnings = ProcessImportLegacy(import_data, pubkey_map, privkey_map, script_pub_keys, have_solving_data, data); // First ensure scriptPubKey has either a script or JSON with "address" string const UniValue& scriptPubKey = data["scriptPubKey"]; @@ -1004,13 +981,9 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con const std::string& witness_script_hex = data.exists("witnessscript") ? data["witnessscript"].get_str() : ""; const UniValue& pubKeys = data.exists("pubkeys") ? data["pubkeys"].get_array() : UniValue(); const UniValue& keys = data.exists("keys") ? data["keys"].get_array() : UniValue(); + const bool internal = data.exists("internal") ? data["internal"].get_bool() : false; const bool watchOnly = data.exists("watchonly") ? data["watchonly"].get_bool() : false; - // 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; @@ -1127,6 +1100,35 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con } } + return warnings; +} + +static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) +{ + UniValue warnings(UniValue::VARR); + UniValue result(UniValue::VOBJ); + + try { + const bool internal = data.exists("internal") ? data["internal"].get_bool() : false; + // Internal addresses should not have a label + if (internal && data.exists("label")) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Internal addresses should not have a label"); + } + const std::string& label = data.exists("label") ? data["label"].get_str() : ""; + + ImportData import_data; + std::map<CKeyID, CPubKey> pubkey_map; + std::map<CKeyID, CKey> privkey_map; + std::set<CScript> script_pub_keys; + bool have_solving_data; + + warnings = ProcessImportLegacy(import_data, pubkey_map, privkey_map, script_pub_keys, have_solving_data, data); + + // If private keys are disabled, abort if private keys are being imported + if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && !privkey_map.empty()) { + throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import private keys to a wallet with private keys disabled"); + } + // Check whether we have any work to do for (const CScript& script : script_pub_keys) { if (::IsMine(*pwallet, script) & ISMINE_SPENDABLE) { |