Skip to content

Commit 866dafd

Browse files
committed
rpc: Make name_show take option for whether to error on expired names
1 parent 3915272 commit 866dafd

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/rpc/names.cpp

+19-4
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,15 @@ namespace
437437
UniValue
438438
name_show (const JSONRPCRequest& request)
439439
{
440-
bool allow_expired = DEFAULT_ALLOWEXPIRED;
440+
bool allow_expired_default = DEFAULT_ALLOWEXPIRED;
441441

442442
NameOptionsHelp optHelp;
443443
optHelp
444444
.withNameEncoding ()
445445
.withValueEncoding ()
446-
.withByHash ();
446+
.withByHash ()
447+
.withArg ("allowExpired", RPCArg::Type::BOOL, allow_expired_default ? "true" : "false",
448+
"Whether to throw error for expired names");
447449

448450
RPCHelpMan ("name_show",
449451
"\nLooks up the current data for the given name. Fails if the name doesn't exist.\n",
@@ -456,6 +458,7 @@ name_show (const JSONRPCRequest& request)
456458
.finish (),
457459
RPCExamples {
458460
HelpExampleCli ("name_show", "\"myname\"")
461+
+ HelpExampleCli ("name_show", R"("myname" '{"allowExpired": false}')")
459462
+ HelpExampleRpc ("name_show", "\"myname\"")
460463
}
461464
).Check (request);
@@ -470,6 +473,17 @@ name_show (const JSONRPCRequest& request)
470473
if (request.params.size () >= 2)
471474
options = request.params[1].get_obj ();
472475

476+
/* Parse and interpret the name_show-specific options. */
477+
RPCTypeCheckObj(options,
478+
{
479+
{"allowExpired", UniValueType(UniValue::VBOOL)},
480+
},
481+
true, false);
482+
483+
bool allow_expired = allow_expired_default;
484+
if (options.exists("allowExpired"))
485+
allow_expired = options["allowExpired"].get_bool();
486+
473487
const valtype name = GetNameForLookup (request.params[0], options);
474488

475489
CNameData data;
@@ -488,11 +502,12 @@ name_show (const JSONRPCRequest& request)
488502
UniValue name_object = getNameInfo(options, name, data, wallet);
489503
assert(!name_object["expired"].isNull());
490504
const bool is_expired = name_object["expired"].get_bool();
491-
if (is_expired && !allow_expired) {
505+
if (is_expired && !allow_expired)
506+
{
492507
std::ostringstream msg;
493508
msg << "name not found: " << EncodeNameForMessage(name);
494509
throw JSONRPCError(RPC_WALLET_ERROR, msg.str());
495-
}
510+
}
496511
return name_object;
497512
}
498513

0 commit comments

Comments
 (0)