Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 583 Lines • ▼ Show 20 Lines | while (file.good()) { | ||||
} | } | ||||
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; | ||||
} | } | ||||
CBitcoinSecret vchSecret; | CBitcoinSecret vchSecret; | ||||
if (!vchSecret.SetString(vstr[0])) { | if (vchSecret.SetString(vstr[0])) { | ||||
continue; | |||||
} | |||||
CKey key = vchSecret.GetKey(); | CKey key = vchSecret.GetKey(); | ||||
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", | LogPrintf("Skipping import of %s (key already present)\n", | ||||
EncodeDestination(keyid)); | EncodeDestination(keyid)); | ||||
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", EncodeDestination(keyid)); | LogPrintf("Importing %s...\n", EncodeDestination(keyid)); | ||||
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])) { | |||||
std::vector<unsigned char> vData(ParseHex(vstr[0])); | |||||
CScript script = CScript(vData.begin(), vData.end()); | |||||
if (pwallet->HaveCScript(script)) { | |||||
LogPrintf("Skipping import of %s (script already present)\n", | |||||
vstr[0]); | |||||
continue; | |||||
} | |||||
if (!pwallet->AddCScript(script)) { | |||||
LogPrintf("Error importing script %s\n", vstr[0]); | |||||
fGood = false; | |||||
continue; | |||||
} | |||||
int64_t birth_time = DecodeDumpTime(vstr[1]); | |||||
if (birth_time > 0) { | |||||
pwallet->m_script_metadata[CScriptID(script)].nCreateTime = | |||||
birth_time; | |||||
nTimeBegin = std::min(nTimeBegin, birth_time); | |||||
} | |||||
} | |||||
} | } | ||||
file.close(); | file.close(); | ||||
// hide progress dialog in GUI | // hide progress dialog in GUI | ||||
pwallet->ShowProgress("", 100); | pwallet->ShowProgress("", 100); | ||||
pwallet->UpdateTimeFirstKey(nTimeBegin); | pwallet->UpdateTimeFirstKey(nTimeBegin); | ||||
pwallet->RescanFromTime(nTimeBegin, false /* update */); | pwallet->RescanFromTime(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 to wallet"); | "Error adding some keys/scripts to wallet"); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
UniValue dumpprivkey(const Config &config, const JSONRPCRequest &request) { | UniValue dumpprivkey(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
▲ Show 20 Lines • Show All 766 Lines • Show Last 20 Lines |