Skip to content

Commit

Permalink
bitcoin/chainparams: add an utility to retrieve chainparams for all n…
Browse files Browse the repository at this point in the history
…etworks
  • Loading branch information
darosior committed Nov 28, 2019
1 parent a1f9645 commit 4ece097
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bitcoin/chainparams.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "chainparams.h"
#include <ccan/array_size/array_size.h>
#include <ccan/str/str.h>
#include <common/utils.h>
#include <string.h>

/* Version codes for BIP32 extended keys in libwally-core.
Expand Down Expand Up @@ -220,6 +221,14 @@ const struct chainparams *chainparams_for_network(const char *network_name)
return NULL;
}

const struct chainparams **chainparams_for_networks(const tal_t *ctx)
{
const struct chainparams **params = tal_arr(ctx, const struct chainparams*, 0);
for (size_t i = 0; i < ARRAY_SIZE(networks); i++)
tal_arr_expand(&params, &networks[i]);
return params;
}

const struct chainparams *chainparams_by_chainhash(const struct bitcoin_blkid *chain_hash)
{
for (size_t i = 0; i < ARRAY_SIZE(networks); i++) {
Expand Down
6 changes: 6 additions & 0 deletions bitcoin/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ struct chainparams {
*/
const struct chainparams *chainparams_for_network(const char *network_name);

/**
* chainparams_for_networks - Get blockchain parameters for all known networks,
* as a tal array.
*/
const struct chainparams **chainparams_for_networks(const tal_t *ctx);

/**
* chainparams_by_bip173 - Helper to get a network by its bip173 name
*
Expand Down

0 comments on commit 4ece097

Please sign in to comment.