From 1f6392fa832c835fb34fc6b09e717afe0d712870 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 17 Jan 2018 06:13:14 +1030 Subject: [PATCH] lightningd: --deprecated-api option to turn off deprecated APIs. This can be used for upgrades to make sure you're not using deprecated options, JSON commands, JSON fields, etc. Signed-off-by: Rusty Russell --- lightningd/jsonrpc.c | 8 ++++++++ lightningd/jsonrpc.h | 1 + lightningd/options.c | 5 +++++ lightningd/options.h | 3 +++ 4 files changed, 17 insertions(+) diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index a14346c4f..195f2f9ff 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -526,6 +527,13 @@ static void parse_request(struct json_connection *jcon, const jsmntok_t tok[]) jcon->buffer + method->start); return; } + if (cmd->deprecated && !deprecated_apis) { + command_fail(jcon->current, + "command '%.*s' is deprecated", + (int)(method->end - method->start), + jcon->buffer + method->start); + return; + } if (params->type != JSMN_ARRAY && params->type != JSMN_OBJECT) { command_fail(jcon->current, diff --git a/lightningd/jsonrpc.h b/lightningd/jsonrpc.h index b8a0d808b..149e942a6 100644 --- a/lightningd/jsonrpc.h +++ b/lightningd/jsonrpc.h @@ -53,6 +53,7 @@ struct json_command { const char *buffer, const jsmntok_t *params); const char *description; const char *help; + bool deprecated; }; struct json_result *null_response(const tal_t *ctx); diff --git a/lightningd/options.c b/lightningd/options.c index 40b738742..5138943fd 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -29,6 +29,8 @@ #include #include +bool deprecated_apis = true; + /* Tal wrappers for opt. */ static void *opt_allocfn(size_t size) { @@ -269,6 +271,9 @@ static void config_register_opts(struct lightningd *ld) ld, "Select the network parameters (bitcoin, testnet," " regtest, or litecoin)"); + opt_register_arg("--deprecated-apis", opt_set_bool_arg, opt_show_bool, + &deprecated_apis, + "Enable deprecated options, JSONRPC commands, fields, etc."); } #if DEVELOPER diff --git a/lightningd/options.h b/lightningd/options.h index 8794c7e87..97de34ea4 100644 --- a/lightningd/options.h +++ b/lightningd/options.h @@ -15,4 +15,7 @@ bool handle_opts(struct lightningd *ld, int argc, char *argv[]); /* Derive default color and alias from the pubkey. */ void setup_color_and_alias(struct lightningd *ld); + +/* Global to allow deprecated options. */ +extern bool deprecated_apis; #endif /* LIGHTNING_LIGHTNINGD_OPTIONS_H */