@@ -2650,6 +2650,76 @@ static UniValue loadwallet(const JSONRPCRequest& request)
2650
2650
return obj;
2651
2651
}
2652
2652
2653
+ static UniValue setwalletflag (const JSONRPCRequest& request)
2654
+ {
2655
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
2656
+ CWallet* const pwallet = wallet.get ();
2657
+
2658
+ if (!EnsureWalletIsAvailable (pwallet, request.fHelp )) {
2659
+ return NullUniValue;
2660
+ }
2661
+
2662
+ if (request.fHelp || request.params .size () < 1 || request.params .size () > 2 ) {
2663
+ std::string flags = " " ;
2664
+ for (auto & it : WALLET_FLAG_MAP)
2665
+ if (it.second & MUTABLE_WALLET_FLAGS)
2666
+ flags += (flags == " " ? " " : " , " ) + it.first ;
2667
+ throw std::runtime_error (
2668
+ RPCHelpMan{" setwalletflag" ,
2669
+ " \n Change the state of the given wallet flag for a wallet.\n " ,
2670
+ {
2671
+ {" flag" , RPCArg::Type::STR, RPCArg::Optional::NO, " The name of the flag to change. Current available flags: " + flags},
2672
+ {" value" , RPCArg::Type::BOOL, /* default */ " true" , " The new state." },
2673
+ },
2674
+ RPCResult{
2675
+ " {\n "
2676
+ " \" flag_name\" : string (string) The name of the flag that was modified\n "
2677
+ " \" flag_state\" : bool (bool) The new state of the flag\n "
2678
+ " \" warnings\" : string (string) Any warnings associated with the change\n "
2679
+ " }\n "
2680
+ },
2681
+ RPCExamples{
2682
+ HelpExampleCli (" setwalletflag" , " avoid_reuse" )
2683
+ + HelpExampleRpc (" setwalletflag" , " \" avoid_reuse\" " )
2684
+ },
2685
+ }.ToString ());
2686
+ }
2687
+
2688
+ std::string flag_str = request.params [0 ].get_str ();
2689
+ bool value = request.params [1 ].isNull () || request.params [1 ].get_bool ();
2690
+
2691
+ if (!WALLET_FLAG_MAP.count (flag_str)) {
2692
+ throw JSONRPCError (RPC_INVALID_PARAMETER, strprintf (" Unknown wallet flag: %s" , flag_str));
2693
+ }
2694
+
2695
+ auto flag = WALLET_FLAG_MAP.at (flag_str);
2696
+
2697
+ if (!(flag & MUTABLE_WALLET_FLAGS)) {
2698
+ throw JSONRPCError (RPC_INVALID_PARAMETER, strprintf (" Wallet flag is immutable: %s" , flag_str));
2699
+ }
2700
+
2701
+ UniValue res (UniValue::VOBJ);
2702
+
2703
+ if (pwallet->IsWalletFlagSet (flag) == value) {
2704
+ throw JSONRPCError (RPC_INVALID_PARAMETER, strprintf (" Wallet flag is already set to %s: %s" , value ? " true" : " false" , flag_str));
2705
+ }
2706
+
2707
+ res.pushKV (" flag_name" , flag_str);
2708
+ res.pushKV (" flag_state" , value);
2709
+
2710
+ if (value) {
2711
+ pwallet->SetWalletFlag (flag);
2712
+ } else {
2713
+ pwallet->UnsetWalletFlag (flag);
2714
+ }
2715
+
2716
+ if (flag && value && WALLET_FLAG_CAVEATS.count (flag)) {
2717
+ res.pushKV (" warnings" , WALLET_FLAG_CAVEATS.at (flag));
2718
+ }
2719
+
2720
+ return res;
2721
+ }
2722
+
2653
2723
static UniValue createwallet (const JSONRPCRequest& request)
2654
2724
{
2655
2725
const RPCHelpMan help{
@@ -4232,6 +4302,7 @@ static const CRPCCommand commands[] =
4232
4302
{ " wallet" , " sethdseed" , &sethdseed, {" newkeypool" ," seed" } },
4233
4303
{ " wallet" , " setlabel" , &setlabel, {" address" ," label" } },
4234
4304
{ " wallet" , " settxfee" , &settxfee, {" amount" } },
4305
+ { " wallet" , " setwalletflag" , &setwalletflag, {" flag" ," value" } },
4235
4306
{ " wallet" , " signmessage" , &signmessage, {" address" ," message" } },
4236
4307
{ " wallet" , " signrawtransactionwithwallet" , &signrawtransactionwithwallet, {" hexstring" ," prevtxs" ," sighashtype" } },
4237
4308
{ " wallet" , " unloadwallet" , &unloadwallet, {" wallet_name" } },
0 commit comments