Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 654 Lines • ▼ Show 20 Lines | if (!IsValidDestination(dest)) { | ||||
"Invalid Bitcoin address"); | "Invalid Bitcoin address"); | ||||
} | } | ||||
const CKeyID *keyID = boost::get<CKeyID>(&dest); | const CKeyID *keyID = boost::get<CKeyID>(&dest); | ||||
if (!keyID) { | if (!keyID) { | ||||
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key"); | throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key"); | ||||
} | } | ||||
CKey vchSecret; | CKey vchSecret; | ||||
if (!pwallet->GetKey(*keyID, vchSecret)) { | if (!pwallet->GetKey(*keyID, vchSecret)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + | ||||
"Private key for address " + strAddress + | strAddress + " is not known"); | ||||
" is not known"); | |||||
} | } | ||||
return CBitcoinSecret(vchSecret).ToString(); | return CBitcoinSecret(vchSecret).ToString(); | ||||
} | } | ||||
UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | UniValue dumpwallet(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | file << strprintf("# mined on %s\n", | ||||
EncodeDumpTime(chainActive.Tip()->GetBlockTime())); | EncodeDumpTime(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)) { | ||||
std::string masterseed = EncodeBase58(key.begin(), key.end()); | |||||
file << "# private masterseed (save to recover HD Wallet): " | |||||
<< masterseed << "\n\n"; | |||||
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"; | ||||
▲ Show 20 Lines • Show All 603 Lines • Show Last 20 Lines |