diff --git a/common/configdir.c b/common/configdir.c index bff259c32..8446ba16a 100644 --- a/common/configdir.c +++ b/common/configdir.c @@ -13,7 +13,6 @@ #include #include -bool deprecated_apis = true; int opt_exitcode = 1; /* The regrettable globals */ @@ -346,13 +345,6 @@ struct configvar **initial_config_opts(const tal_t *ctx, /* Handle --version (and exit) here too */ 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. */ *rpc_filename = default_rpcfile(ctx); opt_register_early_arg("--rpc-file", opt_set_talstr, opt_show_charp, diff --git a/common/configdir.h b/common/configdir.h index d50a0d047..283b4ec9c 100644 --- a/common/configdir.h +++ b/common/configdir.h @@ -3,10 +3,6 @@ #include "config.h" #include -/* 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 */ extern int opt_exitcode; diff --git a/common/json_command.h b/common/json_command.h index 8586ba72d..8cbfc4db4 100644 --- a/common/json_command.h +++ b/common/json_command.h @@ -36,6 +36,9 @@ command_fail_badparam(struct command *cmd, /* Also caller supplied: is this invoked simply to get usage? */ 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. */ void command_set_usage(struct command *cmd, const char *usage); diff --git a/common/json_param.c b/common/json_param.c index 7aa217464..51dc8f79a 100644 --- a/common/json_param.c +++ b/common/json_param.c @@ -115,7 +115,8 @@ static struct command_result *parse_by_position(struct command *cmd, 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) { 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, "|"); if (memeq(first->name, arglen, start, n)) return first; - if (deprecated_apis - && first->name[arglen] + if (first->name[arglen] && memeq(first->name + arglen + 1, strlen(first->name + arglen + 1), - start, n)) + start, n) + && command_deprecated_apis(cmd)) return first; first++; } @@ -146,7 +147,7 @@ static struct command_result *parse_by_name(struct command *cmd, const jsmntok_t *t; 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); if (!p) { if (!allow_extra) { diff --git a/common/test/run-json_filter.c b/common/test/run-json_filter.c index 594eb00f7..44c772a2c 100644 --- a/common/test/run-json_filter.c +++ b/common/test/run-json_filter.c @@ -15,6 +15,9 @@ 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_apis */ +bool command_deprecated_apis(const struct command *cmd UNNEEDED) +{ fprintf(stderr, "command_deprecated_apis called!\n"); abort(); } /* Generated stub for command_fail */ struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED, const char *fmt UNNEEDED, ...) diff --git a/common/test/run-json_remove.c b/common/test/run-json_remove.c index 3b25bd141..e8d6b842f 100644 --- a/common/test/run-json_remove.c +++ b/common/test/run-json_remove.c @@ -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 */ bool command_check_only(const struct command *cmd UNNEEDED) { 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 */ struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code 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 */ bool command_usage_only(const struct command *cmd UNNEEDED) { fprintf(stderr, "command_usage_only called!\n"); abort(); } -/* Generated stub for deprecated_apis */ -bool deprecated_apis; /* Generated stub for fromwire */ const u8 *fromwire(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, void *copy UNNEEDED, size_t n UNNEEDED) { fprintf(stderr, "fromwire called!\n"); abort(); } diff --git a/common/test/run-param.c b/common/test/run-param.c index 26efb52bd..fffc19a16 100644 --- a/common/test/run-param.c +++ b/common/test/run-param.c @@ -40,8 +40,6 @@ struct command_result *command_fail(struct command *cmd, /* Generated stub for command_filter_ptr */ struct json_filter **command_filter_ptr(struct command *cmd UNNEEDED) { fprintf(stderr, "command_filter_ptr called!\n"); abort(); } -/* Generated stub for deprecated_apis */ -bool deprecated_apis; /* Generated stub for fromwire_tlv */ bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED, @@ -64,6 +62,7 @@ enum command_mode { struct command { enum command_mode mode; + bool deprecated_apis; const char *usage; }; @@ -82,6 +81,11 @@ bool command_check_only(const struct command *cmd) return cmd->mode == CMD_CHECK; } +bool command_deprecated_apis(const struct command *cmd) +{ + return cmd->deprecated_apis; +} + struct json { jsmntok_t *toks; char *buffer; @@ -446,12 +450,12 @@ static void deprecated_rename(void) NULL)); assert(*u64 == 42); - deprecated_apis = true; + cmd->deprecated_apis = true; j = json_parse(cmd, "{ 'old_u64': 42 }"); assert(param(cmd, j->buffer, j->toks, p_req("u64|old_u64", param_u64, &u64), NULL)); - deprecated_apis = false; + cmd->deprecated_apis = false; assert(!param(cmd, j->buffer, j->toks, p_req("u64|old_u64", param_u64, &u64), NULL)); diff --git a/lightningd/bitcoind.c b/lightningd/bitcoind.c index a9f76ac86..89b521955 100644 --- a/lightningd/bitcoind.c +++ b/lightningd/bitcoind.c @@ -309,7 +309,7 @@ static void estimatefees_callback(const char *buf, const jsmntok_t *toks, "feerates"), &floor); } else { - if (!deprecated_apis) + if (!call->bitcoind->ld->deprecated_apis) bitcoin_plugin_error(call->bitcoind, buf, resulttok, "estimatefees", "missing fee_floor field"); diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index ea3747aba..1449e7a0f 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -711,7 +711,7 @@ static struct command_result *json_feerates(struct command *cmd, if (rate) json_add_num(response, "penalty", feerate_to_style(rate, *style)); - if (deprecated_apis) { + if (cmd->ld->deprecated_apis) { rate = delayed_to_us_feerate(topo); if (rate) json_add_num(response, "delayed_to_us", diff --git a/lightningd/configs.c b/lightningd/configs.c index 8e3932366..65b325a22 100644 --- a/lightningd/configs.c +++ b/lightningd/configs.c @@ -271,7 +271,7 @@ static struct command_result *json_listconfigs(struct command *cmd, response = json_stream_success(cmd); - if (!deprecated_apis) + if (!cmd->ld->deprecated_apis) goto modern; if (!config) diff --git a/lightningd/connect_control.c b/lightningd/connect_control.c index 6be32373f..290bc1fd7 100644 --- a/lightningd/connect_control.c +++ b/lightningd/connect_control.c @@ -699,7 +699,7 @@ int connectd_init(struct lightningd *ld) ld->config.connection_timeout_secs, websocket_helper_path, ld->websocket_port, - !deprecated_apis, + !ld->deprecated_apis, IFDEV(ld->dev_fast_gossip, false), IFDEV(ld->dev_disconnect_fd >= 0, false), IFDEV(ld->dev_no_ping_timer, false)); diff --git a/lightningd/feerate.c b/lightningd/feerate.c index 93fcb3132..129dbcd58 100644 --- a/lightningd/feerate.c +++ b/lightningd/feerate.c @@ -82,7 +82,7 @@ static struct command_result *param_feerate_unchecked(struct command *cmd, if (!json_tok_streq(buffer, tok, feerate_name(i))) continue; - if (!deprecated_apis) + if (!cmd->ld->deprecated_apis) return command_fail_badparam(cmd, name, buffer, tok, "removed feerate by names"); switch (i) { diff --git a/lightningd/invoice.c b/lightningd/invoice.c index 01cfd64ea..cbe3e9102 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -258,7 +258,7 @@ static const u8 *hook_gives_failmsg(const tal_t *ctx, return failmsg; } - if (!deprecated_apis) + if (!ld->deprecated_apis) return NULL; t = json_get_member(buffer, toks, "failure_code"); diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index 2a4d26ded..930625875 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -332,7 +332,7 @@ static void json_add_help_command(struct command *cmd, char *usage; /* 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; 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, "Unknown command %s", cmdname); - if (!deprecated_apis && one_cmd->deprecated) + if (!cmd->ld->deprecated_apis && one_cmd->deprecated) return command_fail(cmd, JSONRPC2_METHOD_NOT_FOUND, "Deprecated command %s", cmdname); @@ -959,7 +959,7 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[]) c, JSONRPC2_METHOD_NOT_FOUND, "Unknown command '%.*s'", 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, "Command %.*s is deprecated", json_tok_full_len(method), @@ -1265,6 +1265,11 @@ bool command_usage_only(const struct command *cmd) 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) { usage = tal_strdup(cmd->ld, usage); diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index f64f3d2a6..ea4ecf12b 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -255,6 +255,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx) ld->pure_tor_setup = false; ld->tor_service_password = NULL; ld->websocket_port = 0; + ld->deprecated_apis = true; /*~ This is initialized later, but the plugin loop examines this, * so set it to NULL explicitly now. */ diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index 00cecbed1..403ea0740 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -106,6 +106,9 @@ struct lightningd { /* The directory to find all the subdaemons. */ 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 * -1. */ int daemon_parent_fd; diff --git a/lightningd/notification.c b/lightningd/notification.c index aa1550f87..1208ad7aa 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -198,6 +198,7 @@ void notify_invoice_creation(struct lightningd *ld, struct amount_msat *amount, /* FIXME: Use outpoint here! */ static void channel_opened_notification_serialize(struct json_stream *stream, + struct lightningd *ld, struct node_id *node_id, struct amount_sat *funding_sat, 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_amount_sat_msat(stream, "funding_msat", *funding_sat); 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, "channel_ready", channel_ready); json_object_end(stream); @@ -221,6 +222,7 @@ void notify_channel_opened(struct lightningd *ld, struct node_id *node_id, bool channel_ready) { void (*serialize)(struct json_stream *, + struct lightningd *, struct node_id *, struct amount_sat *, struct bitcoin_txid *, @@ -228,7 +230,7 @@ void notify_channel_opened(struct lightningd *ld, struct node_id *node_id, struct jsonrpc_notification *n = 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); plugins_notify(ld->plugins, take(n)); } diff --git a/lightningd/options.c b/lightningd/options.c index a366dd68e..9ae656bbb 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -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); - if (!deprecated_apis) + if (!ld->deprecated_apis) return "Please use --accept-htlc-tlv-type multiple times"; for (int i = 0; elements[i] != NULL; 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: switch (ala) { case ADDR_LISTEN: - if (!deprecated_apis) + if (!ld->deprecated_apis) return tal_fmt(tmpctx, "Don't use --bind-addr=%s, use --announce-addr=%s", arg, arg); @@ -287,7 +287,7 @@ static char *opt_add_addr_withtype(const char *arg, /* And we ignore it */ return NULL; case ADDR_LISTEN_AND_ANNOUNCE: - if (!deprecated_apis) + if (!ld->deprecated_apis) return tal_fmt(tmpctx, "Don't use --addr=%s, use --announce-addr=%s", arg, arg); @@ -332,7 +332,7 @@ static char *opt_add_addr_withtype(const char *arg, return tal_fmt(tmpctx, "Cannot announce sockets, try --bind-addr=%s", arg); 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", arg, arg); 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"); char *err; - if (!deprecated_apis) + if (!ld->deprecated_apis) return "--experimental-websocket-port been deprecated, use --bind=ws:..."; 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) { - if (!deprecated_apis) + if (!ld->deprecated_apis) return "--announce-addr-dns has been deprecated, use --bind-addr=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, ld, "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 * them register more command line options */ clnopt_witharg("--plugin", OPT_MULTI|OPT_EARLY, diff --git a/lightningd/pay.c b/lightningd/pay.c index 7749513ce..50c2f9110 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -848,7 +848,7 @@ static struct channel *find_channel_for_htlc_add(struct lightningd *ld, return channel; /* 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) { if (channel_can_add_htlc(channel)) { return channel; diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 832bfcccb..4788f4517 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1983,7 +1983,7 @@ static void json_add_peer(struct lightningd *ld, /* Note: If !PEER_CONNECTED, peer may use different features on reconnect */ json_add_hex_talarr(response, "features", p->their_features); - if (deprecated_apis) { + if (ld->deprecated_apis) { json_array_start(response, "channels"); json_add_uncommitted_channel(response, p->uncommitted_channel, NULL); diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index f188f943b..cc7f8582f 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -1014,7 +1014,7 @@ static bool htlc_accepted_hook_deserialize(struct htlc_accepted_hook_payload *re buffer + failmsgtok->start); local_fail_in_htlc(hin, take(failmsg)); return false; - } else if (deprecated_apis + } else if (ld->deprecated_apis && (failcodetok = json_get_member(buffer, toks, "failure_code"))) { unsigned int failcode; diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 66c86e014..fa7a3c91a 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -823,7 +823,7 @@ struct io_plan *plugin_stdout_conn_init(struct io_conn *conn, static char *plugin_opt_check(struct plugin_opt *popt) { /* 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 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? */ 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"; } else { 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->plugin = plugin; popt->name = tal_fmt(popt, "--%s", json_strdup(tmpctx, buffer, nametok)); 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' */ if (!json_to_bool(buffer, defaulttok, &val) || val != false) { - if (!deprecated_apis) + if (!plugin->plugins->ld->deprecated_apis) return tal_fmt(plugin, "%s type flag default must be 'false' not %.*s", popt->name, json_tok_full_len(defaulttok), @@ -1624,12 +1625,13 @@ static const char *plugin_parse_getmanifest_response(const char *buffer, "Invalid nonnumericids: %.*s", json_tok_full_len(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, "Plugin does not allow nonnumericids"); } else /* 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); 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); req = jsonrpc_request_start(p, "getmanifest", cmd_id, p->non_numeric_ids, 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); plugin_request_send(p, req); 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)) { json_add_plugin_options(response, "options", p, - !deprecated_apis); + !plugins->ld->deprecated_apis); } json_object_end(response); } diff --git a/lightningd/plugin.h b/lightningd/plugin.h index fc50cd457..49968ad2c 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -130,6 +130,7 @@ struct plugins { * command line and passing them off to the plugin */ struct plugin_opt { + struct plugin *plugin; /* off plugin->plugin_opts */ struct list_node list; /* includes -- prefix! */ diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index de34334ba..ef9a6595f 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -191,8 +191,6 @@ void db_commit_transaction(struct db *db UNNEEDED) /* Generated stub for delete_channel */ void delete_channel(struct channel *channel STEALS UNNEEDED) { fprintf(stderr, "delete_channel called!\n"); abort(); } -/* Generated stub for deprecated_apis */ -bool deprecated_apis; /* Generated stub for encode_scriptpubkey_to_addr */ char *encode_scriptpubkey_to_addr(const tal_t *ctx UNNEEDED, const struct chainparams *chainparams UNNEEDED, diff --git a/lightningd/test/run-jsonrpc.c b/lightningd/test/run-jsonrpc.c index 456af97ef..0950118ea 100644 --- a/lightningd/test/run-jsonrpc.c +++ b/lightningd/test/run-jsonrpc.c @@ -16,8 +16,6 @@ void db_commit_transaction(struct db *db UNNEEDED) /* Generated stub for delayed_to_us_feerate */ u32 delayed_to_us_feerate(struct chain_topology *topo UNNEEDED) { fprintf(stderr, "delayed_to_us_feerate called!\n"); abort(); } -/* Generated stub for deprecated_apis */ -bool deprecated_apis; /* Generated stub for fatal */ void fatal(const char *fmt UNNEEDED, ...) { fprintf(stderr, "fatal called!\n"); abort(); } diff --git a/plugins/libplugin.c b/plugins/libplugin.c index e66f09ca5..5879ba28e 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -500,6 +500,11 @@ bool command_usage_only(const struct command *cmd) return cmd->usage_only; } +bool command_deprecated_apis(const struct command *cmd) +{ + return deprecated_apis; +} + /* FIXME: would be good to support this! */ bool command_check_only(const struct command *cmd) { diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 82650d294..1792a2c85 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -133,8 +133,6 @@ struct onionreply *create_onionreply(const tal_t *ctx UNNEEDED, const struct secret *shared_secret UNNEEDED, const u8 *failure_msg UNNEEDED) { fprintf(stderr, "create_onionreply called!\n"); abort(); } -/* Generated stub for deprecated_apis */ -bool deprecated_apis; /* Generated stub for derive_channel_id */ void derive_channel_id(struct channel_id *channel_id UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED) diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 371e20978..3ad105ace 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -93,7 +93,8 @@ static struct command_result *param_newaddr(struct command *cmd, enum addrtype **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; else if (json_tok_streq(buffer, tok, "bech32")) **addrtype = ADDR_BECH32; @@ -133,7 +134,7 @@ static struct command_result *json_newaddr(struct command *cmd, b32script = scriptpubkey_p2wpkh(tmpctx, &pubkey); if (*addrtype & ADDR_BECH32) 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, scriptpubkey_p2sh(tmpctx, b32script)); @@ -147,7 +148,7 @@ static struct command_result *json_newaddr(struct command *cmd, response = json_stream_success(cmd); if (*addrtype & ADDR_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); return command_success(cmd, response); }