MCPcopy Create free account
hub / github.com/ElementsProject/elements / setwalletflag

Function setwalletflag

src/wallet/rpc/wallet.cpp:239–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

237}
238
239static RPCHelpMan setwalletflag()
240{
241 std::string flags = "";
242 for (auto& it : WALLET_FLAG_MAP)
243 if (it.second & MUTABLE_WALLET_FLAGS)
244 flags += (flags == "" ? "" : ", ") + it.first;
245
246 return RPCHelpMan{"setwalletflag",
247 "\nChange the state of the given wallet flag for a wallet.\n",
248 {
249 {"flag", RPCArg::Type::STR, RPCArg::Optional::NO, "The name of the flag to change. Current available flags: " + flags},
250 {"value", RPCArg::Type::BOOL, RPCArg::Default{true}, "The new state."},
251 },
252 RPCResult{
253 RPCResult::Type::OBJ, "", "",
254 {
255 {RPCResult::Type::STR, "flag_name", "The name of the flag that was modified"},
256 {RPCResult::Type::BOOL, "flag_state", "The new state of the flag"},
257 {RPCResult::Type::STR, "warnings", "Any warnings associated with the change"},
258 }
259 },
260 RPCExamples{
261 HelpExampleCli("setwalletflag", "avoid_reuse")
262 + HelpExampleRpc("setwalletflag", "\"avoid_reuse\"")
263 },
264 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
265{
266 std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
267 if (!pwallet) return NullUniValue;
268
269 std::string flag_str = request.params[0].get_str();
270 bool value = request.params[1].isNull() || request.params[1].get_bool();
271
272 if (!WALLET_FLAG_MAP.count(flag_str)) {
273 throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Unknown wallet flag: %s", flag_str));
274 }
275
276 auto flag = WALLET_FLAG_MAP.at(flag_str);
277
278 if (!(flag & MUTABLE_WALLET_FLAGS)) {
279 throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Wallet flag is immutable: %s", flag_str));
280 }
281
282 UniValue res(UniValue::VOBJ);
283
284 if (pwallet->IsWalletFlagSet(flag) == value) {
285 throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Wallet flag is already set to %s: %s", value ? "true" : "false", flag_str));
286 }
287
288 res.pushKV("flag_name", flag_str);
289 res.pushKV("flag_state", value);
290
291 if (value) {
292 pwallet->SetWalletFlag(flag);
293 } else {
294 pwallet->UnsetWalletFlag(flag);
295 }
296

Callers

nothing calls this directly

Calls 11

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
get_boolMethod · 0.80
countMethod · 0.80
IsWalletFlagSetMethod · 0.80
SetWalletFlagMethod · 0.80
UnsetWalletFlagMethod · 0.80
isNullMethod · 0.45
pushKVMethod · 0.45

Tested by

no test coverage detected