Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 633 Lines • ▼ Show 20 Lines | bool fGood = true; | ||||
CBitcoinSecret vchSecret; | CBitcoinSecret vchSecret; | ||||
if (vchSecret.SetString(vstr[0])) { | if (vchSecret.SetString(vstr[0])) { | ||||
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, 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", EncodeDestination(keyid)); | LogPrintf("Importing %s...\n", | ||||
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"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | if (!masterKeyID.IsNull()) { | ||||
<< "\n\n"; | << "\n\n"; | ||||
} | } | ||||
} | } | ||||
for (std::vector<std::pair<int64_t, CKeyID>>::const_iterator it = | for (std::vector<std::pair<int64_t, CKeyID>>::const_iterator it = | ||||
vKeyBirth.begin(); | vKeyBirth.begin(); | ||||
it != vKeyBirth.end(); it++) { | it != vKeyBirth.end(); it++) { | ||||
const CKeyID &keyid = it->second; | const CKeyID &keyid = it->second; | ||||
std::string strTime = FormatISO8601DateTime(it->first); | std::string strTime = FormatISO8601DateTime(it->first); | ||||
std::string strAddr = EncodeDestination(keyid); | std::string strAddr = EncodeDestination(keyid, config); | ||||
CKey key; | CKey key; | ||||
if (pwallet->GetKey(keyid, key)) { | if (pwallet->GetKey(keyid, key)) { | ||||
file << strprintf("%s %s ", CBitcoinSecret(key).ToString(), | file << strprintf("%s %s ", CBitcoinSecret(key).ToString(), | ||||
strTime); | strTime); | ||||
if (pwallet->mapAddressBook.count(keyid)) { | if (pwallet->mapAddressBook.count(keyid)) { | ||||
file << strprintf( | file << strprintf( | ||||
"label=%s", | "label=%s", | ||||
EncodeDumpString(pwallet->mapAddressBook[keyid].name)); | EncodeDumpString(pwallet->mapAddressBook[keyid].name)); | ||||
Show All 12 Lines | for (std::vector<std::pair<int64_t, CKeyID>>::const_iterator it = | ||||
? " hdkeypath=" + pwallet->mapKeyMetadata[keyid].hdKeypath | ? " hdkeypath=" + pwallet->mapKeyMetadata[keyid].hdKeypath | ||||
: "")); | : "")); | ||||
} | } | ||||
} | } | ||||
file << "\n"; | file << "\n"; | ||||
for (const CScriptID &scriptid : scripts) { | for (const CScriptID &scriptid : scripts) { | ||||
CScript script; | CScript script; | ||||
std::string create_time = "0"; | std::string create_time = "0"; | ||||
std::string address = EncodeDestination(scriptid); | std::string address = EncodeDestination(scriptid, config); | ||||
// get birth times for scripts with metadata | // get birth times for scripts with metadata | ||||
auto it = pwallet->m_script_metadata.find(scriptid); | auto it = pwallet->m_script_metadata.find(scriptid); | ||||
if (it != pwallet->m_script_metadata.end()) { | if (it != pwallet->m_script_metadata.end()) { | ||||
create_time = FormatISO8601DateTime(it->second.nCreateTime); | create_time = FormatISO8601DateTime(it->second.nCreateTime); | ||||
} | } | ||||
if (pwallet->GetCScript(scriptid, script)) { | if (pwallet->GetCScript(scriptid, script)) { | ||||
file << strprintf("%s %s script=1", | file << strprintf("%s %s script=1", | ||||
HexStr(script.begin(), script.end()), | HexStr(script.begin(), script.end()), | ||||
▲ Show 20 Lines • Show All 586 Lines • Show Last 20 Lines |