Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show All 23 Lines | |||||
#include <boost/date_time/posix_time/posix_time.hpp> | #include <boost/date_time/posix_time/posix_time.hpp> | ||||
#include <univalue.h> | #include <univalue.h> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <fstream> | #include <fstream> | ||||
#include <iostream> | #include <iostream> | ||||
static std::string EncodeDumpTime(int64_t nTime) { | |||||
return DateTimeStrFormat("%Y-%m-%dT%H:%M:%SZ", nTime); | |||||
} | |||||
static int64_t DecodeDumpTime(const std::string &str) { | static int64_t DecodeDumpTime(const std::string &str) { | ||||
static const boost::posix_time::ptime epoch = | static const boost::posix_time::ptime epoch = | ||||
boost::posix_time::from_time_t(0); | boost::posix_time::from_time_t(0); | ||||
static const std::locale loc( | static const std::locale loc( | ||||
std::locale::classic(), | std::locale::classic(), | ||||
new boost::posix_time::time_input_facet("%Y-%m-%dT%H:%M:%SZ")); | new boost::posix_time::time_input_facet("%Y-%m-%dT%H:%M:%SZ")); | ||||
std::istringstream iss(str); | std::istringstream iss(str); | ||||
iss.imbue(loc); | iss.imbue(loc); | ||||
▲ Show 20 Lines • Show All 738 Lines • ▼ Show 20 Lines | for (const auto &entry : mapKeyBirth) { | ||||
vKeyBirth.push_back(std::make_pair(entry.second, *keyID)); | vKeyBirth.push_back(std::make_pair(entry.second, *keyID)); | ||||
} | } | ||||
} | } | ||||
mapKeyBirth.clear(); | mapKeyBirth.clear(); | ||||
std::sort(vKeyBirth.begin(), vKeyBirth.end()); | std::sort(vKeyBirth.begin(), vKeyBirth.end()); | ||||
// produce output | // produce output | ||||
file << strprintf("# Wallet dump created by Bitcoin %s\n", CLIENT_BUILD); | file << strprintf("# Wallet dump created by Bitcoin %s\n", CLIENT_BUILD); | ||||
file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime())); | file << strprintf("# * Created on %s\n", FormatISO8601DateTime(GetTime())); | ||||
file << strprintf("# * Best block at time of backup was %i (%s),\n", | file << strprintf("# * Best block at time of backup was %i (%s),\n", | ||||
chainActive.Height(), | chainActive.Height(), | ||||
chainActive.Tip()->GetBlockHash().ToString()); | chainActive.Tip()->GetBlockHash().ToString()); | ||||
file << strprintf("# mined on %s\n", | file << strprintf("# mined on %s\n", | ||||
EncodeDumpTime(chainActive.Tip()->GetBlockTime())); | FormatISO8601DateTime(chainActive.Tip()->GetBlockTime())); | ||||
file << "\n"; | file << "\n"; | ||||
// add the base58check encoded extended master if the wallet uses HD | // add the base58check encoded extended master if the wallet uses HD | ||||
CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID; | CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID; | ||||
if (!masterKeyID.IsNull()) { | if (!masterKeyID.IsNull()) { | ||||
CKey key; | CKey key; | ||||
if (pwallet->GetKey(masterKeyID, key)) { | if (pwallet->GetKey(masterKeyID, key)) { | ||||
CExtKey masterKey; | CExtKey masterKey; | ||||
masterKey.SetMaster(key.begin(), key.size()); | masterKey.SetMaster(key.begin(), key.size()); | ||||
CBitcoinExtKey b58extkey; | CBitcoinExtKey b58extkey; | ||||
b58extkey.SetKey(masterKey); | b58extkey.SetKey(masterKey); | ||||
file << "# extended private masterkey: " << b58extkey.ToString() | file << "# extended private masterkey: " << b58extkey.ToString() | ||||
<< "\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 = EncodeDumpTime(it->first); | std::string strTime = FormatISO8601DateTime(it->first); | ||||
std::string strAddr = EncodeDestination(keyid); | std::string strAddr = EncodeDestination(keyid); | ||||
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", | ||||
Show All 17 Lines | UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | ||||
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); | ||||
// 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 = EncodeDumpTime(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()), | ||||
create_time); | create_time); | ||||
file << strprintf(" # addr=%s\n", address); | file << strprintf(" # addr=%s\n", address); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 577 Lines • Show Last 20 Lines |