Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 861 Lines • ▼ Show 20 Lines | UniValue dumpprivkey(const Config &config, const JSONRPCRequest &request) { | ||||
if (!spk_man.GetKey(keyid, vchSecret)) { | if (!spk_man.GetKey(keyid, vchSecret)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + | throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + | ||||
strAddress + " is not known"); | strAddress + " is not known"); | ||||
} | } | ||||
return EncodeSecret(vchSecret); | return EncodeSecret(vchSecret); | ||||
} | } | ||||
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 pwallet = | ||||
CWallet *const pwallet = wallet.get(); | GetWalletForJSONRPCRequest(request); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet.get(), request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"dumpwallet", | "dumpwallet", | ||||
"Dumps all wallet keys in a human-readable format to a server-side " | "Dumps all wallet keys in a human-readable format to a server-side " | ||||
"file. This does not allow overwriting existing files.\n" | "file. This does not allow overwriting existing files.\n" | ||||
"Imported scripts are included in the dumpsfile, but corresponding " | "Imported scripts are included in the dumpsfile, but corresponding " | ||||
Show All 11 Lines | RPCHelpMan{ | ||||
" \"filename\" : { (string) The filename with full " | " \"filename\" : { (string) The filename with full " | ||||
"absolute path\n" | "absolute path\n" | ||||
"}\n"}, | "}\n"}, | ||||
RPCExamples{HelpExampleCli("dumpwallet", "\"test\"") + | RPCExamples{HelpExampleCli("dumpwallet", "\"test\"") + | ||||
HelpExampleRpc("dumpwallet", "\"test\"")}, | HelpExampleRpc("dumpwallet", "\"test\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
LegacyScriptPubKeyMan &spk_man = EnsureLegacyScriptPubKeyMan(*wallet); | CWallet &wallet = *pwallet; | ||||
LegacyScriptPubKeyMan &spk_man = EnsureLegacyScriptPubKeyMan(wallet); | |||||
// 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 | |||||
wallet.BlockUntilSyncedToCurrentChain(); | |||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK2(pwallet->cs_wallet, spk_man.cs_KeyStore); | LOCK2(pwallet->cs_wallet, spk_man.cs_KeyStore); | ||||
EnsureWalletIsUnlocked(pwallet); | 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 | ||||
* that users have overwritten wallet files this way: | * that users have overwritten wallet files this way: | ||||
* https://github.com/bitcoin/bitcoin/issues/9934 | * https://github.com/bitcoin/bitcoin/issues/9934 | ||||
Show All 26 Lines | UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | ||||
} | } | ||||
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", FormatISO8601DateTime(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", | ||||
pwallet->GetLastBlockHeight(), | wallet.GetLastBlockHeight(), | ||||
pwallet->GetLastBlockHash().ToString()); | wallet.GetLastBlockHash().ToString()); | ||||
int64_t block_time = 0; | int64_t block_time = 0; | ||||
CHECK_NONFATAL(pwallet->chain().findBlock(pwallet->GetLastBlockHash(), | CHECK_NONFATAL(wallet.chain().findBlock(wallet.GetLastBlockHash(), | ||||
FoundBlock().time(block_time))); | FoundBlock().time(block_time))); | ||||
file << strprintf("# mined on %s\n", FormatISO8601DateTime(block_time)); | file << strprintf("# mined on %s\n", FormatISO8601DateTime(block_time)); | ||||
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 seed_id = spk_man.GetHDChain().seed_id; | CKeyID seed_id = spk_man.GetHDChain().seed_id; | ||||
if (!seed_id.IsNull()) { | if (!seed_id.IsNull()) { | ||||
CKey seed; | CKey seed; | ||||
if (spk_man.GetKey(seed_id, seed)) { | if (spk_man.GetKey(seed_id, seed)) { | ||||
Show All 9 Lines | for (std::vector<std::pair<int64_t, CKeyID>>::const_iterator it = | ||||
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; | std::string strAddr; | ||||
std::string strLabel; | std::string strLabel; | ||||
CKey key; | CKey key; | ||||
if (spk_man.GetKey(keyid, key)) { | if (spk_man.GetKey(keyid, key)) { | ||||
file << strprintf("%s %s ", EncodeSecret(key), strTime); | file << strprintf("%s %s ", EncodeSecret(key), strTime); | ||||
if (GetWalletAddressesForKey(config, &spk_man, pwallet, keyid, | if (GetWalletAddressesForKey(config, &spk_man, &wallet, keyid, | ||||
strAddr, strLabel)) { | strAddr, strLabel)) { | ||||
file << strprintf("label=%s", strLabel); | file << strprintf("label=%s", strLabel); | ||||
} else if (keyid == seed_id) { | } else if (keyid == seed_id) { | ||||
file << "hdseed=1"; | file << "hdseed=1"; | ||||
} else if (mapKeyPool.count(keyid)) { | } else if (mapKeyPool.count(keyid)) { | ||||
file << "reserve=1"; | file << "reserve=1"; | ||||
} else if (spk_man.mapKeyMetadata[keyid].hdKeypath == "s") { | } else if (spk_man.mapKeyMetadata[keyid].hdKeypath == "s") { | ||||
file << "inactivehdseed=1"; | file << "inactivehdseed=1"; | ||||
▲ Show 20 Lines • Show All 848 Lines • Show Last 20 Lines |