Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 1,513 Lines • ▼ Show 20 Lines | try { | ||||
"key for this address or script (\"" + | "key for this address or script (\"" + | ||||
HexStr(script.begin(), script.end()) + | HexStr(script.begin(), script.end()) + | ||||
"\")"); | "\")"); | ||||
} | } | ||||
} | } | ||||
// All good, time to import | // All good, time to import | ||||
pwallet->MarkDirty(); | pwallet->MarkDirty(); | ||||
for (const auto &entry : import_data.import_scripts) { | if (!pwallet->ImportScripts(import_data.import_scripts)) { | ||||
if (!pwallet->HaveCScript(CScriptID(entry)) && | |||||
!pwallet->AddCScript(entry)) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error adding script to wallet"); | "Error adding script to wallet"); | ||||
} | } | ||||
if (!pwallet->ImportPrivKeys(privkey_map, timestamp)) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet"); | |||||
} | } | ||||
for (const auto &entry : privkey_map) { | if (!pwallet->ImportPubKeys(ordered_pubkeys, pubkey_map, | ||||
const CKey &key = entry.second; | import_data.key_origins, add_keypool, | ||||
CPubKey pubkey = key.GetPubKey(); | internal, timestamp)) { | ||||
const CKeyID &id = entry.first; | |||||
assert(key.VerifyPubKey(pubkey)); | |||||
pwallet->mapKeyMetadata[id].nCreateTime = timestamp; | |||||
// If the private key is not present in the wallet, insert it. | |||||
if (!pwallet->HaveKey(id) && !pwallet->AddKeyPubKey(key, pubkey)) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Error adding key to wallet"); | |||||
} | |||||
pwallet->UpdateTimeFirstKey(timestamp); | |||||
} | |||||
for (const auto &entry : import_data.key_origins) { | |||||
pwallet->AddKeyOrigin(entry.second.first, entry.second.second); | |||||
} | |||||
for (const CKeyID &id : ordered_pubkeys) { | |||||
auto entry = pubkey_map.find(id); | |||||
if (entry == pubkey_map.end()) { | |||||
continue; | |||||
} | |||||
const CPubKey &pubkey = entry->second; | |||||
CPubKey temp; | |||||
if (!pwallet->GetPubKey(id, temp) && | |||||
!pwallet->AddWatchOnly(GetScriptForRawPubKey(pubkey), | |||||
timestamp)) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error adding address to wallet"); | "Error adding address to wallet"); | ||||
} | } | ||||
pwallet->mapKeyMetadata[id].nCreateTime = timestamp; | if (!pwallet->ImportScriptPubKeys(label, script_pub_keys, | ||||
have_solving_data, internal, | |||||
// Add to keypool only works with pubkeys | timestamp)) { | ||||
if (add_keypool) { | |||||
pwallet->AddKeypoolPubkey(pubkey, internal); | |||||
} | |||||
} | |||||
for (const CScript &script : script_pub_keys) { | |||||
if (!have_solving_data || !::IsMine(*pwallet, script)) { | |||||
// Always call AddWatchOnly for non-solvable watch-only, so that | |||||
// watch timestamp gets updated | |||||
if (!pwallet->AddWatchOnly(script, timestamp)) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error adding address to wallet"); | "Error adding address to wallet"); | ||||
} | } | ||||
} | |||||
CTxDestination dest; | |||||
ExtractDestination(script, dest); | |||||
if (!internal && IsValidDestination(dest)) { | |||||
pwallet->SetAddressBook(dest, label, "receive"); | |||||
} | |||||
} | |||||
result.pushKV("success", UniValue(true)); | result.pushKV("success", UniValue(true)); | ||||
} catch (const UniValue &e) { | } catch (const UniValue &e) { | ||||
result.pushKV("success", UniValue(false)); | result.pushKV("success", UniValue(false)); | ||||
result.pushKV("error", e); | result.pushKV("error", e); | ||||
} catch (...) { | } catch (...) { | ||||
result.pushKV("success", UniValue(false)); | result.pushKV("success", UniValue(false)); | ||||
result.pushKV("error", | result.pushKV("error", | ||||
▲ Show 20 Lines • Show All 334 Lines • Show Last 20 Lines |