Skip to content

Commit d2b381c

Browse files
jnewberymeshcollider
authored andcommitted
[wallet] Refactor ProcessImport() to call ProcessImportLegacy()
This is almost entirely a move-only commit. Reviewer hint: use --color-moved=zebra for review.
1 parent 4cac0dd commit d2b381c

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

src/wallet/rpcdump.cpp

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -967,29 +967,6 @@ static std::string RecurseImportData(const CScript& script, ImportData& import_d
967967
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)
968968
{
969969
UniValue warnings(UniValue::VARR);
970-
return warnings;
971-
}
972-
973-
static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
974-
{
975-
UniValue warnings(UniValue::VARR);
976-
UniValue result(UniValue::VOBJ);
977-
978-
try {
979-
const bool internal = data.exists("internal") ? data["internal"].get_bool() : false;
980-
// Internal addresses should not have a label
981-
if (internal && data.exists("label")) {
982-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Internal addresses should not have a label");
983-
}
984-
const std::string& label = data.exists("label") ? data["label"].get_str() : "";
985-
986-
ImportData import_data;
987-
std::map<CKeyID, CPubKey> pubkey_map;
988-
std::map<CKeyID, CKey> privkey_map;
989-
std::set<CScript> script_pub_keys;
990-
bool have_solving_data;
991-
992-
warnings = ProcessImportLegacy(import_data, pubkey_map, privkey_map, script_pub_keys, have_solving_data, data);
993970

994971
// First ensure scriptPubKey has either a script or JSON with "address" string
995972
const UniValue& scriptPubKey = data["scriptPubKey"];
@@ -1004,13 +981,9 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
1004981
const std::string& witness_script_hex = data.exists("witnessscript") ? data["witnessscript"].get_str() : "";
1005982
const UniValue& pubKeys = data.exists("pubkeys") ? data["pubkeys"].get_array() : UniValue();
1006983
const UniValue& keys = data.exists("keys") ? data["keys"].get_array() : UniValue();
984+
const bool internal = data.exists("internal") ? data["internal"].get_bool() : false;
1007985
const bool watchOnly = data.exists("watchonly") ? data["watchonly"].get_bool() : false;
1008986

1009-
// If private keys are disabled, abort if private keys are being imported
1010-
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && !keys.isNull()) {
1011-
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import private keys to a wallet with private keys disabled");
1012-
}
1013-
1014987
// Generate the script and destination for the scriptPubKey provided
1015988
CScript script;
1016989
CTxDestination dest;
@@ -1127,6 +1100,35 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
11271100
}
11281101
}
11291102

1103+
return warnings;
1104+
}
1105+
1106+
static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
1107+
{
1108+
UniValue warnings(UniValue::VARR);
1109+
UniValue result(UniValue::VOBJ);
1110+
1111+
try {
1112+
const bool internal = data.exists("internal") ? data["internal"].get_bool() : false;
1113+
// Internal addresses should not have a label
1114+
if (internal && data.exists("label")) {
1115+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Internal addresses should not have a label");
1116+
}
1117+
const std::string& label = data.exists("label") ? data["label"].get_str() : "";
1118+
1119+
ImportData import_data;
1120+
std::map<CKeyID, CPubKey> pubkey_map;
1121+
std::map<CKeyID, CKey> privkey_map;
1122+
std::set<CScript> script_pub_keys;
1123+
bool have_solving_data;
1124+
1125+
warnings = ProcessImportLegacy(import_data, pubkey_map, privkey_map, script_pub_keys, have_solving_data, data);
1126+
1127+
// If private keys are disabled, abort if private keys are being imported
1128+
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && !privkey_map.empty()) {
1129+
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import private keys to a wallet with private keys disabled");
1130+
}
1131+
11301132
// Check whether we have any work to do
11311133
for (const CScript& script : script_pub_keys) {
11321134
if (::IsMine(*pwallet, script) & ISMINE_SPENDABLE) {

0 commit comments

Comments
 (0)