Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 653 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(_("Importing..."), 0, false); | uiInterface.ShowProgress( | ||||
strprintf("%s " + _("Importing..."), pwallet->GetDisplayName()), 0, | |||||
false); | |||||
while (file.good()) { | while (file.good()) { | ||||
uiInterface.ShowProgress( | uiInterface.ShowProgress( | ||||
"", | "", | ||||
std::max(1, std::min(99, (int)(((double)file.tellg() / | std::max(1, std::min(99, (int)(((double)file.tellg() / | ||||
(double)nFilesize) * | (double)nFilesize) * | ||||
100))), | 100))), | ||||
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; | ||||
} | } | ||||
std::vector<std::string> vstr; | std::vector<std::string> vstr; | ||||
boost::split(vstr, line, boost::is_any_of(" ")); | boost::split(vstr, line, boost::is_any_of(" ")); | ||||
if (vstr.size() < 2) { | if (vstr.size() < 2) { | ||||
continue; | continue; | ||||
} | } | ||||
CKey key = DecodeSecret(vstr[0]); | CKey key = DecodeSecret(vstr[0]); | ||||
if (key.IsValid()) { | if (key.IsValid()) { | ||||
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)) { | if (pwallet->HaveKey(keyid)) { | ||||
LogPrintf("Skipping import of %s (key already present)\n", | pwallet->WalletLogPrintf( | ||||
"Skipping import of %s (key already present)\n", | |||||
EncodeDestination(keyid, config)); | EncodeDestination(keyid, config)); | ||||
continue; | continue; | ||||
} | } | ||||
int64_t nTime = DecodeDumpTime(vstr[1]); | int64_t nTime = DecodeDumpTime(vstr[1]); | ||||
std::string strLabel; | std::string strLabel; | ||||
bool fLabel = true; | bool fLabel = true; | ||||
for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) { | for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) { | ||||
if (boost::algorithm::starts_with(vstr[nStr], "#")) { | if (boost::algorithm::starts_with(vstr[nStr], "#")) { | ||||
break; | break; | ||||
} | } | ||||
if (vstr[nStr] == "change=1") { | if (vstr[nStr] == "change=1") { | ||||
fLabel = false; | fLabel = false; | ||||
} | } | ||||
if (vstr[nStr] == "reserve=1") { | if (vstr[nStr] == "reserve=1") { | ||||
fLabel = false; | fLabel = false; | ||||
} | } | ||||
if (boost::algorithm::starts_with(vstr[nStr], "label=")) { | if (boost::algorithm::starts_with(vstr[nStr], "label=")) { | ||||
strLabel = DecodeDumpString(vstr[nStr].substr(6)); | strLabel = DecodeDumpString(vstr[nStr].substr(6)); | ||||
fLabel = true; | fLabel = true; | ||||
} | } | ||||
} | } | ||||
LogPrintf("Importing %s...\n", | pwallet->WalletLogPrintf("Importing %s...\n", | ||||
EncodeDestination(keyid, config)); | EncodeDestination(keyid, config)); | ||||
if (!pwallet->AddKeyPubKey(key, pubkey)) { | if (!pwallet->AddKeyPubKey(key, pubkey)) { | ||||
fGood = false; | fGood = false; | ||||
continue; | continue; | ||||
} | } | ||||
pwallet->mapKeyMetadata[keyid].nCreateTime = nTime; | pwallet->mapKeyMetadata[keyid].nCreateTime = nTime; | ||||
if (fLabel) { | if (fLabel) { | ||||
pwallet->SetAddressBook(keyid, strLabel, "receive"); | pwallet->SetAddressBook(keyid, strLabel, "receive"); | ||||
} | } | ||||
nTimeBegin = std::min(nTimeBegin, nTime); | nTimeBegin = std::min(nTimeBegin, nTime); | ||||
} else if (IsHex(vstr[0])) { | } else if (IsHex(vstr[0])) { | ||||
std::vector<uint8_t> vData(ParseHex(vstr[0])); | std::vector<uint8_t> vData(ParseHex(vstr[0])); | ||||
CScript script = CScript(vData.begin(), vData.end()); | CScript script = CScript(vData.begin(), vData.end()); | ||||
if (pwallet->HaveCScript(script)) { | if (pwallet->HaveCScript(script)) { | ||||
LogPrintf( | pwallet->WalletLogPrintf( | ||||
"Skipping import of %s (script already present)\n", | "Skipping import of %s (script already present)\n", | ||||
vstr[0]); | vstr[0]); | ||||
continue; | continue; | ||||
} | } | ||||
if (!pwallet->AddCScript(script)) { | if (!pwallet->AddCScript(script)) { | ||||
LogPrintf("Error importing script %s\n", vstr[0]); | pwallet->WalletLogPrintf("Error importing script %s\n", | ||||
vstr[0]); | |||||
fGood = false; | fGood = false; | ||||
continue; | continue; | ||||
} | } | ||||
int64_t birth_time = DecodeDumpTime(vstr[1]); | int64_t birth_time = DecodeDumpTime(vstr[1]); | ||||
if (birth_time > 0) { | if (birth_time > 0) { | ||||
pwallet->m_script_metadata[CScriptID(script)].nCreateTime = | pwallet->m_script_metadata[CScriptID(script)].nCreateTime = | ||||
birth_time; | birth_time; | ||||
nTimeBegin = std::min(nTimeBegin, birth_time); | nTimeBegin = std::min(nTimeBegin, birth_time); | ||||
▲ Show 20 Lines • Show All 785 Lines • Show Last 20 Lines |