Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 3,173 Lines • ▼ Show 20 Lines | static UniValue loadwallet(const Config &config, | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
obj.pushKV("name", wallet->GetName()); | obj.pushKV("name", wallet->GetName()); | ||||
obj.pushKV("warning", warning); | obj.pushKV("warning", warning); | ||||
return obj; | return obj; | ||||
} | } | ||||
static UniValue setwalletflag(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() < 1 || | |||||
request.params.size() > 2) { | |||||
std::string flags = ""; | |||||
for (auto &it : WALLET_FLAG_MAP) { | |||||
if (it.second & MUTABLE_WALLET_FLAGS) { | |||||
flags += (flags == "" ? "" : ", ") + it.first; | |||||
} | |||||
} | |||||
throw std::runtime_error(RPCHelpMan{ | |||||
"setwalletflag", | |||||
"\nChange the state of the given wallet flag for a wallet.\n", | |||||
{ | |||||
{"flag", RPCArg::Type::STR, RPCArg::Optional::NO, | |||||
"The name of the flag to change. Current available flags: " + | |||||
flags}, | |||||
{"value", RPCArg::Type::BOOL, /* default */ "true", | |||||
"The new state."}, | |||||
}, | |||||
RPCResult{ | |||||
"{\n" | |||||
" \"flag_name\": string (string) The name of the flag " | |||||
"that was modified\n" | |||||
" \"flag_state\": bool (bool) The new state of the flag\n" | |||||
" \"warnings\": string (string) Any warnings associated " | |||||
"with the change\n" | |||||
"}\n"}, | |||||
RPCExamples{HelpExampleCli("setwalletflag", "avoid_reuse") + | |||||
HelpExampleRpc("setwalletflag", "\"avoid_reuse\"")}, | |||||
} | |||||
.ToString()); | |||||
} | |||||
std::string flag_str = request.params[0].get_str(); | |||||
bool value = request.params[1].isNull() || request.params[1].get_bool(); | |||||
if (!WALLET_FLAG_MAP.count(flag_str)) { | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | |||||
strprintf("Unknown wallet flag: %s", flag_str)); | |||||
} | |||||
auto flag = WALLET_FLAG_MAP.at(flag_str); | |||||
if (!(flag & MUTABLE_WALLET_FLAGS)) { | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | |||||
strprintf("Wallet flag is immutable: %s", flag_str)); | |||||
} | |||||
UniValue res(UniValue::VOBJ); | |||||
if (pwallet->IsWalletFlagSet(flag) == value) { | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | |||||
strprintf("Wallet flag is already set to %s: %s", | |||||
value ? "true" : "false", flag_str)); | |||||
} | |||||
res.pushKV("flag_name", flag_str); | |||||
res.pushKV("flag_state", value); | |||||
if (value) { | |||||
pwallet->SetWalletFlag(flag); | |||||
} else { | |||||
pwallet->UnsetWalletFlag(flag); | |||||
} | |||||
if (flag && value && WALLET_FLAG_CAVEATS.count(flag)) { | |||||
res.pushKV("warnings", WALLET_FLAG_CAVEATS.at(flag)); | |||||
} | |||||
return res; | |||||
} | |||||
static UniValue createwallet(const Config &config, | static UniValue createwallet(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
const RPCHelpMan help{ | const RPCHelpMan help{ | ||||
"createwallet", | "createwallet", | ||||
"\nCreates and loads a new wallet.\n", | "\nCreates and loads a new wallet.\n", | ||||
{ | { | ||||
{"wallet_name", RPCArg::Type::STR, RPCArg::Optional::NO, | {"wallet_name", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The name for the new wallet. If this is a path, the wallet will " | "The name for the new wallet. If this is a path, the wallet will " | ||||
▲ Show 20 Lines • Show All 1,659 Lines • ▼ Show 20 Lines | static const CRPCCommand commands[] = { | ||||
{ "wallet", "loadwallet", loadwallet, {"filename"} }, | { "wallet", "loadwallet", loadwallet, {"filename"} }, | ||||
{ "wallet", "lockunspent", lockunspent, {"unlock","transactions"} }, | { "wallet", "lockunspent", lockunspent, {"unlock","transactions"} }, | ||||
{ "wallet", "rescanblockchain", rescanblockchain, {"start_height", "stop_height"} }, | { "wallet", "rescanblockchain", rescanblockchain, {"start_height", "stop_height"} }, | ||||
{ "wallet", "sendmany", sendmany, {"dummy","amounts","minconf","comment","subtractfeefrom"} }, | { "wallet", "sendmany", sendmany, {"dummy","amounts","minconf","comment","subtractfeefrom"} }, | ||||
{ "wallet", "sendtoaddress", sendtoaddress, {"address","amount","comment","comment_to","subtractfeefromamount"} }, | { "wallet", "sendtoaddress", sendtoaddress, {"address","amount","comment","comment_to","subtractfeefromamount"} }, | ||||
{ "wallet", "sethdseed", sethdseed, {"newkeypool","seed"} }, | { "wallet", "sethdseed", sethdseed, {"newkeypool","seed"} }, | ||||
{ "wallet", "setlabel", setlabel, {"address","label"} }, | { "wallet", "setlabel", setlabel, {"address","label"} }, | ||||
{ "wallet", "settxfee", settxfee, {"amount"} }, | { "wallet", "settxfee", settxfee, {"amount"} }, | ||||
{ "wallet", "setwalletflag", setwalletflag, {"flag","value"} }, | |||||
{ "wallet", "signmessage", signmessage, {"address","message"} }, | { "wallet", "signmessage", signmessage, {"address","message"} }, | ||||
{ "wallet", "signrawtransactionwithwallet", signrawtransactionwithwallet, {"hextring","prevtxs","sighashtype"} }, | { "wallet", "signrawtransactionwithwallet", signrawtransactionwithwallet, {"hextring","prevtxs","sighashtype"} }, | ||||
{ "wallet", "unloadwallet", unloadwallet, {"wallet_name"} }, | { "wallet", "unloadwallet", unloadwallet, {"wallet_name"} }, | ||||
{ "wallet", "walletcreatefundedpsbt", walletcreatefundedpsbt, {"inputs","outputs","locktime","options","bip32derivs"} }, | { "wallet", "walletcreatefundedpsbt", walletcreatefundedpsbt, {"inputs","outputs","locktime","options","bip32derivs"} }, | ||||
{ "wallet", "walletlock", walletlock, {} }, | { "wallet", "walletlock", walletlock, {} }, | ||||
{ "wallet", "walletpassphrase", walletpassphrase, {"passphrase","timeout"} }, | { "wallet", "walletpassphrase", walletpassphrase, {"passphrase","timeout"} }, | ||||
{ "wallet", "walletpassphrasechange", walletpassphrasechange, {"oldpassphrase","newpassphrase"} }, | { "wallet", "walletpassphrasechange", walletpassphrasechange, {"oldpassphrase","newpassphrase"} }, | ||||
{ "wallet", "walletprocesspsbt", walletprocesspsbt, {"psbt","sign","sighashtype","bip32derivs"} }, | { "wallet", "walletprocesspsbt", walletprocesspsbt, {"psbt","sign","sighashtype","bip32derivs"} }, | ||||
Show All 12 Lines |