Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 754 Lines • ▼ Show 20 Lines | bool fGood = true; | ||||
const CKey &key = std::get<0>(key_tuple); | const CKey &key = std::get<0>(key_tuple); | ||||
int64_t time = std::get<1>(key_tuple); | int64_t time = std::get<1>(key_tuple); | ||||
bool has_label = std::get<2>(key_tuple); | bool has_label = std::get<2>(key_tuple); | ||||
std::string label = std::get<3>(key_tuple); | std::string label = std::get<3>(key_tuple); | ||||
CPubKey pubkey = key.GetPubKey(); | CPubKey pubkey = key.GetPubKey(); | ||||
assert(key.VerifyPubKey(pubkey)); | assert(key.VerifyPubKey(pubkey)); | ||||
CKeyID keyid = pubkey.GetID(); | CKeyID keyid = pubkey.GetID(); | ||||
if (pwallet->HaveKey(keyid)) { | |||||
pwallet->WalletLogPrintf( | |||||
"Skipping import of %s (key already present)\n", | |||||
EncodeDestination(PKHash(keyid), config)); | |||||
continue; | |||||
} | |||||
pwallet->WalletLogPrintf("Importing %s...\n", | pwallet->WalletLogPrintf("Importing %s...\n", | ||||
EncodeDestination(PKHash(keyid), config)); | EncodeDestination(PKHash(keyid), config)); | ||||
if (!pwallet->AddKeyPubKey(key, pubkey)) { | |||||
if (!pwallet->ImportPrivKeys({{keyid, key}}, time)) { | |||||
pwallet->WalletLogPrintf( | |||||
"Error importing key for %s\n", | |||||
EncodeDestination(PKHash(keyid), config)); | |||||
fGood = false; | fGood = false; | ||||
continue; | continue; | ||||
} | } | ||||
pwallet->mapKeyMetadata[keyid].nCreateTime = time; | |||||
if (has_label) { | if (has_label) { | ||||
pwallet->SetAddressBook(PKHash(keyid), label, "receive"); | pwallet->SetAddressBook(PKHash(keyid), label, "receive"); | ||||
} | } | ||||
nTimeBegin = std::min(nTimeBegin, time); | nTimeBegin = std::min(nTimeBegin, time); | ||||
progress++; | progress++; | ||||
} | } | ||||
for (const auto &script_pair : scripts) { | for (const auto &script_pair : scripts) { | ||||
pwallet->chain().showProgress( | pwallet->chain().showProgress( | ||||
"", | "", | ||||
std::max(50, std::min<int>(75, 100 * progress / total) + 50), | std::max(50, std::min<int>(75, 100 * progress / total) + 50), | ||||
false); | false); | ||||
const CScript &script = script_pair.first; | const CScript &script = script_pair.first; | ||||
int64_t time = script_pair.second; | int64_t time = script_pair.second; | ||||
CScriptID id(script); | |||||
if (pwallet->HaveCScript(id)) { | if (!pwallet->ImportScripts({script}, time)) { | ||||
pwallet->WalletLogPrintf( | |||||
"Skipping import of %s (script already present)\n", | |||||
HexStr(script)); | |||||
continue; | |||||
} | |||||
if (!pwallet->AddCScript(script)) { | |||||
pwallet->WalletLogPrintf("Error importing script %s\n", | pwallet->WalletLogPrintf("Error importing script %s\n", | ||||
HexStr(script)); | HexStr(script)); | ||||
fGood = false; | fGood = false; | ||||
continue; | continue; | ||||
} | } | ||||
if (time > 0) { | if (time > 0) { | ||||
pwallet->m_script_metadata[id].nCreateTime = time; | |||||
nTimeBegin = std::min(nTimeBegin, time); | nTimeBegin = std::min(nTimeBegin, time); | ||||
} | } | ||||
progress++; | progress++; | ||||
} | } | ||||
// hide progress dialog in GUI | // hide progress dialog in GUI | ||||
pwallet->chain().showProgress("", 100, false); | pwallet->chain().showProgress("", 100, false); | ||||
pwallet->UpdateTimeFirstKey(nTimeBegin); | |||||
} | } | ||||
// hide progress dialog in GUI | // hide progress dialog in GUI | ||||
pwallet->chain().showProgress("", 100, false); | pwallet->chain().showProgress("", 100, false); | ||||
RescanWallet(*pwallet, reserver, nTimeBegin, false /* update */); | RescanWallet(*pwallet, reserver, nTimeBegin, false /* update */); | ||||
pwallet->MarkDirty(); | pwallet->MarkDirty(); | ||||
if (!fGood) { | if (!fGood) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
▲ Show 20 Lines • Show All 1,032 Lines • Show Last 20 Lines |