mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
lightningd: listconfigs update, using configvars code.
listconfigs is convenient, but it doesn't handle multi-options well: it outputs an object with duplicate fields in this case (e.g. log-file), nor is it extensible to show more than raw values. However, listconfigs doesn't do what other list commands do (use a sub-object "configs") so we can put the new values under that. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Added: JSON-RPC: `listconfigs` now has `configs` subobject with more information about each config option.
This commit is contained in:
@@ -35,6 +35,226 @@ RETURN VALUE
|
|||||||
[comment]: # (GENERATE-FROM-SCHEMA-START)
|
[comment]: # (GENERATE-FROM-SCHEMA-START)
|
||||||
On success, an object is returned, containing:
|
On success, an object is returned, containing:
|
||||||
|
|
||||||
|
- **configs** (object, optional) *(added v23.08)*:
|
||||||
|
- **conf** (object, optional):
|
||||||
|
- **value\_str** (string): field from cmdline
|
||||||
|
- **source** (string): source of configuration setting (always "cmdline")
|
||||||
|
- **clear-plugins** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **disable-mpp** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **mainnet** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **regtest** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **signet** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **testnet** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **important-plugin** (object, optional):
|
||||||
|
- **values\_str** (array of strings):
|
||||||
|
- field from config or cmdline
|
||||||
|
- **sources** (array of strings):
|
||||||
|
- source of configuration setting
|
||||||
|
- **plugin** (object, optional):
|
||||||
|
- **values\_str** (array of strings):
|
||||||
|
- field from config or cmdline
|
||||||
|
- **sources** (array of strings):
|
||||||
|
- source of configuration setting
|
||||||
|
- **plugin-dir** (object, optional):
|
||||||
|
- **values\_str** (array of strings):
|
||||||
|
- field from config or cmdline
|
||||||
|
- **sources** (array of strings):
|
||||||
|
- source of configuration setting
|
||||||
|
- **lightning-dir** (object, optional):
|
||||||
|
- **value\_str** (string): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **network** (object, optional):
|
||||||
|
- **value\_str** (string): field from config or cmdline, or default (can also be changed by `testnet`, `signet`, `regtest` options!)
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **allow-deprecated-apis** (object, optional):
|
||||||
|
- **value\_bool** (boolean): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **rpc-file** (object, optional):
|
||||||
|
- **value\_str** (string): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **disable-plugin** (object, optional):
|
||||||
|
- **values\_str** (array of strings):
|
||||||
|
- field from config or cmdline
|
||||||
|
- **sources** (array of strings):
|
||||||
|
- source of configuration setting
|
||||||
|
- **always-use-proxy** (object, optional):
|
||||||
|
- **value\_bool** (boolean): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **daemon** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **wallet** (object, optional):
|
||||||
|
- **value\_str** (string): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **large-channels** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **experimental-dual-fund** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **experimental-onion-messages** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **experimental-offers** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **experimental-shutdown-wrong-funding** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **experimental-websocket-port** (object, optional):
|
||||||
|
- **value\_int** (u32): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **experimental-peer-storage** (object, optional) *(added v23.02)*:
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **database-upgrade** (object, optional):
|
||||||
|
- **value\_bool** (boolean): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **rgb** (object, optional):
|
||||||
|
- **value\_str** (hex): field from config or cmdline, or default (always 6 characters)
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **alias** (object, optional):
|
||||||
|
- **value\_str** (string): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **pid-file** (object, optional):
|
||||||
|
- **value\_str** (string): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **ignore-fee-limits** (object, optional):
|
||||||
|
- **value\_bool** (boolean): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **watchtime-blocks** (object, optional):
|
||||||
|
- **value\_int** (u32): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **max-locktime-blocks** (object, optional):
|
||||||
|
- **value\_int** (u32): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **funding-confirms** (object, optional):
|
||||||
|
- **value\_int** (u32): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **cltv-delta** (object, optional):
|
||||||
|
- **value\_int** (u32): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **cltv-final** (object, optional):
|
||||||
|
- **value\_int** (u32): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **commit-time** (object, optional):
|
||||||
|
- **value\_int** (u32): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **fee-base** (object, optional):
|
||||||
|
- **value\_int** (u32): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **rescan** (object, optional):
|
||||||
|
- **value\_int** (integer): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **fee-per-satoshi** (object, optional):
|
||||||
|
- **value\_int** (u32): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **max-concurrent-htlcs** (object, optional):
|
||||||
|
- **value\_int** (u32): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **htlc-minimum-msat** (object, optional):
|
||||||
|
- **value\_msat** (msat): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **htlc-maximum-msat** (object, optional):
|
||||||
|
- **value\_msat** (msat): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **max-dust-htlc-exposure-msat** (object, optional):
|
||||||
|
- **value\_msat** (msat): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **min-capacity-sat** (object, optional):
|
||||||
|
- **value\_int** (u64): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **addr** (object, optional):
|
||||||
|
- **values\_str** (array of strings):
|
||||||
|
- field from config or cmdline
|
||||||
|
- **sources** (array of strings):
|
||||||
|
- source of configuration setting
|
||||||
|
- **announce-addr** (object, optional):
|
||||||
|
- **values\_str** (array of strings):
|
||||||
|
- field from config or cmdline
|
||||||
|
- **sources** (array of strings):
|
||||||
|
- source of configuration setting
|
||||||
|
- **bind-addr** (object, optional):
|
||||||
|
- **values\_str** (array of strings):
|
||||||
|
- field from config or cmdline
|
||||||
|
- **sources** (array of strings):
|
||||||
|
- source of configuration setting
|
||||||
|
- **offline** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **autolisten** (object, optional):
|
||||||
|
- **value\_bool** (boolean): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **proxy** (object, optional):
|
||||||
|
- **value\_str** (string): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **disable-dns** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **announce-addr-discovered** (object, optional) *(added v23.02)*:
|
||||||
|
- **value\_str** (string): field from config or cmdline, or default (one of "true", "false", "auto")
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **announce-addr-discovered-port** (object, optional) *(added v23.02)*:
|
||||||
|
- **value\_int** (u32): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **encrypted-hsm** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **rpc-file-mode** (object, optional):
|
||||||
|
- **value\_str** (string): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **log-level** (object, optional):
|
||||||
|
- **value\_str** (string): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **log-prefix** (object, optional):
|
||||||
|
- **value\_str** (string): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **log-file** (object, optional):
|
||||||
|
- **values\_str** (array of strings):
|
||||||
|
- field from config or cmdline
|
||||||
|
- **sources** (array of strings):
|
||||||
|
- source of configuration setting
|
||||||
|
- **log-timestamps** (object, optional):
|
||||||
|
- **value\_bool** (boolean): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **force-feerates** (object, optional):
|
||||||
|
- **value\_str** (string): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **subdaemon** (object, optional):
|
||||||
|
- **values\_str** (array of strings):
|
||||||
|
- field from config or cmdline
|
||||||
|
- **sources** (array of strings):
|
||||||
|
- source of configuration setting
|
||||||
|
- **fetchinvoice-noconnect** (object, optional):
|
||||||
|
- **set** (boolean): `true` if set in config or cmdline
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **accept-htlc-tlv-types** (object, optional):
|
||||||
|
- **value\_str** (string): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **tor-service-password** (object, optional):
|
||||||
|
- **value\_str** (string): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **announce-addr-dns** (object, optional):
|
||||||
|
- **value\_bool** (boolean): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **require-confirmed-inputs** (object, optional):
|
||||||
|
- **value\_bool** (boolean): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
|
- **commit-fee** (object, optional):
|
||||||
|
- **value\_int** (u64): field from config or cmdline, or default
|
||||||
|
- **source** (string): source of configuration setting
|
||||||
- **# version** (string, optional): Special field indicating the current version
|
- **# version** (string, optional): Special field indicating the current version
|
||||||
- **plugins** (array of objects, optional):
|
- **plugins** (array of objects, optional):
|
||||||
- **path** (string): Full path of the plugin
|
- **path** (string): Full path of the plugin
|
||||||
@@ -55,7 +275,7 @@ On success, an object is returned, containing:
|
|||||||
- **bookkeeper-db** (string, optional): `bookkeeper-db` field from config or cmdline, or default
|
- **bookkeeper-db** (string, optional): `bookkeeper-db` field from config or cmdline, or default
|
||||||
- **always-use-proxy** (boolean, optional): `always-use-proxy` field from config or cmdline, or default
|
- **always-use-proxy** (boolean, optional): `always-use-proxy` field from config or cmdline, or default
|
||||||
- **daemon** (boolean, optional): `daemon` field from config or cmdline, or default
|
- **daemon** (boolean, optional): `daemon` field from config or cmdline, or default
|
||||||
- **wallet** (string, optional): `wallet` field from config or cmdline, or default
|
- **wallet** (string, optional): `wallet` field from config or cmdline default
|
||||||
- **large-channels** (boolean, optional): `large-channels` field from config or cmdline, or default
|
- **large-channels** (boolean, optional): `large-channels` field from config or cmdline, or default
|
||||||
- **experimental-dual-fund** (boolean, optional): `experimental-dual-fund` field from config or cmdline, or default
|
- **experimental-dual-fund** (boolean, optional): `experimental-dual-fund` field from config or cmdline, or default
|
||||||
- **experimental-onion-messages** (boolean, optional): `experimental-onion-messages` field from config or cmdline, or default
|
- **experimental-onion-messages** (boolean, optional): `experimental-onion-messages` field from config or cmdline, or default
|
||||||
@@ -226,4 +446,4 @@ RESOURCES
|
|||||||
|
|
||||||
Main web site: <https://github.com/ElementsProject/lightning>
|
Main web site: <https://github.com/ElementsProject/lightning>
|
||||||
|
|
||||||
[comment]: # ( SHA256STAMP:a0058065f618170918c09d1672d5800beeff01f0fd2d13914a4ec238398f30c3)
|
[comment]: # ( SHA256STAMP:c847cb106f78f616b3adfe506ef499c9228f3966a44e6164b9cf49e1cf67d417)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -683,7 +683,9 @@ int connectd_init(struct lightningd *ld)
|
|||||||
wireaddrs->u.allproto.is_websocket = false;
|
wireaddrs->u.allproto.is_websocket = false;
|
||||||
wireaddrs->u.allproto.port = ld->portnum;
|
wireaddrs->u.allproto.port = ld->portnum;
|
||||||
*listen_announce = ADDR_LISTEN_AND_ANNOUNCE;
|
*listen_announce = ADDR_LISTEN_AND_ANNOUNCE;
|
||||||
}
|
} else
|
||||||
|
/* Make it clear that autolisten is not active! */
|
||||||
|
ld->autolisten = false;
|
||||||
|
|
||||||
msg = towire_connectd_init(
|
msg = towire_connectd_init(
|
||||||
tmpctx, chainparams,
|
tmpctx, chainparams,
|
||||||
|
|||||||
@@ -628,7 +628,8 @@ static char *arg_log_prefix(const char *arg, struct log_book *log_book)
|
|||||||
static bool show_log_prefix(char *buf, size_t len, const struct log_book *log_book)
|
static bool show_log_prefix(char *buf, size_t len, const struct log_book *log_book)
|
||||||
{
|
{
|
||||||
strncpy(buf, log_book->prefix, len);
|
strncpy(buf, log_book->prefix, len);
|
||||||
return true;
|
/* Default is empty, so don't print that! */
|
||||||
|
return !streq(log_book->prefix, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int signalfds[2];
|
static int signalfds[2];
|
||||||
|
|||||||
@@ -1713,7 +1713,16 @@ static bool canon_bool(const char *val)
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_config(struct lightningd *ld,
|
static void check_literal(const char *name, const char *val)
|
||||||
|
{
|
||||||
|
if (streq(val, "true") || streq(val, "false"))
|
||||||
|
return;
|
||||||
|
if (!streq(val, "") && strspn(val, "-0123456789.") == strlen(val))
|
||||||
|
return;
|
||||||
|
errx(1, "Bad literal for %s: %s", name, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void add_config_deprecated(struct lightningd *ld,
|
||||||
struct json_stream *response,
|
struct json_stream *response,
|
||||||
const struct opt_table *opt,
|
const struct opt_table *opt,
|
||||||
const char *name, size_t len)
|
const char *name, size_t len)
|
||||||
@@ -1905,6 +1914,188 @@ static void add_config(struct lightningd *ld,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void json_add_source(struct json_stream *result,
|
||||||
|
const char *fieldname,
|
||||||
|
const struct configvar *cv)
|
||||||
|
{
|
||||||
|
const char *source;
|
||||||
|
|
||||||
|
if (!cv) {
|
||||||
|
source = "default";
|
||||||
|
} else {
|
||||||
|
source = NULL;
|
||||||
|
switch (cv->src) {
|
||||||
|
case CONFIGVAR_CMDLINE:
|
||||||
|
case CONFIGVAR_CMDLINE_SHORT:
|
||||||
|
source = "cmdline";
|
||||||
|
break;
|
||||||
|
case CONFIGVAR_EXPLICIT_CONF:
|
||||||
|
case CONFIGVAR_BASE_CONF:
|
||||||
|
case CONFIGVAR_NETWORK_CONF:
|
||||||
|
source = tal_fmt(tmpctx, "%s:%u", cv->file, cv->linenum);
|
||||||
|
break;
|
||||||
|
case CONFIGVAR_PLUGIN_START:
|
||||||
|
source = "pluginstart";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
json_add_string(result, fieldname, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *configval_fieldname(const struct opt_table *ot)
|
||||||
|
{
|
||||||
|
bool multi = (ot->type & OPT_MULTI);
|
||||||
|
if (ot->type & OPT_SHOWBOOL)
|
||||||
|
return multi ? "values_bool" : "value_bool";
|
||||||
|
if (ot->type & OPT_SHOWINT)
|
||||||
|
return multi ? "values_int" : "value_int";
|
||||||
|
if (ot->type & OPT_SHOWMSATS)
|
||||||
|
return multi ? "values_msat" : "value_msat";
|
||||||
|
return multi ? "values_str" : "value_str";
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CONFIG_SHOW_BUFSIZE 4096
|
||||||
|
|
||||||
|
static const char *get_opt_val(const struct opt_table *ot,
|
||||||
|
char buf[],
|
||||||
|
const struct configvar *cv)
|
||||||
|
{
|
||||||
|
if (ot->show == (void *)opt_show_charp) {
|
||||||
|
/* Don't truncate or quote! */
|
||||||
|
return *(char **)ot->u.carg;
|
||||||
|
}
|
||||||
|
if (ot->show) {
|
||||||
|
strcpy(buf + CONFIG_SHOW_BUFSIZE, "...");
|
||||||
|
if (ot->show(buf, CONFIG_SHOW_BUFSIZE, ot->u.carg))
|
||||||
|
return buf;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* For everything else we only display if it's set,
|
||||||
|
* BUT we check here to make sure you've handled
|
||||||
|
* everything! */
|
||||||
|
if (ot->cb_arg == (void *)opt_set_talstr
|
||||||
|
|| ot->cb_arg == (void *)opt_add_proxy_addr
|
||||||
|
|| ot->cb_arg == (void *)opt_force_feerates
|
||||||
|
|| ot->cb_arg == (void *)opt_set_accept_extra_tlv_types
|
||||||
|
|| ot->cb_arg == (void *)opt_set_websocket_port
|
||||||
|
|| ot->cb_arg == (void *)opt_add_plugin
|
||||||
|
|| ot->cb_arg == (void *)opt_add_plugin_dir
|
||||||
|
|| ot->cb_arg == (void *)opt_important_plugin
|
||||||
|
|| ot->cb_arg == (void *)opt_disable_plugin
|
||||||
|
|| ot->cb_arg == (void *)opt_add_addr
|
||||||
|
|| ot->cb_arg == (void *)opt_add_bind_addr
|
||||||
|
|| ot->cb_arg == (void *)opt_add_announce_addr
|
||||||
|
|| ot->cb_arg == (void *)opt_subdaemon
|
||||||
|
|| ot->cb_arg == (void *)opt_set_db_upgrade
|
||||||
|
|| ot->cb_arg == (void *)arg_log_to_file
|
||||||
|
#if DEVELOPER
|
||||||
|
|| ot->cb_arg == (void *)opt_subd_dev_disconnect
|
||||||
|
|| ot->cb_arg == (void *)opt_force_featureset
|
||||||
|
|| ot->cb_arg == (void *)opt_force_privkey
|
||||||
|
|| ot->cb_arg == (void *)opt_force_bip32_seed
|
||||||
|
|| ot->cb_arg == (void *)opt_force_channel_secrets
|
||||||
|
|| ot->cb_arg == (void *)opt_force_tmp_channel_id
|
||||||
|
#endif
|
||||||
|
|| is_restricted_print_if_nonnull(ot->cb_arg)) {
|
||||||
|
/* Only if set! */
|
||||||
|
if (cv)
|
||||||
|
return cv->optarg;
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Insert more decodes here! */
|
||||||
|
errx(1, "Unknown decode for %s", ot->names);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void json_add_configval(struct json_stream *result,
|
||||||
|
const char *fieldname,
|
||||||
|
const struct opt_table *ot,
|
||||||
|
const char *str)
|
||||||
|
{
|
||||||
|
if (ot->type & OPT_SHOWBOOL) {
|
||||||
|
json_add_bool(result, fieldname, canon_bool(str));
|
||||||
|
} else if (ot->type & (OPT_SHOWMSATS|OPT_SHOWINT)) {
|
||||||
|
check_literal(ot->names, str);
|
||||||
|
json_add_primitive(result, fieldname, str);
|
||||||
|
} else
|
||||||
|
json_add_string(result, fieldname, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Config vars can have multiple names ("--large-channels|--wumbo"), but first
|
||||||
|
* is preferred */
|
||||||
|
static void json_add_config(struct lightningd *ld,
|
||||||
|
struct json_stream *response,
|
||||||
|
bool always_include,
|
||||||
|
const struct opt_table *ot,
|
||||||
|
const char **names)
|
||||||
|
{
|
||||||
|
char buf[CONFIG_SHOW_BUFSIZE + sizeof("...")];
|
||||||
|
const char *val;
|
||||||
|
struct configvar *cv;
|
||||||
|
|
||||||
|
/* This tells us if they actually set the option */
|
||||||
|
cv = configvar_first(ld->configvars, names);
|
||||||
|
|
||||||
|
/* Ignore dev/hidden options (deprecated) unless they actually used it */
|
||||||
|
if (!cv
|
||||||
|
&& (ot->desc == opt_hidden || (ot->type & OPT_DEV))
|
||||||
|
&& !always_include) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ignore options which simply exit */
|
||||||
|
if (ot->type & OPT_EXITS)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ot->type & OPT_NOARG) {
|
||||||
|
json_object_start(response, names[0]);
|
||||||
|
json_add_bool(response, "set", cv != NULL);
|
||||||
|
json_add_source(response, "source", cv);
|
||||||
|
json_object_end(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(ot->type & OPT_HASARG);
|
||||||
|
|
||||||
|
/* FIXME: handle plugin options: either the default or what they set */
|
||||||
|
if (ot->cb_arg == (void *)plugin_opt_set)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ot->type & OPT_MULTI) {
|
||||||
|
json_object_start(response, names[0]);
|
||||||
|
json_array_start(response, configval_fieldname(ot));
|
||||||
|
while (cv) {
|
||||||
|
val = get_opt_val(ot, buf, cv);
|
||||||
|
json_add_configval(response, NULL, ot, val);
|
||||||
|
cv = configvar_next(ld->configvars, cv, names);
|
||||||
|
}
|
||||||
|
json_array_end(response);
|
||||||
|
|
||||||
|
/* Iterate again, for sources */
|
||||||
|
json_array_start(response, "sources");
|
||||||
|
for (cv = configvar_first(ld->configvars, names);
|
||||||
|
cv;
|
||||||
|
cv = configvar_next(ld->configvars, cv, names)) {
|
||||||
|
json_add_source(response, NULL, cv);
|
||||||
|
}
|
||||||
|
json_array_end(response);
|
||||||
|
json_object_end(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returns NULL if we don't want to print it */
|
||||||
|
val = get_opt_val(ot, buf, cv);
|
||||||
|
if (!val)
|
||||||
|
return;
|
||||||
|
|
||||||
|
json_object_start(response, names[0]);
|
||||||
|
json_add_configval(response, configval_fieldname(ot), ot, val);
|
||||||
|
json_add_source(response, "source", cv);
|
||||||
|
json_object_end(response);
|
||||||
|
}
|
||||||
|
|
||||||
static struct command_result *param_opt_config(struct command *cmd,
|
static struct command_result *param_opt_config(struct command *cmd,
|
||||||
const char *name,
|
const char *name,
|
||||||
const char *buffer,
|
const char *buffer,
|
||||||
@@ -1934,6 +2125,8 @@ static struct command_result *json_listconfigs(struct command *cmd,
|
|||||||
return command_param_failed();
|
return command_param_failed();
|
||||||
|
|
||||||
response = json_stream_success(cmd);
|
response = json_stream_success(cmd);
|
||||||
|
|
||||||
|
/* FIXME: Deprecate old output! */
|
||||||
if (!config)
|
if (!config)
|
||||||
json_add_string(response, "# version", version());
|
json_add_string(response, "# version", version());
|
||||||
|
|
||||||
@@ -1953,7 +2146,7 @@ static struct command_result *json_listconfigs(struct command *cmd,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!config || config == &opt_table[i]) {
|
if (!config || config == &opt_table[i]) {
|
||||||
add_config(cmd->ld, response, &opt_table[i],
|
add_config_deprecated(cmd->ld, response, &opt_table[i],
|
||||||
name+1, len-1);
|
name+1, len-1);
|
||||||
}
|
}
|
||||||
/* If we have more than one long name, first
|
/* If we have more than one long name, first
|
||||||
@@ -1961,6 +2154,37 @@ static struct command_result *json_listconfigs(struct command *cmd,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json_object_start(response, "configs");
|
||||||
|
for (size_t i = 0; i < opt_count; i++) {
|
||||||
|
unsigned int len;
|
||||||
|
const char *name;
|
||||||
|
const char **names;
|
||||||
|
|
||||||
|
/* FIXME: Print out comment somehow? */
|
||||||
|
if (opt_table[i].type == OPT_SUBTABLE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (config && config != &opt_table[i])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
names = tal_arr(tmpctx, const char *, 0);
|
||||||
|
for (name = first_name(opt_table[i].names, &len);
|
||||||
|
name;
|
||||||
|
name = next_name(name, &len)) {
|
||||||
|
/* Skips over first -, so just need to look for one */
|
||||||
|
if (name[0] != '-')
|
||||||
|
continue;
|
||||||
|
tal_arr_expand(&names,
|
||||||
|
tal_strndup(names, name+1, len-1));
|
||||||
|
}
|
||||||
|
/* We don't usually print dev or deprecated options, unless
|
||||||
|
* they explicitly ask, or they're set. */
|
||||||
|
json_add_config(cmd->ld, response, config != NULL,
|
||||||
|
&opt_table[i], names);
|
||||||
|
}
|
||||||
|
json_object_end(response);
|
||||||
|
|
||||||
return command_success(cmd, response);
|
return command_success(cmd, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -741,11 +741,16 @@ def test_listconfigs(node_factory, bitcoind, chainparams):
|
|||||||
|
|
||||||
# Test one at a time.
|
# Test one at a time.
|
||||||
for c in configs.keys():
|
for c in configs.keys():
|
||||||
if c.startswith('#') or c.startswith('plugins') or c == 'important-plugins':
|
if c.startswith('#') or c.startswith('plugins') or c == 'important-plugins' or c == 'configs':
|
||||||
continue
|
continue
|
||||||
oneconfig = l1.rpc.listconfigs(config=c)
|
oneconfig = l1.rpc.listconfigs(config=c)
|
||||||
assert(oneconfig[c] == configs[c])
|
assert(oneconfig[c] == configs[c])
|
||||||
|
|
||||||
|
# Test modern ones!
|
||||||
|
for c in configs['configs'].keys():
|
||||||
|
oneconfig = l1.rpc.listconfigs(config=c)['configs']
|
||||||
|
assert(oneconfig[c] == configs['configs'][c])
|
||||||
|
|
||||||
|
|
||||||
def test_listconfigs_plugins(node_factory, bitcoind, chainparams):
|
def test_listconfigs_plugins(node_factory, bitcoind, chainparams):
|
||||||
l1 = node_factory.get_node()
|
l1 = node_factory.get_node()
|
||||||
|
|||||||
Reference in New Issue
Block a user