Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 695 Lines • ▼ Show 20 Lines | bool fGood = true; | ||||
file.seekg(0, file.beg); | file.seekg(0, file.beg); | ||||
// Use uiInterface.ShowProgress instead of pwallet.ShowProgress because | // Use uiInterface.ShowProgress instead of pwallet.ShowProgress because | ||||
// pwallet.ShowProgress has a cancel button tied to AbortRescan which we | // pwallet.ShowProgress has a cancel button tied to AbortRescan which we | ||||
// don't want for this progress bar showing the import progress. | // don't want for this progress bar showing the import progress. | ||||
// uiInterface.ShowProgress does not have a cancel button. | // uiInterface.ShowProgress does not have a cancel button. | ||||
// show progress dialog in GUI | // show progress dialog in GUI | ||||
uiInterface.ShowProgress( | pwallet->chain().showProgress( | ||||
strprintf("%s " + _("Importing..."), pwallet->GetDisplayName()), 0, | strprintf("%s " + _("Importing..."), pwallet->GetDisplayName()), 0, | ||||
false); | false); | ||||
std::vector<std::tuple<CKey, int64_t, bool, std::string>> keys; | std::vector<std::tuple<CKey, int64_t, bool, std::string>> keys; | ||||
std::vector<std::pair<CScript, int64_t>> scripts; | std::vector<std::pair<CScript, int64_t>> scripts; | ||||
while (file.good()) { | while (file.good()) { | ||||
uiInterface.ShowProgress( | pwallet->chain().showProgress( | ||||
"", | "", | ||||
std::max(1, std::min<int>(50, 100 * double(file.tellg()) / | std::max(1, std::min<int>(50, 100 * double(file.tellg()) / | ||||
double(nFilesize))), | double(nFilesize))), | ||||
false); | false); | ||||
std::string line; | std::string line; | ||||
std::getline(file, line); | std::getline(file, line); | ||||
if (line.empty() || line[0] == '#') { | if (line.empty() || line[0] == '#') { | ||||
continue; | continue; | ||||
Show All 34 Lines | bool fGood = true; | ||||
} | } | ||||
} | } | ||||
file.close(); | file.close(); | ||||
// We now know whether we are importing private keys, so we can error if | // We now know whether we are importing private keys, so we can error if | ||||
// private keys are disabled | // private keys are disabled | ||||
if (keys.size() > 0 && | if (keys.size() > 0 && | ||||
pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | ||||
// hide progress dialog in GUI | // hide progress dialog in GUI | ||||
uiInterface.ShowProgress("", 100, false); | pwallet->chain().showProgress("", 100, false); | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_ERROR, | RPC_WALLET_ERROR, | ||||
"Importing wallets is disabled when private keys are disabled"); | "Importing wallets is disabled when private keys are disabled"); | ||||
} | } | ||||
double total = double(keys.size() + scripts.size()); | double total = double(keys.size() + scripts.size()); | ||||
double progress = 0; | double progress = 0; | ||||
for (const auto &key_tuple : keys) { | for (const auto &key_tuple : keys) { | ||||
uiInterface.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 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); | ||||
Show All 15 Lines | bool fGood = true; | ||||
pwallet->mapKeyMetadata[keyid].nCreateTime = time; | pwallet->mapKeyMetadata[keyid].nCreateTime = time; | ||||
if (has_label) { | if (has_label) { | ||||
pwallet->SetAddressBook(keyid, label, "receive"); | pwallet->SetAddressBook(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) { | ||||
uiInterface.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); | CScriptID id(script); | ||||
if (pwallet->HaveCScript(id)) { | if (pwallet->HaveCScript(id)) { | ||||
pwallet->WalletLogPrintf( | pwallet->WalletLogPrintf( | ||||
Show All 9 Lines | bool fGood = true; | ||||
} | } | ||||
if (time > 0) { | if (time > 0) { | ||||
pwallet->m_script_metadata[id].nCreateTime = time; | 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 | ||||
uiInterface.ShowProgress("", 100, false); | pwallet->chain().showProgress("", 100, false); | ||||
pwallet->UpdateTimeFirstKey(nTimeBegin); | pwallet->UpdateTimeFirstKey(nTimeBegin); | ||||
} | } | ||||
// hide progress dialog in GUI | // hide progress dialog in GUI | ||||
uiInterface.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, | ||||
"Error adding some keys/scripts to wallet"); | "Error adding some keys/scripts to wallet"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 899 Lines • Show Last 20 Lines |