Skip to content

Commit

Permalink
feat: restructure plugin and options in listconfigs
Browse files Browse the repository at this point in the history
This will change the command `listconfigs` output in several ways:

 - remove duplicated "plugin" JSON output by replacing it with
 - a "plugins" substructure which maps plugin name to their options
 - adds "_cmd" to the strucuture which is the path of the plugin

Changelog-Changed: JSON-RPC: `listconfigs` now structures plugins and include their options
  • Loading branch information
m-schmoock committed Nov 21, 2019
1 parent 654faa6 commit 2973862
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
29 changes: 28 additions & 1 deletion lightningd/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <ccan/utf8/utf8.h>
#include <common/utils.h>
#include <common/version.h>
#include <libgen.h>
#include <lightningd/json.h>
#include <lightningd/notification.h>
#include <lightningd/options.h>
Expand Down Expand Up @@ -1086,9 +1087,35 @@ void json_add_opt_plugins(struct json_stream *response,
const struct plugins *plugins)
{
struct plugin *p;
struct plugin_opt *opt;
const char *opt_name;
const char *plugin_name;
char *plugin_ext;

/* we output 'plugins' and their config as substructure:
* "plugins" : { "name" -> { "param" : "value" }, ... } */
json_object_start(response, "plugins");
list_for_each(&plugins->plugins, p, list) {
json_add_string(response, "plugin", p->cmd);

/* guess a suitable plugin name: basename without extension */
plugin_name = tal_strdup(p, basename(p->cmd));
plugin_ext = strrchr(plugin_name, '.');
if (plugin_ext != NULL)
plugin_ext[0] = 0;
json_object_start(response, plugin_name);
tal_free(plugin_name);

json_add_string(response, "_cmd", p->cmd);
list_for_each(&p->plugin_opts, opt, list) {
/* Trim the `--` that we added before */
opt_name = opt->name + 2;
if (opt->value->as_str) {
json_add_string(response, opt_name, opt->value->as_str);
}
}
json_object_end(response);
}
json_object_end(response);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,12 +742,22 @@ def test_listconfigs(node_factory, bitcoind, chainparams):

# Test one at a time.
for c in configs.keys():
if c.startswith('#'):
if c.startswith('#') or c.startswith('plugins'):
continue
oneconfig = l1.rpc.listconfigs(config=c)
assert(oneconfig[c] == configs[c])


def test_listconfigs_plugins(node_factory, bitcoind, chainparams):
l1 = node_factory.get_node()

# assert that we have _cmd paths and a pay plugin
configs = l1.rpc.listconfigs()
assert configs['plugins'] and configs['plugins']['pay']
for p in configs['plugins'].keys():
assert configs['plugins'][p]['_cmd']


def test_multirpc(node_factory):
"""Test that we can do multiple RPC without waiting for response"""
l1 = node_factory.get_node()
Expand Down

0 comments on commit 2973862

Please sign in to comment.