Browse Source

dynamically generate string of network names

pull/2938/head
Karl-Johan Alm 6 years ago
committed by neil saitug
parent
commit
ff2bfe3bdb
  1. 8
      bitcoin/chainparams.c
  2. 6
      bitcoin/chainparams.h
  3. 6
      wallet/wallet.c

8
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;
}

6
bitcoin/chainparams.h

@ -4,6 +4,7 @@
#include "config.h"
#include <bitcoin/block.h>
#include <ccan/short_types/short_types.h>
#include <ccan/tal/str/str.h>
#include <common/amount.h>
#include <stdbool.h>
@ -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 */

6
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 {

Loading…
Cancel
Save