Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 899 Lines • ▼ Show 20 Lines | UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet &wallet = *pwallet; | CWallet &wallet = *pwallet; | ||||
LegacyScriptPubKeyMan &spk_man = EnsureLegacyScriptPubKeyMan(wallet); | LegacyScriptPubKeyMan &spk_man = EnsureLegacyScriptPubKeyMan(wallet); | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
wallet.BlockUntilSyncedToCurrentChain(); | wallet.BlockUntilSyncedToCurrentChain(); | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK2(pwallet->cs_wallet, spk_man.cs_KeyStore); | LOCK2(wallet.cs_wallet, spk_man.cs_KeyStore); | ||||
EnsureWalletIsUnlocked(&wallet); | EnsureWalletIsUnlocked(&wallet); | ||||
fs::path filepath = request.params[0].get_str(); | fs::path filepath = request.params[0].get_str(); | ||||
filepath = fs::absolute(filepath); | filepath = fs::absolute(filepath); | ||||
/** | /** | ||||
* Prevent arbitrary files from being overwritten. There have been reports | * Prevent arbitrary files from being overwritten. There have been reports | ||||
Show All 12 Lines | UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | ||||
file.open(filepath); | 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<CKeyID, int64_t> mapKeyBirth; | std::map<CKeyID, int64_t> mapKeyBirth; | ||||
const std::map<CKeyID, int64_t> &mapKeyPool = spk_man.GetAllReserveKeys(); | const std::map<CKeyID, int64_t> &mapKeyPool = spk_man.GetAllReserveKeys(); | ||||
pwallet->GetKeyBirthTimes(*locked_chain, mapKeyBirth); | wallet.GetKeyBirthTimes(*locked_chain, mapKeyBirth); | ||||
std::set<CScriptID> scripts = spk_man.GetCScripts(); | std::set<CScriptID> scripts = spk_man.GetCScripts(); | ||||
// sort time/key pairs | // sort time/key pairs | ||||
std::vector<std::pair<int64_t, CKeyID>> vKeyBirth; | std::vector<std::pair<int64_t, CKeyID>> vKeyBirth; | ||||
for (const auto &entry : mapKeyBirth) { | for (const auto &entry : mapKeyBirth) { | ||||
vKeyBirth.push_back(std::make_pair(entry.second, entry.first)); | vKeyBirth.push_back(std::make_pair(entry.second, entry.first)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 894 Lines • Show Last 20 Lines |