Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show All 31 Lines | 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); | ||||
boost::posix_time::ptime ptime(boost::date_time::not_a_date_time); | boost::posix_time::ptime ptime(boost::date_time::not_a_date_time); | ||||
iss >> ptime; | iss >> ptime; | ||||
if (ptime.is_not_a_date_time()) return 0; | if (ptime.is_not_a_date_time()) { | ||||
return 0; | |||||
} | |||||
return (ptime - epoch).total_seconds(); | return (ptime - epoch).total_seconds(); | ||||
} | } | ||||
static std::string EncodeDumpString(const std::string &str) { | static std::string EncodeDumpString(const std::string &str) { | ||||
std::stringstream ret; | std::stringstream ret; | ||||
for (const uint8_t c : str) { | for (const uint8_t c : str) { | ||||
if (c <= 32 || c >= 128 || c == '%') { | if (c <= 32 || c >= 128 || c == '%') { | ||||
ret << '%' << HexStr(&c, &c + 1); | ret << '%' << HexStr(&c, &c + 1); | ||||
▲ Show 20 Lines • Show All 813 Lines • ▼ Show 20 Lines | |||||
UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 1) | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"dumpwallet \"filename\"\n" | "dumpwallet \"filename\"\n" | ||||
"\nDumps all wallet keys in a human-readable format to a " | "\nDumps all wallet keys in a human-readable format to a " | ||||
"server-side file. This does not allow overwriting existing " | "server-side file. This does not allow overwriting existing " | ||||
"files.\n" | "files.\n" | ||||
"Imported scripts are included in the dumpsfile, but corresponding " | "Imported scripts are included in the dumpsfile, but corresponding " | ||||
"addresses may not be added automatically by importwallet.\n" | "addresses may not be added automatically by importwallet.\n" | ||||
"Note that if your wallet contains keys which are not derived from " | "Note that if your wallet contains keys which are not derived from " | ||||
"your HD seed (e.g. imported keys), these are not covered by\n" | "your HD seed (e.g. imported keys), these are not covered by\n" | ||||
"only backing up the seed itself, and must be backed up too (e.g. " | "only backing up the seed itself, and must be backed up too (e.g. " | ||||
"ensure you back up the whole dumpfile).\n" | "ensure you back up the whole dumpfile).\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"filename\" (string, required) The filename with path " | "1. \"filename\" (string, required) The filename with path " | ||||
"(either absolute or relative to bitcoind)\n" | "(either absolute or relative to bitcoind)\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"{ (json object)\n" | "{ (json object)\n" | ||||
" \"filename\" : { (string) The filename with full " | " \"filename\" : { (string) The filename with full " | ||||
"absolute path\n" | "absolute path\n" | ||||
"}\n" | "}\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("dumpwallet", "\"test\"") + | HelpExampleCli("dumpwallet", "\"test\"") + | ||||
HelpExampleRpc("dumpwallet", "\"test\"")); | HelpExampleRpc("dumpwallet", "\"test\"")); | ||||
} | |||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
fs::path filepath = request.params[0].get_str(); | fs::path filepath = request.params[0].get_str(); | ||||
filepath = fs::absolute(filepath); | filepath = fs::absolute(filepath); | ||||
▲ Show 20 Lines • Show All 690 Lines • Show Last 20 Lines |