From ad8489729edaa4cfba77a28ff1e688f811f8f4a0 Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Fri, 19 Jul 2019 11:37:33 +0900 Subject: [PATCH] dynamically generate string of network names --- bitcoin/chainparams.c | 8 ++++++++ bitcoin/chainparams.h | 6 ++++++ wallet/wallet.c | 6 +++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/bitcoin/chainparams.c b/bitcoin/chainparams.c index a244ed8678b3..678580337268 100644 --- a/bitcoin/chainparams.c +++ b/bitcoin/chainparams.c @@ -123,3 +123,11 @@ const struct chainparams *chainparams_by_bip173(const char *bip173_name) } return NULL; } + +const char *chainparams_get_network_names(const tal_t *ctx) +{ + char *networks_string = tal_strdup(ctx, networks[0].network_name); + for (size_t i = 1; i < ARRAY_SIZE(networks); ++i) + tal_append_fmt(&networks_string, ", %s", networks[i].network_name); + return networks_string; +} diff --git a/bitcoin/chainparams.h b/bitcoin/chainparams.h index 5fcfabb6cab2..01b0cef6c297 100644 --- a/bitcoin/chainparams.h +++ b/bitcoin/chainparams.h @@ -4,6 +4,7 @@ #include "config.h" #include #include +#include #include #include @@ -53,4 +54,9 @@ const struct chainparams *chainparams_by_bip173(const char *bip173_name); */ const struct chainparams *chainparams_by_chainhash(const struct bitcoin_blkid *chain_hash); +/** + * chainparams_get_network_names - Produce a comma-separated list of network names + */ +const char *chainparams_get_network_names(const tal_t *ctx); + #endif /* LIGHTNING_BITCOIN_CHAINPARAMS_H */ diff --git a/wallet/wallet.c b/wallet/wallet.c index 5def5da153ee..43a5ceb77df1 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -2239,12 +2239,12 @@ bool wallet_network_check(struct wallet *w, "match network blockchain hash: %s " "!= %s. " "Are you on the right network? " - "(--network={bitcoin, testnet, regtest, " - "litecoin or litecoin-testnet})", + "(--network={one of %s})", type_to_string(w, struct bitcoin_blkid, &chainhash), type_to_string(w, struct bitcoin_blkid, - &chainparams->genesis_blockhash)); + &chainparams->genesis_blockhash), + chainparams_get_network_names(tmpctx)); return false; } } else {