Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 4,353 Lines • ▼ Show 20 Lines | if (meta) { | ||||
if (!meta->hdKeypath.empty()) { | if (!meta->hdKeypath.empty()) { | ||||
ret.pushKV("hdkeypath", meta->hdKeypath); | ret.pushKV("hdkeypath", meta->hdKeypath); | ||||
ret.pushKV("hdmasterkeyid", meta->hdMasterKeyID.GetHex()); | ret.pushKV("hdmasterkeyid", meta->hdMasterKeyID.GetHex()); | ||||
} | } | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue sethdseed(const Config &config, const JSONRPCRequest &request) { | |||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | |||||
return NullUniValue; | |||||
} | |||||
if (request.fHelp || request.params.size() > 2) { | |||||
throw std::runtime_error( | |||||
"sethdseed ( \"newkeypool\" \"seed\" )\n" | |||||
"\nSet or generate a new HD wallet seed. Non-HD wallets will not " | |||||
"be upgraded to being a HD wallet. Wallets that are already\n" | |||||
"HD will have a new HD seed set so that new keys added to the " | |||||
"keypool will be derived from this new seed.\n" | |||||
"\nNote that you will need to MAKE A NEW BACKUP of your wallet " | |||||
"after setting the HD wallet seed.\n" + | |||||
HelpRequiringPassphrase(pwallet) + | |||||
"\nArguments:\n" | |||||
"1. \"newkeypool\" (boolean, optional, default=true) " | |||||
"Whether to flush old unused addresses, including change " | |||||
"addresses, from the keypool and regenerate it.\n" | |||||
" If true, the next address from " | |||||
"getnewaddress and change address from getrawchangeaddress will be " | |||||
"from this new seed.\n" | |||||
" If false, addresses (including " | |||||
"change addresses if the wallet already had HD Chain Split " | |||||
"enabled) from the existing\n" | |||||
" keypool will be used until it has " | |||||
"been depleted.\n" | |||||
"2. \"seed\" (string, optional) The WIF private key " | |||||
"to use as the new HD seed; if not provided a random seed will be " | |||||
"used.\n" | |||||
" The seed value can be retrieved " | |||||
"using the dumpwallet command. It is the private key marked " | |||||
"hdmaster=1\n" | |||||
"\nExamples:\n" + | |||||
HelpExampleCli("sethdseed", "") + | |||||
HelpExampleCli("sethdseed", "false") + | |||||
HelpExampleCli("sethdseed", "true \"wifkey\"") + | |||||
HelpExampleRpc("sethdseed", "true, \"wifkey\"")); | |||||
} | |||||
if (IsInitialBlockDownload()) { | |||||
throw JSONRPCError( | |||||
RPC_CLIENT_IN_INITIAL_DOWNLOAD, | |||||
"Cannot set a new HD seed while still in Initial Block Download"); | |||||
} | |||||
LOCK2(cs_main, pwallet->cs_wallet); | |||||
// Do not do anything to non-HD wallets | |||||
if (!pwallet->IsHDEnabled()) { | |||||
throw JSONRPCError( | |||||
RPC_WALLET_ERROR, | |||||
"Cannot set a HD seed on a non-HD wallet. Start with " | |||||
"-upgradewallet in order to upgrade a non-HD wallet to HD"); | |||||
} | |||||
EnsureWalletIsUnlocked(pwallet); | |||||
bool flush_key_pool = true; | |||||
if (!request.params[0].isNull()) { | |||||
flush_key_pool = request.params[0].get_bool(); | |||||
} | |||||
CPubKey master_pub_key; | |||||
if (request.params[1].isNull()) { | |||||
master_pub_key = pwallet->GenerateNewHDMasterKey(); | |||||
} else { | |||||
CKey key = DecodeSecret(request.params[1].get_str()); | |||||
if (!key.IsValid()) { | |||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | |||||
"Invalid private key"); | |||||
} | |||||
if (HaveKey(*pwallet, key)) { | |||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | |||||
"Already have this key (either as an HD seed or " | |||||
"as a loose private key)"); | |||||
} | |||||
master_pub_key = pwallet->DeriveNewMasterHDKey(key); | |||||
} | |||||
pwallet->SetHDMasterKey(master_pub_key); | |||||
if (flush_key_pool) { | |||||
pwallet->NewKeyPool(); | |||||
} | |||||
return NullUniValue; | |||||
} | |||||
// clang-format off | // clang-format off | ||||
static const ContextFreeRPCCommand commands[] = { | static const ContextFreeRPCCommand commands[] = { | ||||
// category name actor (function) argNames | // category name actor (function) argNames | ||||
// ------------------- ------------------------ ---------------------- ---------- | // ------------------- ------------------------ ---------------------- ---------- | ||||
{ "rawtransactions", "fundrawtransaction", fundrawtransaction, {"hexstring","options"} }, | { "rawtransactions", "fundrawtransaction", fundrawtransaction, {"hexstring","options"} }, | ||||
{ "hidden", "resendwallettransactions", resendwallettransactions, {} }, | { "hidden", "resendwallettransactions", resendwallettransactions, {} }, | ||||
{ "wallet", "abandontransaction", abandontransaction, {"txid"} }, | { "wallet", "abandontransaction", abandontransaction, {"txid"} }, | ||||
{ "wallet", "addmultisigaddress", addmultisigaddress, {"nrequired","keys","label|account"} }, | { "wallet", "addmultisigaddress", addmultisigaddress, {"nrequired","keys","label|account"} }, | ||||
Show All 23 Lines | static const ContextFreeRPCCommand commands[] = { | ||||
{ "wallet", "listsinceblock", listsinceblock, {"blockhash","target_confirmations","include_watchonly","include_removed"} }, | { "wallet", "listsinceblock", listsinceblock, {"blockhash","target_confirmations","include_watchonly","include_removed"} }, | ||||
{ "wallet", "listtransactions", listtransactions, {"account","count","skip","include_watchonly"} }, | { "wallet", "listtransactions", listtransactions, {"account","count","skip","include_watchonly"} }, | ||||
{ "wallet", "listunspent", listunspent, {"minconf","maxconf","addresses","include_unsafe","query_options"} }, | { "wallet", "listunspent", listunspent, {"minconf","maxconf","addresses","include_unsafe","query_options"} }, | ||||
{ "wallet", "listwallets", listwallets, {} }, | { "wallet", "listwallets", listwallets, {} }, | ||||
{ "wallet", "loadwallet", loadwallet, {"filename"} }, | { "wallet", "loadwallet", loadwallet, {"filename"} }, | ||||
{ "wallet", "lockunspent", lockunspent, {"unlock","transactions"} }, | { "wallet", "lockunspent", lockunspent, {"unlock","transactions"} }, | ||||
{ "wallet", "move", movecmd, {"fromaccount","toaccount","amount","minconf","comment"} }, | { "wallet", "move", movecmd, {"fromaccount","toaccount","amount","minconf","comment"} }, | ||||
{ "wallet", "rescanblockchain", rescanblockchain, {"start_height", "stop_height"} }, | { "wallet", "rescanblockchain", rescanblockchain, {"start_height", "stop_height"} }, | ||||
{ "wallet", "sethdseed", sethdseed, {"newkeypool","seed"} }, | |||||
{ "wallet", "sendfrom", sendfrom, {"fromaccount","toaddress","amount","minconf","comment","comment_to"} }, | { "wallet", "sendfrom", sendfrom, {"fromaccount","toaddress","amount","minconf","comment","comment_to"} }, | ||||
{ "wallet", "sendmany", sendmany, {"fromaccount","amounts","minconf","comment","subtractfeefrom"} }, | { "wallet", "sendmany", sendmany, {"fromaccount","amounts","minconf","comment","subtractfeefrom"} }, | ||||
{ "wallet", "sendtoaddress", sendtoaddress, {"address","amount","comment","comment_to","subtractfeefromamount"} }, | { "wallet", "sendtoaddress", sendtoaddress, {"address","amount","comment","comment_to","subtractfeefromamount"} }, | ||||
{ "wallet", "setlabel", setlabel, {"address","label"} }, | { "wallet", "setlabel", setlabel, {"address","label"} }, | ||||
{ "wallet", "setaccount", setlabel, {"address","account"} }, | { "wallet", "setaccount", setlabel, {"address","account"} }, | ||||
{ "wallet", "settxfee", settxfee, {"amount"} }, | { "wallet", "settxfee", settxfee, {"amount"} }, | ||||
{ "wallet", "signmessage", signmessage, {"address","message"} }, | { "wallet", "signmessage", signmessage, {"address","message"} }, | ||||
{ "wallet", "signrawtransactionwithwallet", signrawtransactionwithwallet, {"hextring","prevtxs","sighashtype"} }, | { "wallet", "signrawtransactionwithwallet", signrawtransactionwithwallet, {"hextring","prevtxs","sighashtype"} }, | ||||
Show All 12 Lines |