From 930e2948018153a03aa430fcd5174d78f109cb2e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 6 Aug 2020 09:57:19 +0930 Subject: [PATCH] help: better handing of deprecated commands If allow-deprecated-apis=false, don't mention them at all (we already disallow calling them in that case). Otherwise, note that they're deprecated in the help msg. Signed-off-by: Rusty Russell --- lightningd/jsonrpc.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index eda944215..97577cd58 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -321,8 +321,13 @@ static void json_add_help_command(struct command *cmd, { char *usage; - usage = tal_fmt(cmd, "%s %s", + /* If they disallow deprecated APIs, don't even list them */ + if (!deprecated_apis && json_command->deprecated) + return; + + usage = tal_fmt(cmd, "%s%s %s", json_command->name, + json_command->deprecated ? " (DEPRECATED!)" : "", strmap_get(&cmd->ld->jsonrpc->usagemap, json_command->name)); json_object_start(response, NULL); @@ -387,6 +392,11 @@ static struct command_result *json_help(struct command *cmd, "Unknown command '%.*s'", cmdtok->end - cmdtok->start, buffer + cmdtok->start); + if (!deprecated_apis && one_cmd->deprecated) + return command_fail(cmd, JSONRPC2_METHOD_NOT_FOUND, + "Deprecated command '%.*s'", + json_tok_full_len(cmdtok), + json_tok_full(buffer, cmdtok)); } else one_cmd = NULL; @@ -839,9 +849,9 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[]) } if (c->json_cmd->deprecated && !deprecated_apis) { return command_fail(c, JSONRPC2_METHOD_NOT_FOUND, - "Command '%.*s' is deprecated", - method->end - method->start, - jcon->buffer + method->start); + "Command %.*s is deprecated", + json_tok_full_len(method), + json_tok_full(jcon->buffer, method)); } rpc_hook = tal(c, struct rpc_command_hook_payload);