From a594196c7ca67e8b56ca3c6f447fa1e0da29a573 Mon Sep 17 00:00:00 2001 From: trueptolemy <823220586@qq.com> Date: Sun, 30 Jun 2019 17:00:48 +0800 Subject: [PATCH] bitcoin-cli: rename bcli_args() to bcli_args_direct(), and also warp it in bcli_args() 1. bcli_args_direct() will be used in wait_for_bitcoind; At the beginning, we check if bitcoin-cli is running by "echo" command whitout any bitcoin_cli struction. If this first command fails, we need present the agrs gathered, like "-rpcuser", like "-rpcpassword". Related changes include: i) rename bcli_args() to bcli_args_direct(), and use 'const char **' as the paramater for bcli_args_direct(); ii) add a new function bcli_args() warpped on bcli_args_direct(), this warpping can reduce the large number of changes later in the file; 2. bcli_args() warpping on bcli_args_direct() is used like original. --- lightningd/bitcoind.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lightningd/bitcoind.c b/lightningd/bitcoind.c index b59e34392..f09859e01 100644 --- a/lightningd/bitcoind.c +++ b/lightningd/bitcoind.c @@ -111,24 +111,32 @@ static struct io_plan *output_init(struct io_conn *conn, struct bitcoin_cli *bcl static void next_bcli(struct bitcoind *bitcoind, enum bitcoind_prio prio); /* For printing: simple string of args. */ -static char *bcli_args(const tal_t *ctx, struct bitcoin_cli *bcli) +/* bcli_args_direct() will be used in wat_for_bitcoind(), where + * we send bitcoin-cli a "getblockchaininfo" command without + * struct bitcoin_cli */ +static char *bcli_args_direct(const tal_t *ctx, const char **args) { size_t i; - char *ret = tal_strdup(ctx, bcli->args[0]); + char *ret = tal_strdup(ctx, args[0]); - for (i = 1; bcli->args[i]; i++) { + for (i = 1; args[i]; i++) { ret = tal_strcat(ctx, take(ret), " "); - if (strstarts(bcli->args[i], "-rpcpassword")) { + if (strstarts(args[i], "-rpcpassword")) { ret = tal_strcat(ctx, take(ret), "-rpcpassword=..."); - } else if (strstarts(bcli->args[i], "-rpcuser")) { + } else if (strstarts(args[i], "-rpcuser")) { ret = tal_strcat(ctx, take(ret), "-rpcuser=..."); } else { - ret = tal_strcat(ctx, take(ret), bcli->args[i]); + ret = tal_strcat(ctx, take(ret), args[i]); } } return ret; } +static char *bcli_args(const tal_t *ctx, struct bitcoin_cli *bcli) +{ + return bcli_args_direct(ctx, bcli->args); +} + static void retry_bcli(struct bitcoin_cli *bcli) { list_add_tail(&bcli->bitcoind->pending[bcli->prio], &bcli->list);