Browse Source

plugin: Added .params.configuration to init call

This tells the plugin both the `lightning-dir` as well as the
`rpc-filename` to use to talk to `lightningd`. Prior to this they'd
had to guess.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
plugin-6
Christian Decker 6 years ago
parent
commit
be7674ed6c
  1. 2
      contrib/plugins/helloworld.py
  2. 2
      lightningd/lightningd.c
  3. 11
      lightningd/plugin.c
  4. 2
      lightningd/plugin.h
  5. 2
      lightningd/test/run-find_my_abspath.c

2
contrib/plugins/helloworld.py

@ -45,7 +45,7 @@ def json_getmanifest(request):
} }
def json_init(request, options): def json_init(request, options, configuration):
"""The main daemon is telling us the relevant cli options """The main daemon is telling us the relevant cli options
""" """
global greeting global greeting

2
lightningd/lightningd.c

@ -214,7 +214,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
*code. Here we initialize the context that will keep track and control *code. Here we initialize the context that will keep track and control
*the plugins. *the plugins.
*/ */
ld->plugins = plugins_new(ld, ld->log_book, ld->jsonrpc); ld->plugins = plugins_new(ld, ld->log_book, ld->jsonrpc, ld);
return ld; return ld;
} }

11
lightningd/plugin.c

@ -90,6 +90,7 @@ struct plugins {
struct jsonrpc *rpc; struct jsonrpc *rpc;
struct timers timers; struct timers timers;
struct lightningd *ld;
}; };
/* Represents a pending JSON-RPC request that was forwarded to a /* Represents a pending JSON-RPC request that was forwarded to a
@ -116,7 +117,7 @@ struct plugin_opt {
}; };
struct plugins *plugins_new(const tal_t *ctx, struct log_book *log_book, struct plugins *plugins_new(const tal_t *ctx, struct log_book *log_book,
struct jsonrpc *rpc) struct jsonrpc *rpc, struct lightningd *ld)
{ {
struct plugins *p; struct plugins *p;
p = tal(ctx, struct plugins); p = tal(ctx, struct plugins);
@ -125,6 +126,7 @@ struct plugins *plugins_new(const tal_t *ctx, struct log_book *log_book,
p->log = new_log(p, log_book, "plugin-manager"); p->log = new_log(p, log_book, "plugin-manager");
p->rpc = rpc; p->rpc = rpc;
timers_init(&p->timers, time_mono()); timers_init(&p->timers, time_mono());
p->ld = ld;
return p; return p;
} }
@ -825,6 +827,7 @@ static void plugin_config(struct plugin *plugin)
struct plugin_opt *opt; struct plugin_opt *opt;
const char *name; const char *name;
struct plugin_request *req; struct plugin_request *req;
struct lightningd *ld = plugin->plugins->ld;
/* No writer since we don't flush concurrently. */ /* No writer since we don't flush concurrently. */
req = plugin_request_new(plugin, "init", plugin_config_cb, plugin); req = plugin_request_new(plugin, "init", plugin_config_cb, plugin);
@ -839,6 +842,12 @@ static void plugin_config(struct plugin *plugin)
} }
json_object_end(req->stream); /* end of .params.options */ json_object_end(req->stream); /* end of .params.options */
/* Add .params.configuration */
json_object_start(req->stream, "configuration");
json_add_string(req->stream, "lightning-dir", ld->config_dir);
json_add_string(req->stream, "rpc-file", ld->rpc_filename);
json_object_end(req->stream);
json_object_end(req->stream); /* end of .params */ json_object_end(req->stream); /* end of .params */
plugin_request_queue(req); plugin_request_queue(req);

2
lightningd/plugin.h

@ -17,7 +17,7 @@ struct plugins;
* Create a new plugins context. * Create a new plugins context.
*/ */
struct plugins *plugins_new(const tal_t *ctx, struct log_book *log_book, struct plugins *plugins_new(const tal_t *ctx, struct log_book *log_book,
struct jsonrpc *rpc); struct jsonrpc *rpc, struct lightningd *ld);
/** /**
* Initialize the registered plugins. * Initialize the registered plugins.

2
lightningd/test/run-find_my_abspath.c

@ -140,7 +140,7 @@ void plugins_init(struct plugins *plugins UNNEEDED)
{ fprintf(stderr, "plugins_init called!\n"); abort(); } { fprintf(stderr, "plugins_init called!\n"); abort(); }
/* Generated stub for plugins_new */ /* Generated stub for plugins_new */
struct plugins *plugins_new(const tal_t *ctx UNNEEDED, struct log_book *log_book UNNEEDED, struct plugins *plugins_new(const tal_t *ctx UNNEEDED, struct log_book *log_book UNNEEDED,
struct jsonrpc *rpc UNNEEDED) struct jsonrpc *rpc UNNEEDED, struct lightningd *ld UNNEEDED)
{ fprintf(stderr, "plugins_new called!\n"); abort(); } { fprintf(stderr, "plugins_new called!\n"); abort(); }
/* Generated stub for register_opts */ /* Generated stub for register_opts */
void register_opts(struct lightningd *ld UNNEEDED) void register_opts(struct lightningd *ld UNNEEDED)

Loading…
Cancel
Save