Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show All 18 Lines | |||||
#include <wallet/rpcwallet.h> | #include <wallet/rpcwallet.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#include <boost/algorithm/string.hpp> | #include <boost/algorithm/string.hpp> | ||||
#include <univalue.h> | #include <univalue.h> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <fstream> | |||||
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); | ||||
} else { | } else { | ||||
ret << c; | ret << c; | ||||
▲ Show 20 Lines • Show All 599 Lines • ▼ Show 20 Lines | UniValue importwallet(const Config &config, const JSONRPCRequest &request) { | ||||
int64_t nTimeBegin = 0; | int64_t nTimeBegin = 0; | ||||
bool fGood = true; | bool fGood = true; | ||||
{ | { | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
std::ifstream file; | fsbridge::ifstream file; | ||||
file.open(request.params[0].get_str().c_str(), | file.open(request.params[0].get_str(), std::ios::in | std::ios::ate); | ||||
std::ios::in | std::ios::ate); | |||||
if (!file.is_open()) { | if (!file.is_open()) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Cannot open wallet dump file"); | "Cannot open wallet dump file"); | ||||
} | } | ||||
nTimeBegin = ::ChainActive().Tip()->GetBlockTime(); | nTimeBegin = ::ChainActive().Tip()->GetBlockTime(); | ||||
int64_t nFilesize = std::max<int64_t>(1, file.tellg()); | int64_t nFilesize = std::max<int64_t>(1, file.tellg()); | ||||
file.seekg(0, file.beg); | file.seekg(0, file.beg); | ||||
▲ Show 20 Lines • Show All 238 Lines • ▼ Show 20 Lines | UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | ||||
*/ | */ | ||||
if (fs::exists(filepath)) { | if (fs::exists(filepath)) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
filepath.string() + " already exists. If you are " | filepath.string() + " already exists. If you are " | ||||
"sure this is what you want, " | "sure this is what you want, " | ||||
"move it out of the way first"); | "move it out of the way first"); | ||||
} | } | ||||
std::ofstream file; | fsbridge::ofstream file; | ||||
file.open(filepath.string().c_str()); | file.open(filepath); | ||||
if (!file.is_open()) { | if (!file.is_open()) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Cannot open wallet dump file"); | "Cannot open wallet dump file"); | ||||
} | } | ||||
std::map<CTxDestination, int64_t> mapKeyBirth; | std::map<CTxDestination, int64_t> mapKeyBirth; | ||||
const std::map<CKeyID, int64_t> &mapKeyPool = pwallet->GetAllReserveKeys(); | const std::map<CKeyID, int64_t> &mapKeyPool = pwallet->GetAllReserveKeys(); | ||||
pwallet->GetKeyBirthTimes(*locked_chain, mapKeyBirth); | pwallet->GetKeyBirthTimes(*locked_chain, mapKeyBirth); | ||||
▲ Show 20 Lines • Show All 669 Lines • Show Last 20 Lines |