Skip to content

Commit 1d9ff8b

Browse files
endothermicdevShahanaFarooqui
authored andcommitted
reckless-rpc: read lightningdir and network from listconfigs
1 parent f69c4d6 commit 1d9ff8b

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

plugins/recklessrpc.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
#include <ccan/array_size/array_size.h>
66
#include <ccan/io/io.h>
77
#include <ccan/pipecmd/pipecmd.h>
8+
#include <ccan/str/str.h>
89
#include <ccan/tal/str/str.h>
910
#include <common/json_param.h>
1011
#include <common/json_parse_simple.h>
1112
#include <common/json_stream.h>
13+
#include <common/memleak.h>
1214
#include <errno.h>
1315
#include <plugins/libplugin.h>
1416
#include <signal.h>
@@ -27,6 +29,12 @@ struct reckless {
2729
pid_t pid;
2830
};
2931

32+
struct lconfig {
33+
char *lightningdir;
34+
char *config;
35+
char *network;
36+
} lconfig;
37+
3038
static struct io_plan *read_more(struct io_conn *conn, struct reckless *rkls)
3139
{
3240
rkls->stdout_read += rkls->stdout_new;
@@ -116,6 +124,14 @@ static struct command_result *reckless_call(struct command *cmd,
116124
tal_arr_expand(&my_call, "reckless");
117125
tal_arr_expand(&my_call, "-v");
118126
tal_arr_expand(&my_call, "--json");
127+
tal_arr_expand(&my_call, "-l");
128+
tal_arr_expand(&my_call, lconfig.lightningdir);
129+
tal_arr_expand(&my_call, "--network");
130+
tal_arr_expand(&my_call, lconfig.network);
131+
if (lconfig.config) {
132+
tal_arr_expand(&my_call, "--conf");
133+
tal_arr_expand(&my_call, lconfig.config);
134+
}
119135
tal_arr_expand(&my_call, "search");
120136
tal_arr_expand(&my_call, (char *) call);
121137
tal_arr_expand(&my_call, NULL);
@@ -160,9 +176,24 @@ static const char *init(struct plugin *p,
160176
const jsmntok_t *config UNUSED)
161177
{
162178
plugin = p;
179+
rpc_scan(p, "listconfigs",
180+
take(json_out_obj(NULL, NULL, NULL)),
181+
"{configs:{"
182+
"conf?:{value_str:%},"
183+
"lightning-dir:{value_str:%},"
184+
"network:{value_str:%}"
185+
"}}",
186+
JSON_SCAN_TAL(p, json_strdup, &lconfig.config),
187+
JSON_SCAN_TAL(p, json_strdup, &lconfig.lightningdir),
188+
JSON_SCAN_TAL(p, json_strdup, &lconfig.network));
189+
/* These lightning config parameters need to stick around for each
190+
* reckless call. */
191+
if (lconfig.config)
192+
notleak(lconfig.config);
193+
notleak(lconfig.lightningdir);
194+
notleak(lconfig.network);
163195
plugin_log(p, LOG_DBG, "plugin initialized!");
164-
/* FIXME: TODO: scan for reckless config info */
165-
/* FIXME: TODO: assume default reckless config using ld config dets */
196+
plugin_log(p, LOG_DBG, "lightning-dir: %s", lconfig.lightningdir);
166197
return NULL;
167198
}
168199

0 commit comments

Comments
 (0)