Skip to content

Commit

Permalink
dynamically generate string of network names
Browse files Browse the repository at this point in the history
  • Loading branch information
kallewoof committed Jul 19, 2019
1 parent bb30104 commit ad84897
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
8 changes: 8 additions & 0 deletions bitcoin/chainparams.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 6 additions & 0 deletions bitcoin/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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 changes: 3 additions & 3 deletions wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ad84897

Please sign in to comment.