mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
common: allow JSON-RPC parameters to specify deprecation versions.
This infrastructure is use by both libplugin and lightningd. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
2fe4ba01cd
commit
8e6eaf2511
9 changed files with 53 additions and 10 deletions
|
@ -27,6 +27,7 @@
|
|||
|
||||
struct param {
|
||||
const char *name;
|
||||
const char *depr_start, *depr_end;
|
||||
bool is_set;
|
||||
enum param_style style;
|
||||
param_cbx cbx;
|
||||
|
@ -36,6 +37,8 @@ struct param {
|
|||
static void param_add(struct param **params,
|
||||
const char *name,
|
||||
enum param_style style,
|
||||
const char *depr_start,
|
||||
const char *depr_end,
|
||||
param_cbx cbx, void *arg)
|
||||
{
|
||||
struct param last;
|
||||
|
@ -46,6 +49,8 @@ static void param_add(struct param **params,
|
|||
|
||||
last.is_set = false;
|
||||
last.name = name;
|
||||
last.depr_start = depr_start;
|
||||
last.depr_end = depr_end;
|
||||
last.style = style;
|
||||
last.cbx = cbx;
|
||||
last.arg = arg;
|
||||
|
@ -138,8 +143,14 @@ static struct param *find_param(struct command *cmd,
|
|||
struct param *last = first + tal_count(params);
|
||||
|
||||
while (first != last) {
|
||||
if (memeqstr(start, n, first->name))
|
||||
if (memeqstr(start, n, first->name)) {
|
||||
if (!command_deprecated_in_ok(cmd, first->name,
|
||||
first->depr_start,
|
||||
first->depr_end)) {
|
||||
return NULL;
|
||||
}
|
||||
return first;
|
||||
}
|
||||
first++;
|
||||
}
|
||||
return NULL;
|
||||
|
@ -301,7 +312,8 @@ const char *param_subcommand(struct command *cmd, const char *buffer,
|
|||
const char *arg, **names = tal_arr(tmpctx, const char *, 1);
|
||||
const char *subcmd;
|
||||
|
||||
param_add(¶ms, "subcommand", PARAM_REQUIRED, (void *)param_string, &subcmd);
|
||||
param_add(¶ms, "subcommand", PARAM_REQUIRED, NULL, NULL,
|
||||
(void *)param_string, &subcmd);
|
||||
names[0] = name;
|
||||
va_start(ap, name);
|
||||
while ((arg = va_arg(ap, const char *)) != NULL)
|
||||
|
@ -347,13 +359,15 @@ static bool param_core(struct command *cmd,
|
|||
|
||||
while ((name = va_arg(ap, const char *)) != NULL) {
|
||||
enum param_style style = va_arg(ap, enum param_style);
|
||||
const char *depr_start = va_arg(ap, const char *);
|
||||
const char *depr_end = va_arg(ap, const char *);
|
||||
param_cbx cbx = va_arg(ap, param_cbx);
|
||||
void *arg = va_arg(ap, void *);
|
||||
if (streq(name, "")) {
|
||||
allow_extra = true;
|
||||
continue;
|
||||
}
|
||||
param_add(¶ms, name, style, cbx, arg);
|
||||
param_add(¶ms, name, style, depr_start, depr_end, cbx, arg);
|
||||
}
|
||||
|
||||
if (command_usage_only(cmd)) {
|
||||
|
|
|
@ -91,9 +91,10 @@ enum param_style {
|
|||
/*
|
||||
* Add a required parameter.
|
||||
*/
|
||||
#define p_req(name, cbx, arg) \
|
||||
#define p_req_depr(name, depr_start, depr_end, cbx, arg) \
|
||||
name"", \
|
||||
PARAM_REQUIRED, \
|
||||
(depr_start), (depr_end), \
|
||||
(param_cbx)(cbx), \
|
||||
(arg) + 0*sizeof((cbx)((struct command *)NULL, \
|
||||
(const char *)NULL, \
|
||||
|
@ -101,12 +102,15 @@ enum param_style {
|
|||
(const jsmntok_t *)NULL, \
|
||||
(arg)) == (struct command_result *)NULL)
|
||||
|
||||
#define p_req(name, cbx, arg) p_req_depr(name, NULL, NULL, (cbx), (arg))
|
||||
|
||||
/*
|
||||
* Add an optional parameter. *arg is set to NULL if it isn't found.
|
||||
*/
|
||||
#define p_opt(name, cbx, arg) \
|
||||
#define p_opt_depr(name, depr_start, depr_end, cbx, arg) \
|
||||
name"", \
|
||||
PARAM_OPTIONAL, \
|
||||
(depr_start), (depr_end), \
|
||||
(param_cbx)(cbx), \
|
||||
({ *arg = NULL; \
|
||||
(arg) + 0*sizeof((cbx)((struct command *)NULL, \
|
||||
|
@ -115,12 +119,15 @@ enum param_style {
|
|||
(const jsmntok_t *)NULL, \
|
||||
(arg)) == (struct command_result *)NULL); })
|
||||
|
||||
#define p_opt(name, cbx, arg) p_opt_depr(name, NULL, NULL, (cbx), (arg))
|
||||
|
||||
/*
|
||||
* Add an optional parameter. *arg is set to @def if it isn't found.
|
||||
*/
|
||||
#define p_opt_def(name, cbx, arg, def) \
|
||||
name"", \
|
||||
PARAM_OPTIONAL_WITH_DEFAULT, \
|
||||
NULL, NULL, \
|
||||
(param_cbx)(cbx), \
|
||||
({ (*arg) = tal((cmd), typeof(**arg)); \
|
||||
(**arg) = (def); \
|
||||
|
@ -136,6 +143,7 @@ enum param_style {
|
|||
#define p_opt_dev(name, cbx, arg, def) \
|
||||
name"", \
|
||||
PARAM_OPTIONAL_DEV_WITH_DEFAULT, \
|
||||
NULL, NULL, \
|
||||
(param_cbx)(cbx), \
|
||||
({ (*arg) = tal((cmd), typeof(**arg)); \
|
||||
(**arg) = (def); \
|
||||
|
@ -146,7 +154,7 @@ enum param_style {
|
|||
(arg)) == (struct command_result *)NULL); })
|
||||
|
||||
/* Special flag for 'check' which allows any parameters. */
|
||||
#define p_opt_any() "", PARAM_OPTIONAL, NULL, NULL
|
||||
#define p_opt_any() "", PARAM_OPTIONAL, NULL, NULL, NULL, NULL, NULL
|
||||
|
||||
/* All the helper routines. */
|
||||
struct amount_msat;
|
||||
|
|
|
@ -15,6 +15,12 @@ struct command;
|
|||
/* Generated stub for command_check_only */
|
||||
bool command_check_only(const struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "command_check_only called!\n"); abort(); }
|
||||
/* Generated stub for command_deprecated_in_ok */
|
||||
bool command_deprecated_in_ok(struct command *cmd UNNEEDED,
|
||||
const char *param UNNEEDED,
|
||||
const char *depr_start UNNEEDED,
|
||||
const char *depr_end UNNEEDED)
|
||||
{ fprintf(stderr, "command_deprecated_in_ok called!\n"); abort(); }
|
||||
/* Generated stub for command_dev_apis */
|
||||
bool command_dev_apis(const struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "command_dev_apis called!\n"); abort(); }
|
||||
|
|
|
@ -44,6 +44,12 @@ struct amount_sat amount_tx_fee(u32 fee_per_kw UNNEEDED, size_t weight UNNEEDED)
|
|||
/* Generated stub for command_check_only */
|
||||
bool command_check_only(const struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "command_check_only called!\n"); abort(); }
|
||||
/* Generated stub for command_deprecated_in_ok */
|
||||
bool command_deprecated_in_ok(struct command *cmd UNNEEDED,
|
||||
const char *param UNNEEDED,
|
||||
const char *depr_start UNNEEDED,
|
||||
const char *depr_end UNNEEDED)
|
||||
{ fprintf(stderr, "command_deprecated_in_ok called!\n"); abort(); }
|
||||
/* Generated stub for command_dev_apis */
|
||||
bool command_dev_apis(const struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "command_dev_apis called!\n"); abort(); }
|
||||
|
|
|
@ -48,6 +48,14 @@ struct command_result *command_fail(struct command *cmd,
|
|||
return &cmd_failed;
|
||||
}
|
||||
|
||||
bool command_deprecated_in_ok(struct command *cmd,
|
||||
const char *param,
|
||||
const char *depr_start,
|
||||
const char *depr_end)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for command_dev_apis */
|
||||
bool command_dev_apis(const struct command *cmd UNNEEDED)
|
||||
|
@ -386,7 +394,7 @@ static void add_members(struct param **params,
|
|||
}
|
||||
tal_append_fmt(obj, "\"%i\" : %i", i, i);
|
||||
tal_append_fmt(arr, "%i", i);
|
||||
param_add(params, name, true,
|
||||
param_add(params, name, true, NULL, NULL,
|
||||
typesafe_cb_preargs(struct command_result *, void **,
|
||||
param_number,
|
||||
&ints[i],
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <ccan/tal/str/str.h>
|
||||
#include <common/codex32.h>
|
||||
#include <common/configdir.h>
|
||||
#include <common/deprecation.h>
|
||||
#include <common/json_command.h>
|
||||
#include <common/json_filter.h>
|
||||
#include <common/json_param.h>
|
||||
|
|
|
@ -47,7 +47,7 @@ s64 db_get_intvar(struct db *db UNNEEDED, const char *varname UNNEEDED, s64 defv
|
|||
bool db_in_transaction(struct db *db UNNEEDED)
|
||||
{ fprintf(stderr, "db_in_transaction called!\n"); abort(); }
|
||||
/* Generated stub for deprecated_ok_ */
|
||||
bool deprecated_ok_(bool deprecated_apis UNNEEDED,
|
||||
bool deprecated_ok_(bool deprecated_apis UNNEEDED,
|
||||
const char *feature UNNEEDED,
|
||||
const char *start UNNEEDED,
|
||||
const char *end UNNEEDED,
|
||||
|
|
|
@ -33,7 +33,7 @@ void daemon_setup(const char *argv0 UNNEEDED,
|
|||
void (*backtrace_exit)(void))
|
||||
{ fprintf(stderr, "daemon_setup called!\n"); abort(); }
|
||||
/* Generated stub for deprecated_ok_ */
|
||||
bool deprecated_ok_(bool deprecated_apis UNNEEDED,
|
||||
bool deprecated_ok_(bool deprecated_apis UNNEEDED,
|
||||
const char *feature UNNEEDED,
|
||||
const char *start UNNEEDED,
|
||||
const char *end UNNEEDED,
|
||||
|
|
|
@ -39,7 +39,7 @@ void daemon_setup(const char *argv0 UNNEEDED,
|
|||
void (*backtrace_exit)(void))
|
||||
{ fprintf(stderr, "daemon_setup called!\n"); abort(); }
|
||||
/* Generated stub for deprecated_ok_ */
|
||||
bool deprecated_ok_(bool deprecated_apis UNNEEDED,
|
||||
bool deprecated_ok_(bool deprecated_apis UNNEEDED,
|
||||
const char *feature UNNEEDED,
|
||||
const char *start UNNEEDED,
|
||||
const char *end UNNEEDED,
|
||||
|
|
Loading…
Add table
Reference in a new issue