From 4ece097eedaca652049e485f08009cfde8aa43c9 Mon Sep 17 00:00:00 2001 From: darosior Date: Thu, 28 Nov 2019 15:10:08 +0100 Subject: [PATCH] bitcoin/chainparams: add an utility to retrieve chainparams for all networks --- bitcoin/chainparams.c | 9 +++++++++ bitcoin/chainparams.h | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/bitcoin/chainparams.c b/bitcoin/chainparams.c index 39e689fb990c..6147524d3adf 100644 --- a/bitcoin/chainparams.c +++ b/bitcoin/chainparams.c @@ -1,6 +1,7 @@ #include "chainparams.h" #include #include +#include #include /* Version codes for BIP32 extended keys in libwally-core. @@ -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(¶ms, &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++) { diff --git a/bitcoin/chainparams.h b/bitcoin/chainparams.h index 2feca23a8e36..e041a79a1f9d 100644 --- a/bitcoin/chainparams.h +++ b/bitcoin/chainparams.h @@ -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 *