lightningd: remove deprecated_apis global, put into lightningd.

We usually have access to `ld`, so avoid the global.

The only place generic code needs it is for the json command struct,
and that already has accessors: add one for libplugin and lightningd
to tell it if deprecated apis are OK.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-07-06 17:06:50 +09:30
parent db7c608e2d
commit 0c4426a349
28 changed files with 80 additions and 59 deletions

View File

@@ -13,7 +13,6 @@
#include <common/utils.h> #include <common/utils.h>
#include <common/version.h> #include <common/version.h>
bool deprecated_apis = true;
int opt_exitcode = 1; int opt_exitcode = 1;
/* The regrettable globals */ /* The regrettable globals */
@@ -346,13 +345,6 @@ struct configvar **initial_config_opts(const tal_t *ctx,
/* Handle --version (and exit) here too */ /* Handle --version (and exit) here too */
opt_register_version(); opt_register_version();
/* For convenience, we set deprecated_apis and rpc_filename now, too */
clnopt_witharg("--allow-deprecated-apis",
OPT_EARLY|OPT_SHOWBOOL,
opt_set_bool_arg, opt_show_bool,
&deprecated_apis,
"Enable deprecated options, JSONRPC commands, fields, etc.");
/* Allow them to override rpc-file too. */ /* Allow them to override rpc-file too. */
*rpc_filename = default_rpcfile(ctx); *rpc_filename = default_rpcfile(ctx);
opt_register_early_arg("--rpc-file", opt_set_talstr, opt_show_charp, opt_register_early_arg("--rpc-file", opt_set_talstr, opt_show_charp,

View File

@@ -3,10 +3,6 @@
#include "config.h" #include "config.h"
#include <ccan/tal/tal.h> #include <ccan/tal/tal.h>
/* Put things we're going to get rid of behind this, so testers can catch
* them early. */
extern bool deprecated_apis;
/* Unless overridden, we exit with status 1 when option parsing fails */ /* Unless overridden, we exit with status 1 when option parsing fails */
extern int opt_exitcode; extern int opt_exitcode;

View File

@@ -36,6 +36,9 @@ command_fail_badparam(struct command *cmd,
/* Also caller supplied: is this invoked simply to get usage? */ /* Also caller supplied: is this invoked simply to get usage? */
bool command_usage_only(const struct command *cmd); bool command_usage_only(const struct command *cmd);
/* Do we allow deprecated apis? */
bool command_deprecated_apis(const struct command *cmd);
/* If so, this is called. */ /* If so, this is called. */
void command_set_usage(struct command *cmd, const char *usage); void command_set_usage(struct command *cmd, const char *usage);

View File

@@ -115,7 +115,8 @@ static struct command_result *parse_by_position(struct command *cmd,
return post_check(cmd, params); return post_check(cmd, params);
} }
static struct param *find_param(struct param *params, const char *start, static struct param *find_param(struct command *cmd,
struct param *params, const char *start,
size_t n) size_t n)
{ {
struct param *first = params; struct param *first = params;
@@ -125,11 +126,11 @@ static struct param *find_param(struct param *params, const char *start,
size_t arglen = strcspn(first->name, "|"); size_t arglen = strcspn(first->name, "|");
if (memeq(first->name, arglen, start, n)) if (memeq(first->name, arglen, start, n))
return first; return first;
if (deprecated_apis if (first->name[arglen]
&& first->name[arglen]
&& memeq(first->name + arglen + 1, && memeq(first->name + arglen + 1,
strlen(first->name + arglen + 1), strlen(first->name + arglen + 1),
start, n)) start, n)
&& command_deprecated_apis(cmd))
return first; return first;
first++; first++;
} }
@@ -146,7 +147,7 @@ static struct command_result *parse_by_name(struct command *cmd,
const jsmntok_t *t; const jsmntok_t *t;
json_for_each_obj(i, t, tokens) { json_for_each_obj(i, t, tokens) {
struct param *p = find_param(params, buffer + t->start, struct param *p = find_param(cmd, params, buffer + t->start,
t->end - t->start); t->end - t->start);
if (!p) { if (!p) {
if (!allow_extra) { if (!allow_extra) {

View File

@@ -15,6 +15,9 @@ struct command;
/* Generated stub for command_check_only */ /* Generated stub for command_check_only */
bool command_check_only(const struct command *cmd UNNEEDED) bool command_check_only(const struct command *cmd UNNEEDED)
{ fprintf(stderr, "command_check_only called!\n"); abort(); } { fprintf(stderr, "command_check_only called!\n"); abort(); }
/* Generated stub for command_deprecated_apis */
bool command_deprecated_apis(const struct command *cmd UNNEEDED)
{ fprintf(stderr, "command_deprecated_apis called!\n"); abort(); }
/* Generated stub for command_fail */ /* Generated stub for command_fail */
struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED, struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED,
const char *fmt UNNEEDED, ...) const char *fmt UNNEEDED, ...)

View File

@@ -47,6 +47,9 @@ struct amount_sat amount_tx_fee(u32 fee_per_kw UNNEEDED, size_t weight UNNEEDED)
/* Generated stub for command_check_only */ /* Generated stub for command_check_only */
bool command_check_only(const struct command *cmd UNNEEDED) bool command_check_only(const struct command *cmd UNNEEDED)
{ fprintf(stderr, "command_check_only called!\n"); abort(); } { fprintf(stderr, "command_check_only called!\n"); abort(); }
/* Generated stub for command_deprecated_apis */
bool command_deprecated_apis(const struct command *cmd UNNEEDED)
{ fprintf(stderr, "command_deprecated_apis called!\n"); abort(); }
/* Generated stub for command_fail */ /* Generated stub for command_fail */
struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED, struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED,
const char *fmt UNNEEDED, ...) const char *fmt UNNEEDED, ...)
@@ -58,8 +61,6 @@ void command_set_usage(struct command *cmd UNNEEDED, const char *usage UNNEEDED)
/* Generated stub for command_usage_only */ /* Generated stub for command_usage_only */
bool command_usage_only(const struct command *cmd UNNEEDED) bool command_usage_only(const struct command *cmd UNNEEDED)
{ fprintf(stderr, "command_usage_only called!\n"); abort(); } { fprintf(stderr, "command_usage_only called!\n"); abort(); }
/* Generated stub for deprecated_apis */
bool deprecated_apis;
/* Generated stub for fromwire */ /* Generated stub for fromwire */
const u8 *fromwire(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, void *copy UNNEEDED, size_t n UNNEEDED) const u8 *fromwire(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, void *copy UNNEEDED, size_t n UNNEEDED)
{ fprintf(stderr, "fromwire called!\n"); abort(); } { fprintf(stderr, "fromwire called!\n"); abort(); }

View File

@@ -40,8 +40,6 @@ struct command_result *command_fail(struct command *cmd,
/* Generated stub for command_filter_ptr */ /* Generated stub for command_filter_ptr */
struct json_filter **command_filter_ptr(struct command *cmd UNNEEDED) struct json_filter **command_filter_ptr(struct command *cmd UNNEEDED)
{ fprintf(stderr, "command_filter_ptr called!\n"); abort(); } { fprintf(stderr, "command_filter_ptr called!\n"); abort(); }
/* Generated stub for deprecated_apis */
bool deprecated_apis;
/* Generated stub for fromwire_tlv */ /* Generated stub for fromwire_tlv */
bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED, const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED,
@@ -64,6 +62,7 @@ enum command_mode {
struct command { struct command {
enum command_mode mode; enum command_mode mode;
bool deprecated_apis;
const char *usage; const char *usage;
}; };
@@ -82,6 +81,11 @@ bool command_check_only(const struct command *cmd)
return cmd->mode == CMD_CHECK; return cmd->mode == CMD_CHECK;
} }
bool command_deprecated_apis(const struct command *cmd)
{
return cmd->deprecated_apis;
}
struct json { struct json {
jsmntok_t *toks; jsmntok_t *toks;
char *buffer; char *buffer;
@@ -446,12 +450,12 @@ static void deprecated_rename(void)
NULL)); NULL));
assert(*u64 == 42); assert(*u64 == 42);
deprecated_apis = true; cmd->deprecated_apis = true;
j = json_parse(cmd, "{ 'old_u64': 42 }"); j = json_parse(cmd, "{ 'old_u64': 42 }");
assert(param(cmd, j->buffer, j->toks, assert(param(cmd, j->buffer, j->toks,
p_req("u64|old_u64", param_u64, &u64), p_req("u64|old_u64", param_u64, &u64),
NULL)); NULL));
deprecated_apis = false; cmd->deprecated_apis = false;
assert(!param(cmd, j->buffer, j->toks, assert(!param(cmd, j->buffer, j->toks,
p_req("u64|old_u64", param_u64, &u64), p_req("u64|old_u64", param_u64, &u64),
NULL)); NULL));

View File

@@ -309,7 +309,7 @@ static void estimatefees_callback(const char *buf, const jsmntok_t *toks,
"feerates"), "feerates"),
&floor); &floor);
} else { } else {
if (!deprecated_apis) if (!call->bitcoind->ld->deprecated_apis)
bitcoin_plugin_error(call->bitcoind, buf, resulttok, bitcoin_plugin_error(call->bitcoind, buf, resulttok,
"estimatefees", "estimatefees",
"missing fee_floor field"); "missing fee_floor field");

View File

@@ -711,7 +711,7 @@ static struct command_result *json_feerates(struct command *cmd,
if (rate) if (rate)
json_add_num(response, "penalty", json_add_num(response, "penalty",
feerate_to_style(rate, *style)); feerate_to_style(rate, *style));
if (deprecated_apis) { if (cmd->ld->deprecated_apis) {
rate = delayed_to_us_feerate(topo); rate = delayed_to_us_feerate(topo);
if (rate) if (rate)
json_add_num(response, "delayed_to_us", json_add_num(response, "delayed_to_us",

View File

@@ -271,7 +271,7 @@ static struct command_result *json_listconfigs(struct command *cmd,
response = json_stream_success(cmd); response = json_stream_success(cmd);
if (!deprecated_apis) if (!cmd->ld->deprecated_apis)
goto modern; goto modern;
if (!config) if (!config)

View File

@@ -699,7 +699,7 @@ int connectd_init(struct lightningd *ld)
ld->config.connection_timeout_secs, ld->config.connection_timeout_secs,
websocket_helper_path, websocket_helper_path,
ld->websocket_port, ld->websocket_port,
!deprecated_apis, !ld->deprecated_apis,
IFDEV(ld->dev_fast_gossip, false), IFDEV(ld->dev_fast_gossip, false),
IFDEV(ld->dev_disconnect_fd >= 0, false), IFDEV(ld->dev_disconnect_fd >= 0, false),
IFDEV(ld->dev_no_ping_timer, false)); IFDEV(ld->dev_no_ping_timer, false));

View File

@@ -82,7 +82,7 @@ static struct command_result *param_feerate_unchecked(struct command *cmd,
if (!json_tok_streq(buffer, tok, feerate_name(i))) if (!json_tok_streq(buffer, tok, feerate_name(i)))
continue; continue;
if (!deprecated_apis) if (!cmd->ld->deprecated_apis)
return command_fail_badparam(cmd, name, buffer, tok, return command_fail_badparam(cmd, name, buffer, tok,
"removed feerate by names"); "removed feerate by names");
switch (i) { switch (i) {

View File

@@ -258,7 +258,7 @@ static const u8 *hook_gives_failmsg(const tal_t *ctx,
return failmsg; return failmsg;
} }
if (!deprecated_apis) if (!ld->deprecated_apis)
return NULL; return NULL;
t = json_get_member(buffer, toks, "failure_code"); t = json_get_member(buffer, toks, "failure_code");

View File

@@ -332,7 +332,7 @@ static void json_add_help_command(struct command *cmd,
char *usage; char *usage;
/* If they disallow deprecated APIs, don't even list them */ /* If they disallow deprecated APIs, don't even list them */
if (!deprecated_apis && json_command->deprecated) if (!cmd->ld->deprecated_apis && json_command->deprecated)
return; return;
usage = tal_fmt(cmd, "%s%s %s", usage = tal_fmt(cmd, "%s%s %s",
@@ -400,7 +400,7 @@ static struct command_result *json_help(struct command *cmd,
return command_fail(cmd, JSONRPC2_METHOD_NOT_FOUND, return command_fail(cmd, JSONRPC2_METHOD_NOT_FOUND,
"Unknown command %s", "Unknown command %s",
cmdname); cmdname);
if (!deprecated_apis && one_cmd->deprecated) if (!cmd->ld->deprecated_apis && one_cmd->deprecated)
return command_fail(cmd, JSONRPC2_METHOD_NOT_FOUND, return command_fail(cmd, JSONRPC2_METHOD_NOT_FOUND,
"Deprecated command %s", "Deprecated command %s",
cmdname); cmdname);
@@ -959,7 +959,7 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[])
c, JSONRPC2_METHOD_NOT_FOUND, "Unknown command '%.*s'", c, JSONRPC2_METHOD_NOT_FOUND, "Unknown command '%.*s'",
method->end - method->start, jcon->buffer + method->start); method->end - method->start, jcon->buffer + method->start);
} }
if (c->json_cmd->deprecated && !deprecated_apis) { if (c->json_cmd->deprecated && !jcon->ld->deprecated_apis) {
return command_fail(c, JSONRPC2_METHOD_NOT_FOUND, return command_fail(c, JSONRPC2_METHOD_NOT_FOUND,
"Command %.*s is deprecated", "Command %.*s is deprecated",
json_tok_full_len(method), json_tok_full_len(method),
@@ -1265,6 +1265,11 @@ bool command_usage_only(const struct command *cmd)
return cmd->mode == CMD_USAGE; return cmd->mode == CMD_USAGE;
} }
bool command_deprecated_apis(const struct command *cmd)
{
return cmd->ld->deprecated_apis;
}
void command_set_usage(struct command *cmd, const char *usage TAKES) void command_set_usage(struct command *cmd, const char *usage TAKES)
{ {
usage = tal_strdup(cmd->ld, usage); usage = tal_strdup(cmd->ld, usage);

View File

@@ -255,6 +255,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
ld->pure_tor_setup = false; ld->pure_tor_setup = false;
ld->tor_service_password = NULL; ld->tor_service_password = NULL;
ld->websocket_port = 0; ld->websocket_port = 0;
ld->deprecated_apis = true;
/*~ This is initialized later, but the plugin loop examines this, /*~ This is initialized later, but the plugin loop examines this,
* so set it to NULL explicitly now. */ * so set it to NULL explicitly now. */

View File

@@ -106,6 +106,9 @@ struct lightningd {
/* The directory to find all the subdaemons. */ /* The directory to find all the subdaemons. */
const char *daemon_dir; const char *daemon_dir;
/* Are deprecated APIs enabled? */
bool deprecated_apis;
/* If we told to run in the background, this is our parent fd, otherwise /* If we told to run in the background, this is our parent fd, otherwise
* -1. */ * -1. */
int daemon_parent_fd; int daemon_parent_fd;

View File

@@ -198,6 +198,7 @@ void notify_invoice_creation(struct lightningd *ld, struct amount_msat *amount,
/* FIXME: Use outpoint here! */ /* FIXME: Use outpoint here! */
static void channel_opened_notification_serialize(struct json_stream *stream, static void channel_opened_notification_serialize(struct json_stream *stream,
struct lightningd *ld,
struct node_id *node_id, struct node_id *node_id,
struct amount_sat *funding_sat, struct amount_sat *funding_sat,
struct bitcoin_txid *funding_txid, struct bitcoin_txid *funding_txid,
@@ -207,7 +208,7 @@ static void channel_opened_notification_serialize(struct json_stream *stream,
json_add_node_id(stream, "id", node_id); json_add_node_id(stream, "id", node_id);
json_add_amount_sat_msat(stream, "funding_msat", *funding_sat); json_add_amount_sat_msat(stream, "funding_msat", *funding_sat);
json_add_txid(stream, "funding_txid", funding_txid); json_add_txid(stream, "funding_txid", funding_txid);
if (deprecated_apis) if (ld->deprecated_apis)
json_add_bool(stream, "funding_locked", channel_ready); json_add_bool(stream, "funding_locked", channel_ready);
json_add_bool(stream, "channel_ready", channel_ready); json_add_bool(stream, "channel_ready", channel_ready);
json_object_end(stream); json_object_end(stream);
@@ -221,6 +222,7 @@ void notify_channel_opened(struct lightningd *ld, struct node_id *node_id,
bool channel_ready) bool channel_ready)
{ {
void (*serialize)(struct json_stream *, void (*serialize)(struct json_stream *,
struct lightningd *,
struct node_id *, struct node_id *,
struct amount_sat *, struct amount_sat *,
struct bitcoin_txid *, struct bitcoin_txid *,
@@ -228,7 +230,7 @@ void notify_channel_opened(struct lightningd *ld, struct node_id *node_id,
struct jsonrpc_notification *n struct jsonrpc_notification *n
= jsonrpc_notification_start(NULL, channel_opened_notification_gen.topic); = jsonrpc_notification_start(NULL, channel_opened_notification_gen.topic);
serialize(n->stream, node_id, funding_sat, funding_txid, channel_ready); serialize(n->stream, ld, node_id, funding_sat, funding_txid, channel_ready);
jsonrpc_notification_end(n); jsonrpc_notification_end(n);
plugins_notify(ld->plugins, take(n)); plugins_notify(ld->plugins, take(n));
} }

View File

@@ -206,7 +206,7 @@ static char *opt_set_accept_extra_tlv_types(const char *arg,
{ {
char *ret, **elements = tal_strsplit(tmpctx, arg, ",", STR_NO_EMPTY); char *ret, **elements = tal_strsplit(tmpctx, arg, ",", STR_NO_EMPTY);
if (!deprecated_apis) if (!ld->deprecated_apis)
return "Please use --accept-htlc-tlv-type multiple times"; return "Please use --accept-htlc-tlv-type multiple times";
for (int i = 0; elements[i] != NULL; i++) { for (int i = 0; elements[i] != NULL; i++) {
ret = opt_add_accept_htlc_tlv(elements[i], ret = opt_add_accept_htlc_tlv(elements[i],
@@ -275,7 +275,7 @@ static char *opt_add_addr_withtype(const char *arg,
case ADDR_TYPE_TOR_V3: case ADDR_TYPE_TOR_V3:
switch (ala) { switch (ala) {
case ADDR_LISTEN: case ADDR_LISTEN:
if (!deprecated_apis) if (!ld->deprecated_apis)
return tal_fmt(tmpctx, return tal_fmt(tmpctx,
"Don't use --bind-addr=%s, use --announce-addr=%s", "Don't use --bind-addr=%s, use --announce-addr=%s",
arg, arg); arg, arg);
@@ -287,7 +287,7 @@ static char *opt_add_addr_withtype(const char *arg,
/* And we ignore it */ /* And we ignore it */
return NULL; return NULL;
case ADDR_LISTEN_AND_ANNOUNCE: case ADDR_LISTEN_AND_ANNOUNCE:
if (!deprecated_apis) if (!ld->deprecated_apis)
return tal_fmt(tmpctx, return tal_fmt(tmpctx,
"Don't use --addr=%s, use --announce-addr=%s", "Don't use --addr=%s, use --announce-addr=%s",
arg, arg); arg, arg);
@@ -332,7 +332,7 @@ static char *opt_add_addr_withtype(const char *arg,
return tal_fmt(tmpctx, return tal_fmt(tmpctx,
"Cannot announce sockets, try --bind-addr=%s", arg); "Cannot announce sockets, try --bind-addr=%s", arg);
case ADDR_LISTEN_AND_ANNOUNCE: case ADDR_LISTEN_AND_ANNOUNCE:
if (!deprecated_apis) if (!ld->deprecated_apis)
return tal_fmt(tmpctx, "Don't use --addr=%s, use --bind-addr=%s", return tal_fmt(tmpctx, "Don't use --addr=%s, use --bind-addr=%s",
arg, arg); arg, arg);
ala = ADDR_LISTEN; ala = ADDR_LISTEN;
@@ -1158,7 +1158,7 @@ static char *opt_set_websocket_port(const char *arg, struct lightningd *ld)
u32 port COMPILER_WANTS_INIT("9.3.0 -O2"); u32 port COMPILER_WANTS_INIT("9.3.0 -O2");
char *err; char *err;
if (!deprecated_apis) if (!ld->deprecated_apis)
return "--experimental-websocket-port been deprecated, use --bind=ws:..."; return "--experimental-websocket-port been deprecated, use --bind=ws:...";
err = opt_set_u32(arg, &port); err = opt_set_u32(arg, &port);
@@ -1248,7 +1248,7 @@ static char *opt_disable_ip_discovery(struct lightningd *ld)
static char *opt_set_announce_dns(const char *optarg, struct lightningd *ld) static char *opt_set_announce_dns(const char *optarg, struct lightningd *ld)
{ {
if (!deprecated_apis) if (!ld->deprecated_apis)
return "--announce-addr-dns has been deprecated, use --bind-addr=dns:..."; return "--announce-addr-dns has been deprecated, use --bind-addr=dns:...";
return opt_set_bool_arg(optarg, &ld->announce_dns); return opt_set_bool_arg(optarg, &ld->announce_dns);
} }
@@ -1260,6 +1260,12 @@ static void register_opts(struct lightningd *ld)
test_subdaemons_and_exit, test_subdaemons_and_exit,
ld, ld,
"Test that subdaemons can be run, then exit immediately"); "Test that subdaemons can be run, then exit immediately");
/* We need to know this even before we talk to plugins */
clnopt_witharg("--allow-deprecated-apis",
OPT_EARLY|OPT_SHOWBOOL,
opt_set_bool_arg, opt_show_bool,
&ld->deprecated_apis,
"Enable deprecated options, JSONRPC commands, fields, etc.");
/* Register plugins as an early args, so we can initialize them and have /* Register plugins as an early args, so we can initialize them and have
* them register more command line options */ * them register more command line options */
clnopt_witharg("--plugin", OPT_MULTI|OPT_EARLY, clnopt_witharg("--plugin", OPT_MULTI|OPT_EARLY,

View File

@@ -848,7 +848,7 @@ static struct channel *find_channel_for_htlc_add(struct lightningd *ld,
return channel; return channel;
/* We used to ignore scid: now all-zero means "any" */ /* We used to ignore scid: now all-zero means "any" */
if (!channel && (deprecated_apis || memeqzero(scid_or_alias, sizeof(*scid_or_alias)))) { if (!channel && (ld->deprecated_apis || memeqzero(scid_or_alias, sizeof(*scid_or_alias)))) {
list_for_each(&peer->channels, channel, list) { list_for_each(&peer->channels, channel, list) {
if (channel_can_add_htlc(channel)) { if (channel_can_add_htlc(channel)) {
return channel; return channel;

View File

@@ -1983,7 +1983,7 @@ static void json_add_peer(struct lightningd *ld,
/* Note: If !PEER_CONNECTED, peer may use different features on reconnect */ /* Note: If !PEER_CONNECTED, peer may use different features on reconnect */
json_add_hex_talarr(response, "features", p->their_features); json_add_hex_talarr(response, "features", p->their_features);
if (deprecated_apis) { if (ld->deprecated_apis) {
json_array_start(response, "channels"); json_array_start(response, "channels");
json_add_uncommitted_channel(response, p->uncommitted_channel, NULL); json_add_uncommitted_channel(response, p->uncommitted_channel, NULL);

View File

@@ -1014,7 +1014,7 @@ static bool htlc_accepted_hook_deserialize(struct htlc_accepted_hook_payload *re
buffer + failmsgtok->start); buffer + failmsgtok->start);
local_fail_in_htlc(hin, take(failmsg)); local_fail_in_htlc(hin, take(failmsg));
return false; return false;
} else if (deprecated_apis } else if (ld->deprecated_apis
&& (failcodetok = json_get_member(buffer, toks, && (failcodetok = json_get_member(buffer, toks,
"failure_code"))) { "failure_code"))) {
unsigned int failcode; unsigned int failcode;

View File

@@ -823,7 +823,7 @@ struct io_plan *plugin_stdout_conn_init(struct io_conn *conn,
static char *plugin_opt_check(struct plugin_opt *popt) static char *plugin_opt_check(struct plugin_opt *popt)
{ {
/* Warn them that this is deprecated */ /* Warn them that this is deprecated */
if (popt->deprecated && !deprecated_apis) if (popt->deprecated && !popt->plugin->plugins->ld->deprecated_apis)
return tal_fmt(tmpctx, "deprecated option (will be removed!)"); return tal_fmt(tmpctx, "deprecated option (will be removed!)");
return NULL; return NULL;
} }
@@ -847,7 +847,7 @@ static char *plugin_opt_bool_check(const char *arg, struct plugin_opt *popt)
{ {
/* FIXME: For some reason, '1' and '0' were allowed here? */ /* FIXME: For some reason, '1' and '0' were allowed here? */
if (streq(arg, "1") || streq(arg, "0")) { if (streq(arg, "1") || streq(arg, "0")) {
if (!deprecated_apis) if (!popt->plugin->plugins->ld->deprecated_apis)
return "boolean plugin arguments must be true or false"; return "boolean plugin arguments must be true or false";
} else { } else {
bool v; bool v;
@@ -937,6 +937,7 @@ static const char *plugin_opt_add(struct plugin *plugin, const char *buffer,
} }
popt = tal(plugin, struct plugin_opt); popt = tal(plugin, struct plugin_opt);
popt->plugin = plugin;
popt->name = tal_fmt(popt, "--%s", popt->name = tal_fmt(popt, "--%s",
json_strdup(tmpctx, buffer, nametok)); json_strdup(tmpctx, buffer, nametok));
name = popt->name + 2; name = popt->name + 2;
@@ -981,7 +982,7 @@ static const char *plugin_opt_add(struct plugin *plugin, const char *buffer,
/* We used to allow (ignore) anything, now make sure it's 'false' */ /* We used to allow (ignore) anything, now make sure it's 'false' */
if (!json_to_bool(buffer, defaulttok, &val) if (!json_to_bool(buffer, defaulttok, &val)
|| val != false) { || val != false) {
if (!deprecated_apis) if (!plugin->plugins->ld->deprecated_apis)
return tal_fmt(plugin, "%s type flag default must be 'false' not %.*s", return tal_fmt(plugin, "%s type flag default must be 'false' not %.*s",
popt->name, popt->name,
json_tok_full_len(defaulttok), json_tok_full_len(defaulttok),
@@ -1624,12 +1625,13 @@ static const char *plugin_parse_getmanifest_response(const char *buffer,
"Invalid nonnumericids: %.*s", "Invalid nonnumericids: %.*s",
json_tok_full_len(tok), json_tok_full_len(tok),
json_tok_full(buffer, tok)); json_tok_full(buffer, tok));
if (!deprecated_apis && !plugin->non_numeric_ids) if (!plugin->plugins->ld->deprecated_apis
&& !plugin->non_numeric_ids)
return tal_fmt(plugin, return tal_fmt(plugin,
"Plugin does not allow nonnumericids"); "Plugin does not allow nonnumericids");
} else } else
/* Default is false in deprecated mode */ /* Default is false in deprecated mode */
plugin->non_numeric_ids = !deprecated_apis; plugin->non_numeric_ids = !plugin->plugins->ld->deprecated_apis;
err = plugin_notifications_add(buffer, resulttok, plugin); err = plugin_notifications_add(buffer, resulttok, plugin);
if (!err) if (!err)
@@ -1837,7 +1839,8 @@ const char *plugin_send_getmanifest(struct plugin *p, const char *cmd_id)
p->stdin_conn = io_new_conn(p, stdinfd, plugin_stdin_conn_init, p); p->stdin_conn = io_new_conn(p, stdinfd, plugin_stdin_conn_init, p);
req = jsonrpc_request_start(p, "getmanifest", cmd_id, p->non_numeric_ids, req = jsonrpc_request_start(p, "getmanifest", cmd_id, p->non_numeric_ids,
p->log, NULL, plugin_manifest_cb, p); p->log, NULL, plugin_manifest_cb, p);
json_add_bool(req->stream, "allow-deprecated-apis", deprecated_apis); json_add_bool(req->stream, "allow-deprecated-apis",
p->plugins->ld->deprecated_apis);
jsonrpc_request_end(req); jsonrpc_request_end(req);
plugin_request_send(p, req); plugin_request_send(p, req);
p->plugin_state = AWAITING_GETMANIFEST_RESPONSE; p->plugin_state = AWAITING_GETMANIFEST_RESPONSE;
@@ -2204,7 +2207,7 @@ void json_add_opt_plugins_array(struct json_stream *response,
if (!list_empty(&p->plugin_opts)) { if (!list_empty(&p->plugin_opts)) {
json_add_plugin_options(response, "options", p, json_add_plugin_options(response, "options", p,
!deprecated_apis); !plugins->ld->deprecated_apis);
} }
json_object_end(response); json_object_end(response);
} }

View File

@@ -130,6 +130,7 @@ struct plugins {
* command line and passing them off to the plugin * command line and passing them off to the plugin
*/ */
struct plugin_opt { struct plugin_opt {
struct plugin *plugin;
/* off plugin->plugin_opts */ /* off plugin->plugin_opts */
struct list_node list; struct list_node list;
/* includes -- prefix! */ /* includes -- prefix! */

View File

@@ -191,8 +191,6 @@ void db_commit_transaction(struct db *db UNNEEDED)
/* Generated stub for delete_channel */ /* Generated stub for delete_channel */
void delete_channel(struct channel *channel STEALS UNNEEDED) void delete_channel(struct channel *channel STEALS UNNEEDED)
{ fprintf(stderr, "delete_channel called!\n"); abort(); } { fprintf(stderr, "delete_channel called!\n"); abort(); }
/* Generated stub for deprecated_apis */
bool deprecated_apis;
/* Generated stub for encode_scriptpubkey_to_addr */ /* Generated stub for encode_scriptpubkey_to_addr */
char *encode_scriptpubkey_to_addr(const tal_t *ctx UNNEEDED, char *encode_scriptpubkey_to_addr(const tal_t *ctx UNNEEDED,
const struct chainparams *chainparams UNNEEDED, const struct chainparams *chainparams UNNEEDED,

View File

@@ -16,8 +16,6 @@ void db_commit_transaction(struct db *db UNNEEDED)
/* Generated stub for delayed_to_us_feerate */ /* Generated stub for delayed_to_us_feerate */
u32 delayed_to_us_feerate(struct chain_topology *topo UNNEEDED) u32 delayed_to_us_feerate(struct chain_topology *topo UNNEEDED)
{ fprintf(stderr, "delayed_to_us_feerate called!\n"); abort(); } { fprintf(stderr, "delayed_to_us_feerate called!\n"); abort(); }
/* Generated stub for deprecated_apis */
bool deprecated_apis;
/* Generated stub for fatal */ /* Generated stub for fatal */
void fatal(const char *fmt UNNEEDED, ...) void fatal(const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "fatal called!\n"); abort(); } { fprintf(stderr, "fatal called!\n"); abort(); }

View File

@@ -500,6 +500,11 @@ bool command_usage_only(const struct command *cmd)
return cmd->usage_only; return cmd->usage_only;
} }
bool command_deprecated_apis(const struct command *cmd)
{
return deprecated_apis;
}
/* FIXME: would be good to support this! */ /* FIXME: would be good to support this! */
bool command_check_only(const struct command *cmd) bool command_check_only(const struct command *cmd)
{ {

View File

@@ -133,8 +133,6 @@ struct onionreply *create_onionreply(const tal_t *ctx UNNEEDED,
const struct secret *shared_secret UNNEEDED, const struct secret *shared_secret UNNEEDED,
const u8 *failure_msg UNNEEDED) const u8 *failure_msg UNNEEDED)
{ fprintf(stderr, "create_onionreply called!\n"); abort(); } { fprintf(stderr, "create_onionreply called!\n"); abort(); }
/* Generated stub for deprecated_apis */
bool deprecated_apis;
/* Generated stub for derive_channel_id */ /* Generated stub for derive_channel_id */
void derive_channel_id(struct channel_id *channel_id UNNEEDED, void derive_channel_id(struct channel_id *channel_id UNNEEDED,
const struct bitcoin_outpoint *outpoint UNNEEDED) const struct bitcoin_outpoint *outpoint UNNEEDED)

View File

@@ -93,7 +93,8 @@ static struct command_result *param_newaddr(struct command *cmd,
enum addrtype **addrtype) enum addrtype **addrtype)
{ {
*addrtype = tal(cmd, enum addrtype); *addrtype = tal(cmd, enum addrtype);
if (deprecated_apis && json_tok_streq(buffer, tok, "p2sh-segwit")) if (cmd->ld->deprecated_apis
&& json_tok_streq(buffer, tok, "p2sh-segwit"))
**addrtype = ADDR_P2SH_SEGWIT; **addrtype = ADDR_P2SH_SEGWIT;
else if (json_tok_streq(buffer, tok, "bech32")) else if (json_tok_streq(buffer, tok, "bech32"))
**addrtype = ADDR_BECH32; **addrtype = ADDR_BECH32;
@@ -133,7 +134,7 @@ static struct command_result *json_newaddr(struct command *cmd,
b32script = scriptpubkey_p2wpkh(tmpctx, &pubkey); b32script = scriptpubkey_p2wpkh(tmpctx, &pubkey);
if (*addrtype & ADDR_BECH32) if (*addrtype & ADDR_BECH32)
txfilter_add_scriptpubkey(cmd->ld->owned_txfilter, b32script); txfilter_add_scriptpubkey(cmd->ld->owned_txfilter, b32script);
if (deprecated_apis && (*addrtype & ADDR_P2SH_SEGWIT)) if (cmd->ld->deprecated_apis && (*addrtype & ADDR_P2SH_SEGWIT))
txfilter_add_scriptpubkey(cmd->ld->owned_txfilter, txfilter_add_scriptpubkey(cmd->ld->owned_txfilter,
scriptpubkey_p2sh(tmpctx, b32script)); scriptpubkey_p2sh(tmpctx, b32script));
@@ -147,7 +148,7 @@ static struct command_result *json_newaddr(struct command *cmd,
response = json_stream_success(cmd); response = json_stream_success(cmd);
if (*addrtype & ADDR_BECH32) if (*addrtype & ADDR_BECH32)
json_add_string(response, "bech32", bech32); json_add_string(response, "bech32", bech32);
if (deprecated_apis && (*addrtype & ADDR_P2SH_SEGWIT)) if (cmd->ld->deprecated_apis && (*addrtype & ADDR_P2SH_SEGWIT))
json_add_string(response, "p2sh-segwit", p2sh); json_add_string(response, "p2sh-segwit", p2sh);
return command_success(cmd, response); return command_success(cmd, response);
} }