mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
opts: Remove --regtest flag and pass chainparams to bitcoind
This commit is contained in:
parent
cf16b5faea
commit
843e21826a
@ -30,18 +30,9 @@ static char **gather_args(struct bitcoind *bitcoind,
|
|||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
char **args = tal_arr(ctx, char *, 3);
|
char **args = tal_arr(ctx, char *, 3);
|
||||||
|
|
||||||
args[n++] = BITCOIN_CLI;
|
args[n++] = bitcoind->chainparams->cli;
|
||||||
switch (bitcoind->testmode) {
|
args[n++] = bitcoind->chainparams->cli_args;
|
||||||
case BITCOIND_REGTEST:
|
|
||||||
args[n++] = "-regtest=1";
|
|
||||||
break;
|
|
||||||
case BITCOIND_TESTNET:
|
|
||||||
args[n++] = "-testnet=1";
|
|
||||||
break;
|
|
||||||
case BITCOIND_MAINNET:
|
|
||||||
args[n++] = "-testnet=0";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (bitcoind->datadir) {
|
if (bitcoind->datadir) {
|
||||||
args[n++] = tal_fmt(args, "-datadir=%s", bitcoind->datadir);
|
args[n++] = tal_fmt(args, "-datadir=%s", bitcoind->datadir);
|
||||||
tal_resize(&args, n + 1);
|
tal_resize(&args, n + 1);
|
||||||
@ -458,7 +449,8 @@ struct bitcoind *new_bitcoind(const tal_t *ctx, struct log *log)
|
|||||||
{
|
{
|
||||||
struct bitcoind *bitcoind = tal(ctx, struct bitcoind);
|
struct bitcoind *bitcoind = tal(ctx, struct bitcoind);
|
||||||
|
|
||||||
bitcoind->testmode = BITCOIND_TESTNET;
|
/* Use testnet by default, change later if we want another network */
|
||||||
|
bitcoind->chainparams = chainparams_for_network("testnet");
|
||||||
bitcoind->datadir = NULL;
|
bitcoind->datadir = NULL;
|
||||||
bitcoind->log = log;
|
bitcoind->log = log;
|
||||||
bitcoind->req_running = false;
|
bitcoind->req_running = false;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef LIGHTNING_DAEMON_BITCOIND_H
|
#ifndef LIGHTNING_DAEMON_BITCOIND_H
|
||||||
#define LIGHTNING_DAEMON_BITCOIND_H
|
#define LIGHTNING_DAEMON_BITCOIND_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include <bitcoin/chainparams.h>
|
||||||
#include <ccan/list/list.h>
|
#include <ccan/list/list.h>
|
||||||
#include <ccan/short_types/short_types.h>
|
#include <ccan/short_types/short_types.h>
|
||||||
#include <ccan/tal/tal.h>
|
#include <ccan/tal/tal.h>
|
||||||
@ -21,9 +22,6 @@ enum bitcoind_mode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct bitcoind {
|
struct bitcoind {
|
||||||
/* What mode are we in. */
|
|
||||||
enum bitcoind_mode testmode;
|
|
||||||
|
|
||||||
/* -datadir arg for bitcoin-cli. */
|
/* -datadir arg for bitcoin-cli. */
|
||||||
char *datadir;
|
char *datadir;
|
||||||
|
|
||||||
@ -35,6 +33,9 @@ struct bitcoind {
|
|||||||
|
|
||||||
/* Pending requests. */
|
/* Pending requests. */
|
||||||
struct list_head pending;
|
struct list_head pending;
|
||||||
|
|
||||||
|
/* What network are we on? */
|
||||||
|
const struct chainparams *chainparams;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bitcoind *new_bitcoind(const tal_t *ctx, struct log *log);
|
struct bitcoind *new_bitcoind(const tal_t *ctx, struct log *log);
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "secrets.h"
|
#include "secrets.h"
|
||||||
#include "timeout.h"
|
#include "timeout.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include <bitcoin/chainparams.h>
|
||||||
#include <ccan/container_of/container_of.h>
|
#include <ccan/container_of/container_of.h>
|
||||||
#include <ccan/err/err.h>
|
#include <ccan/err/err.h>
|
||||||
#include <ccan/io/io.h>
|
#include <ccan/io/io.h>
|
||||||
@ -82,6 +83,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
dstate->topology = new_topology(dstate, dstate->base_log);
|
dstate->topology = new_topology(dstate, dstate->base_log);
|
||||||
dstate->bitcoind = new_bitcoind(dstate, dstate->base_log);
|
dstate->bitcoind = new_bitcoind(dstate, dstate->base_log);
|
||||||
|
dstate->bitcoind->chainparams = chainparams_for_network("regtest");
|
||||||
|
|
||||||
/* Handle options and config; move to .lightningd */
|
/* Handle options and config; move to .lightningd */
|
||||||
register_opts(dstate);
|
register_opts(dstate);
|
||||||
|
@ -153,25 +153,18 @@ static void opt_show_u16(char buf[OPT_SHOW_LEN], const u16 *u)
|
|||||||
snprintf(buf, OPT_SHOW_LEN, "%u", *u);
|
snprintf(buf, OPT_SHOW_LEN, "%u", *u);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *opt_set_regtest(struct bitcoind *bitcoind)
|
|
||||||
{
|
|
||||||
bitcoind->testmode = BITCOIND_REGTEST;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *opt_set_network(const char *arg, struct lightningd *ld)
|
static char *opt_set_network(const char *arg, struct lightningd *ld)
|
||||||
{
|
{
|
||||||
ld->chainparams = chainparams_for_network(arg);
|
ld->chainparams = chainparams_for_network(arg);
|
||||||
if (!ld->chainparams)
|
if (!ld->chainparams)
|
||||||
return tal_fmt(NULL, "Unknown network name '%s'", arg);
|
return tal_fmt(NULL, "Unknown network name '%s'", arg);
|
||||||
|
ld->dstate.testnet = ld->chainparams->testnet;
|
||||||
|
ld->bitcoind->chainparams = ld->chainparams;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void config_register_opts(struct lightningd_state *dstate)
|
static void config_register_opts(struct lightningd_state *dstate)
|
||||||
{
|
{
|
||||||
opt_register_noarg("--bitcoind-regtest", opt_set_regtest,
|
|
||||||
dstate->bitcoind,
|
|
||||||
"Bitcoind is in regtest mode");
|
|
||||||
opt_register_arg("--locktime-blocks", opt_set_u32, opt_show_u32,
|
opt_register_arg("--locktime-blocks", opt_set_u32, opt_show_u32,
|
||||||
&dstate->config.locktime_blocks,
|
&dstate->config.locktime_blocks,
|
||||||
"Blocks before peer can unilaterally spend funds");
|
"Blocks before peer can unilaterally spend funds");
|
||||||
|
@ -112,7 +112,6 @@ setup_lightning()
|
|||||||
cat > $DIR1/config <<EOF
|
cat > $DIR1/config <<EOF
|
||||||
disable-irc
|
disable-irc
|
||||||
log-level=debug
|
log-level=debug
|
||||||
bitcoind-regtest
|
|
||||||
bitcoind-poll=5s
|
bitcoind-poll=5s
|
||||||
deadline-blocks=5
|
deadline-blocks=5
|
||||||
min-htlc-expiry=6
|
min-htlc-expiry=6
|
||||||
|
@ -130,7 +130,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
|
|||||||
ld->dstate.announce = NULL;
|
ld->dstate.announce = NULL;
|
||||||
ld->topology = ld->dstate.topology = new_topology(ld, ld->log);
|
ld->topology = ld->dstate.topology = new_topology(ld, ld->log);
|
||||||
ld->bitcoind = ld->dstate.bitcoind = new_bitcoind(ld, ld->log);
|
ld->bitcoind = ld->dstate.bitcoind = new_bitcoind(ld, ld->log);
|
||||||
ld->bitcoind->testmode = ld->dstate.testnet?BITCOIND_TESTNET:BITCOIND_MAINNET;
|
ld->chainparams = chainparams_for_network("testnet");
|
||||||
|
|
||||||
/* FIXME: Move into invoice daemon. */
|
/* FIXME: Move into invoice daemon. */
|
||||||
ld->dstate.invoices = invoices_init(&ld->dstate);
|
ld->dstate.invoices = invoices_init(&ld->dstate);
|
||||||
|
@ -214,7 +214,6 @@ class LightningD(TailableProc):
|
|||||||
'--lightning-dir={}'.format(lightning_dir),
|
'--lightning-dir={}'.format(lightning_dir),
|
||||||
'--port={}'.format(port),
|
'--port={}'.format(port),
|
||||||
'--disable-irc',
|
'--disable-irc',
|
||||||
'--bitcoind-regtest',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
self.cmd_line += ["--{}={}".format(k, v) for k, v in LIGHTNINGD_CONFIG.items()]
|
self.cmd_line += ["--{}={}".format(k, v) for k, v in LIGHTNINGD_CONFIG.items()]
|
||||||
|
Loading…
Reference in New Issue
Block a user