From 8f2e66089bb35cd3c54c838afa5f707bf7924a70 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 15 Mar 2016 17:08:40 +1030 Subject: [PATCH] daemon: add --bitcoin-datadir for bitcoin-cli. Signed-off-by: Rusty Russell --- daemon/bitcoind.c | 16 ++++++++++++---- daemon/bitcoind.h | 2 ++ daemon/lightningd.c | 3 +++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/daemon/bitcoind.c b/daemon/bitcoind.c index 9536c83bd..3960fcfc1 100644 --- a/daemon/bitcoind.c +++ b/daemon/bitcoind.c @@ -19,13 +19,21 @@ #define BITCOIN_CLI "bitcoin-cli" +char *bitcoin_datadir; + static char **gather_args(const tal_t *ctx, const char *cmd, va_list ap) { - size_t n = 2; - char **args = tal_arr(ctx, char *, n+1); + size_t n = 0; + char **args = tal_arr(ctx, char *, 1); - args[0] = BITCOIN_CLI; - args[1] = cast_const(char *, cmd); + args[n++] = BITCOIN_CLI; + tal_resize(&args, n + 1); + if (bitcoin_datadir) { + args[n++] = tal_fmt(args, "-datadir=%s", bitcoin_datadir); + tal_resize(&args, n + 1); + } + args[n++] = cast_const(char *, cmd); + tal_resize(&args, n + 1); while ((args[n] = va_arg(ap, char *)) != NULL) { args[n] = tal_strdup(args, args[n]); diff --git a/daemon/bitcoind.h b/daemon/bitcoind.h index 8ea198b2b..f6802020f 100644 --- a/daemon/bitcoind.h +++ b/daemon/bitcoind.h @@ -10,6 +10,8 @@ struct lightningd_state; struct ripemd160; struct bitcoin_tx; struct peer; +/* -datadir arg for bitcoin-cli. */ +extern char *bitcoin_datadir; void bitcoind_watch_addr(struct lightningd_state *dstate, const struct ripemd160 *redeemhash); diff --git a/daemon/lightningd.c b/daemon/lightningd.c index 6b5034f9d..edd49e46f 100644 --- a/daemon/lightningd.c +++ b/daemon/lightningd.c @@ -213,6 +213,9 @@ int main(int argc, char *argv[]) "Print this message."); opt_register_arg("--port", opt_set_uintval, NULL, &portnum, "Port to bind to (otherwise, dynamic port is used)"); + opt_register_arg("--bitcoin-datadir", opt_set_charp, NULL, + &bitcoin_datadir, + "-datadir arg for bitcoin-cli"); opt_register_logging(dstate->base_log); opt_register_version();