plugin: Tell the plugin which network we run on

The fundchannel plugin needs to know how to build a transaction, so we need to
tell it which chainparams to use. Also adds `chainparams` as a global, since
that seems to be the way to do things in plugins.
This commit is contained in:
Christian Decker
2019-09-17 13:03:11 +02:00
committed by Rusty Russell
parent 858b3f2b93
commit 14247283b2
3 changed files with 20 additions and 8 deletions

View File

@@ -1,3 +1,4 @@
#include <bitcoin/chainparams.h>
#include <ccan/err/err.h>
#include <ccan/intmap/intmap.h>
#include <ccan/json_out/json_out.h>
@@ -34,6 +35,8 @@ static size_t in_timer;
bool deprecated_apis;
const struct chainparams *chainparams;
struct plugin_timer {
struct timer timer;
struct command_result *(*cb)(void);
@@ -523,10 +526,10 @@ static struct command_result *handle_init(struct command *init_cmd,
void (*init)(struct plugin_conn *,
const char *buf, const jsmntok_t *))
{
const jsmntok_t *configtok, *rpctok, *dirtok, *opttok, *t;
const jsmntok_t *configtok, *rpctok, *dirtok, *opttok, *nettok, *t;
struct sockaddr_un addr;
size_t i;
char *dir;
char *dir, *network;
struct json_out *param_obj;
configtok = json_delve(buf, params, ".configuration");
@@ -537,6 +540,11 @@ static struct command_result *handle_init(struct command *init_cmd,
if (chdir(dir) != 0)
plugin_err("chdir to %s: %s", dir, strerror(errno));
nettok = json_delve(buf, configtok, ".network");
network = json_strdup(tmpctx, buf, nettok);
chainparams = chainparams_for_network(network);
is_elements = chainparams->is_elements;
rpctok = json_delve(buf, configtok, ".rpc-file");
rpc_conn.fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (rpctok->end - rpctok->start + 1 > sizeof(addr.sun_path))