elements: Move from a global is_elements to a global chainparams

We now have a pointer to chainparams, that fails valgrind if we do anything
chain-specific before setting it.

Suggested-by: Rusty Russell <@rustyrussell>
This commit is contained in:
Christian Decker 2019-09-25 22:38:45 +02:00 committed by Rusty Russell
parent 378745391d
commit ef7a63d8f8
28 changed files with 70 additions and 42 deletions

View File

@ -387,7 +387,7 @@ struct bitcoin_tx *bitcoin_tx(const tal_t *ctx,
/* If we are constructing an elements transaction we need to
* explicitly add the fee as an extra output. So allocate one more
* than the outputs we need internally. */
if (is_elements)
if (chainparams->is_elements)
output_count += 1;
wally_tx_init_alloc(WALLY_TX_VERSION_2, 0, input_count, output_count,

View File

@ -5,7 +5,7 @@
# Begin! (passes gossipd-client fd)
msgtype,channel_init,1000
msgdata,channel_init,chain_hash,bitcoin_blkid,
msgdata,channel_init,chainparams,chainparams,
msgdata,channel_init,funding_txid,bitcoin_txid,
msgdata,channel_init,funding_txout,u16,
msgdata,channel_init,funding_satoshi,amount_sat,

1 #include <common/cryptomsg.h>
5 # Begin! (passes gossipd-client fd)
6 msgtype,channel_init,1000
7 msgdata,channel_init,chain_hash,bitcoin_blkid, msgdata,channel_init,chainparams,chainparams,
8 msgdata,channel_init,funding_txid,bitcoin_txid,
9 msgdata,channel_init,funding_txout,u16,
10 msgdata,channel_init,funding_satoshi,amount_sat,
11 msgdata,channel_init,minimum_depth,u32,

View File

@ -2944,7 +2944,7 @@ static void init_channel(struct peer *peer)
msg = wire_sync_read(tmpctx, MASTER_FD);
if (!fromwire_channel_init(peer, msg,
&peer->chain_hash,
&chainparams,
&funding_txid, &funding_txout,
&funding,
&minimum_depth,
@ -3002,7 +3002,9 @@ static void init_channel(struct peer *peer)
/* stdin == requests, 3 == peer, 4 = gossip, 5 = gossip_store, 6 = HSM */
per_peer_state_set_fds(peer->pps, 3, 4, 5);
is_elements = chainparams_by_chainhash(&peer->chain_hash)->is_elements;
is_elements = chainparams->is_elements;
peer->chain_hash = chainparams->genesis_blockhash;
status_debug("init %s: remote_per_commit = %s, old_remote_per_commit = %s"
" next_idx_local = %"PRIu64
" next_idx_remote = %"PRIu64

View File

@ -3,9 +3,8 @@
#include <common/per_peer_state.h>
# Begin! (passes peer fd, gossipd-client fd)
msgtype,closing_init,2001
msgdata,closing_init,chain_hash,chain_hash,
msgdata,closing_init,chainparams,chainparams,
msgdata,closing_init,pps,per_peer_state,
msgdata,closing_init,chain_hash,bitcoin_blkid,
msgdata,closing_init,funding_txid,bitcoin_txid,
msgdata,closing_init,funding_txout,u16,
msgdata,closing_init,funding_satoshi,amount_sat,

1 #include <common/cryptomsg.h>
3 #include <common/per_peer_state.h>
4 # Begin! (passes peer fd, gossipd-client fd)
5 msgtype,closing_init,2001
6 msgdata,closing_init,chain_hash,chain_hash, msgdata,closing_init,chainparams,chainparams,
7 msgdata,closing_init,pps,per_peer_state,
msgdata,closing_init,chain_hash,bitcoin_blkid,
8 msgdata,closing_init,funding_txid,bitcoin_txid,
9 msgdata,closing_init,funding_txout,u16,
10 msgdata,closing_init,funding_satoshi,amount_sat,

View File

@ -576,8 +576,6 @@ int main(int argc, char *argv[])
enum side whose_turn;
u8 *channel_reestablish;
struct secret last_remote_per_commit_secret;
struct bitcoin_blkid chain_hash;
const struct chainparams *chainparams;
subdaemon_setup(argc, argv);
@ -585,7 +583,7 @@ int main(int argc, char *argv[])
msg = wire_sync_read(tmpctx, REQ_FD);
if (!fromwire_closing_init(ctx, msg,
&chain_hash,
&chainparams,
&pps,
&funding_txid, &funding_txout,
&funding,
@ -611,8 +609,6 @@ int main(int argc, char *argv[])
/* stdin == requests, 3 == peer, 4 = gossip, 5 = gossip_store, 6 = hsmd */
per_peer_state_set_fds(pps, 3, 4, 5);
chainparams = chainparams_by_chainhash(&chain_hash);
is_elements = chainparams->is_elements;
status_debug("out = %s/%s",
type_to_string(tmpctx, struct amount_sat, &out[LOCAL]),

View File

@ -8,6 +8,8 @@ secp256k1_context *secp256k1_ctx;
const tal_t *tmpctx;
bool is_elements = false;
const struct chainparams *chainparams;
char *tal_hexstr(const tal_t *ctx, const void *data, size_t len)
{
char *str = tal_arr(ctx, char, hex_str_size(len));

View File

@ -13,6 +13,7 @@ extern secp256k1_context *secp256k1_ctx;
/* FIXME: Instead of using this as a global, we might want to pass it as
* context whenever we need it. The global var is just lazy... */
extern bool is_elements;
extern const struct chainparams *chainparams;
/* Allocate and fill in a hex-encoded string of this data. */
char *tal_hexstr(const tal_t *ctx, const void *data, size_t len);

View File

@ -4,7 +4,7 @@
# Initialize the gossip daemon.
msgtype,gossipctl_init,3000
msgdata,gossipctl_init,chain_hash,bitcoin_blkid,
msgdata,gossipctl_init,chainparams,chainparams,
msgdata,gossipctl_init,id,node_id,
msgdata,gossipctl_init,gflen,u16,
msgdata,gossipctl_init,globalfeatures,u8,gflen

Can't render this file because it has a wrong number of fields in line 6.

View File

@ -930,7 +930,7 @@ static struct io_plan *gossip_init(struct io_conn *conn,
bool dev_fast_gossip, dev_fast_gossip_prune;
if (!fromwire_gossipctl_init(daemon, msg,
&daemon->chain_hash,
&chainparams,
&daemon->id, &daemon->globalfeatures,
daemon->rgb,
daemon->alias,
@ -941,6 +941,7 @@ static struct io_plan *gossip_init(struct io_conn *conn,
master_badmsg(WIRE_GOSSIPCTL_INIT, msg);
}
daemon->chain_hash = chainparams->genesis_blockhash;
daemon->rstate = new_routing_state(daemon,
chainparams_by_chainhash(&daemon->chain_hash),
&daemon->id,

View File

@ -9,7 +9,7 @@ msgdata,hsmstatus_client_bad_request,msg,u8,len
# Start the HSM.
msgtype,hsm_init,11
msgdata,hsm_init,bip32_key_version,bip32_key_version,
msgdata,hsm_init,chain_hash,bitcoin_blkid,
msgdata,hsm_init,chainparams,chainparams,
msgdata,hsm_init,dev_force_privkey,?privkey,
msgdata,hsm_init,dev_force_bip32_seed,?secret,
msgdata,hsm_init,dev_force_channel_secrets,?secrets,

1 # Clients should not give a bad request but not the HSM's decision to crash.
9 msgtype,hsm_init,11
10 msgdata,hsm_init,bip32_key_version,bip32_key_version,
11 msgdata,hsm_init,chain_hash,bitcoin_blkid, msgdata,hsm_init,chainparams,chainparams,
12 msgdata,hsm_init,dev_force_privkey,?privkey,
13 msgdata,hsm_init,dev_force_bip32_seed,?secret,
14 msgdata,hsm_init,dev_force_channel_secrets,?secrets,
15 msgdata,hsm_init,dev_force_channel_secrets_shaseed,?sha256,

View File

@ -580,7 +580,6 @@ static struct io_plan *init_hsm(struct io_conn *conn,
struct secret *seed;
struct secrets *secrets;
struct sha256 *shaseed;
struct bitcoin_blkid chain_hash;
/* This must be lightningd. */
assert(is_lightningd(c));
@ -589,7 +588,7 @@ static struct io_plan *init_hsm(struct io_conn *conn,
* definitions in hsm_client_wire.csv. The format of those files is
* an extension of the simple comma-separated format output by the
* BOLT tools/extract-formats.py tool. */
if (!fromwire_hsm_init(NULL, msg_in, &bip32_key_version, &chain_hash,
if (!fromwire_hsm_init(NULL, msg_in, &bip32_key_version, &chainparams,
&privkey, &seed, &secrets, &shaseed))
return bad_req(conn, c, msg_in);
@ -602,9 +601,7 @@ static struct io_plan *init_hsm(struct io_conn *conn,
/* Once we have read the init message we know which params the master
* will use */
c->chainparams = chainparams_by_chainhash(&chain_hash);
is_elements = c->chainparams->is_elements;
c->chainparams = chainparams;
maybe_create_new_hsm();
load_hsm();

View File

@ -421,7 +421,7 @@ void peer_start_channeld(struct channel *channel,
}
initmsg = towire_channel_init(tmpctx,
&get_chainparams(ld)->genesis_blockhash,
chainparams,
&channel->funding_txid,
channel->funding_outnum,
channel->funding,

View File

@ -273,7 +273,7 @@ void peer_start_closingd(struct channel *channel,
return;
}
initmsg = towire_closing_init(tmpctx,
&get_chainparams(ld)->genesis_blockhash,
chainparams,
pps,
&channel->funding_txid,
channel->funding_outnum,

View File

@ -208,7 +208,8 @@ void gossip_init(struct lightningd *ld, int connectd_fd)
msg = towire_gossipctl_init(
tmpctx,
&get_chainparams(ld)->genesis_blockhash, &ld->id,
chainparams,
&ld->id,
get_offered_globalfeatures(tmpctx),
ld->rgb,
ld->alias,

View File

@ -80,8 +80,6 @@ void hsm_init(struct lightningd *ld)
{
u8 *msg;
int fds[2];
struct bitcoin_blkid chainhash;
chainhash = get_chainparams(ld)->genesis_blockhash;
/* We actually send requests synchronously: only status is async. */
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0)
@ -97,7 +95,7 @@ void hsm_init(struct lightningd *ld)
ld->hsm_fd = fds[0];
if (!wire_sync_write(ld->hsm_fd, towire_hsm_init(tmpctx,
&ld->topology->bitcoind->chainparams->bip32_key_version,
&chainhash,
chainparams,
IFDEV(ld->dev_force_privkey, NULL),
IFDEV(ld->dev_force_bip32_seed, NULL),
IFDEV(ld->dev_force_channel_secrets, NULL),

View File

@ -513,8 +513,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
msg = towire_onchain_init(channel,
&channel->their_shachain.chain,
chainparams->is_elements,
&chainparams->genesis_blockhash,
chainparams,
channel->funding,
&channel->channel_info.old_remote_per_commit,
&channel->channel_info.remote_per_commit,

View File

@ -937,7 +937,7 @@ void peer_start_openingd(struct peer *peer,
uc->minimum_depth = peer->ld->config.anchor_confirms;
msg = towire_opening_init(NULL,
&get_chainparams(peer->ld)->genesis_blockhash,
chainparams,
&uc->our_config,
max_to_self_delay,
min_effective_htlc_capacity,

View File

@ -241,7 +241,10 @@ static char *opt_set_network(const char *arg, struct lightningd *ld)
{
assert(arg != NULL);
ld->topology->bitcoind->chainparams = chainparams_for_network(arg);
/* Set the global chainparams instance */
chainparams = chainparams_for_network(arg);
ld->topology->bitcoind->chainparams = chainparams;
if (!ld->topology->bitcoind->chainparams)
return tal_fmt(NULL, "Unknown network name '%s'", arg);
is_elements = ld->topology->bitcoind->chainparams->is_elements;

View File

@ -7,8 +7,7 @@ msgtype,onchain_init,5001
msgdata,onchain_init,shachain,shachain,
# This needs to be set explicitly since the same message also contains a
# transaction that we need to parse correctly.
msgdata,onchain_init,is_elements,bool,
msgdata,onchain_init,chain_hash,bitcoin_blkid,
msgdata,onchain_init,chainparams,chainparams,
msgdata,onchain_init,funding_amount_satoshi,amount_sat,
# Remote per commit point for committed tx.
msgdata,onchain_init,old_remote_per_commitment_point,pubkey,

1 #include <common/derive_basepoints.h>
7 # This needs to be set explicitly since the same message also contains a
8 # transaction that we need to parse correctly.
9 msgdata,onchain_init,is_elements,bool, msgdata,onchain_init,chainparams,chainparams,
10 msgdata,onchain_init,chain_hash,bitcoin_blkid, msgdata,onchain_init,funding_amount_satoshi,amount_sat,
msgdata,onchain_init,funding_amount_satoshi,amount_sat,
11 # Remote per commit point for committed tx.
12 msgdata,onchain_init,old_remote_per_commitment_point,pubkey,
13 # Remote per commit point for current tx (needed if we haven't got revoke_and_ack yet).

View File

@ -2628,7 +2628,6 @@ int main(int argc, char *argv[])
bool *tell_if_missing, *tell_immediately;
u32 tx_blockheight;
struct pubkey *possible_remote_per_commitment_point;
struct bitcoin_blkid chain_hash;
subdaemon_setup(argc, argv);
@ -2639,8 +2638,7 @@ int main(int argc, char *argv[])
msg = wire_sync_read(tmpctx, REQ_FD);
if (!fromwire_onchain_init(tmpctx, msg,
&shachain,
&is_elements,
&chain_hash,
&chainparams,
&funding,
&old_remote_per_commit_point,
&remote_per_commit_point,
@ -2667,7 +2665,7 @@ int main(int argc, char *argv[])
master_badmsg(WIRE_ONCHAIN_INIT, msg);
}
tx->chainparams = chainparams_by_chainhash(&chain_hash);
tx->chainparams = chainparams;
status_debug("feerate_per_kw = %u", feerate_per_kw);
bitcoin_txid(tx, &txid);

View File

@ -43,7 +43,7 @@ bool fromwire_onchain_dev_memleak(const void *p UNNEEDED)
bool fromwire_onchain_htlc(const void *p UNNEEDED, struct htlc_stub *htlc UNNEEDED, bool *tell_if_missing UNNEEDED, bool *tell_immediately UNNEEDED)
{ fprintf(stderr, "fromwire_onchain_htlc called!\n"); abort(); }
/* Generated stub for fromwire_onchain_init */
bool fromwire_onchain_init(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct shachain *shachain UNNEEDED, bool *is_elements UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct amount_sat *funding_amount_satoshi UNNEEDED, struct pubkey *old_remote_per_commitment_point UNNEEDED, struct pubkey *remote_per_commitment_point UNNEEDED, u32 *local_to_self_delay UNNEEDED, u32 *remote_to_self_delay UNNEEDED, u32 *feerate_per_kw UNNEEDED, struct amount_sat *local_dust_limit_satoshi UNNEEDED, struct bitcoin_txid *our_broadcast_txid UNNEEDED, u8 **local_scriptpubkey UNNEEDED, u8 **remote_scriptpubkey UNNEEDED, struct pubkey *ourwallet_pubkey UNNEEDED, enum side *funder UNNEEDED, struct basepoints *local_basepoints UNNEEDED, struct basepoints *remote_basepoints UNNEEDED, struct bitcoin_tx **tx UNNEEDED, u32 *tx_blockheight UNNEEDED, u32 *reasonable_depth UNNEEDED, secp256k1_ecdsa_signature **htlc_signature UNNEEDED, u64 *num_htlcs UNNEEDED, u32 *min_possible_feerate UNNEEDED, u32 *max_possible_feerate UNNEEDED, struct pubkey **possible_remote_per_commit_point UNNEEDED, bool *option_static_remotekey UNNEEDED)
bool fromwire_onchain_init(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct shachain *shachain UNNEEDED, const struct chainparams **chainparams UNNEEDED, struct amount_sat *funding_amount_satoshi UNNEEDED, struct pubkey *old_remote_per_commitment_point UNNEEDED, struct pubkey *remote_per_commitment_point UNNEEDED, u32 *local_to_self_delay UNNEEDED, u32 *remote_to_self_delay UNNEEDED, u32 *feerate_per_kw UNNEEDED, struct amount_sat *local_dust_limit_satoshi UNNEEDED, struct bitcoin_txid *our_broadcast_txid UNNEEDED, u8 **local_scriptpubkey UNNEEDED, u8 **remote_scriptpubkey UNNEEDED, struct pubkey *ourwallet_pubkey UNNEEDED, enum side *funder UNNEEDED, struct basepoints *local_basepoints UNNEEDED, struct basepoints *remote_basepoints UNNEEDED, struct bitcoin_tx **tx UNNEEDED, u32 *tx_blockheight UNNEEDED, u32 *reasonable_depth UNNEEDED, secp256k1_ecdsa_signature **htlc_signature UNNEEDED, u64 *num_htlcs UNNEEDED, u32 *min_possible_feerate UNNEEDED, u32 *max_possible_feerate UNNEEDED, struct pubkey **possible_remote_per_commit_point UNNEEDED, bool *option_static_remotekey UNNEEDED)
{ fprintf(stderr, "fromwire_onchain_init called!\n"); abort(); }
/* Generated stub for fromwire_onchain_known_preimage */
bool fromwire_onchain_known_preimage(const void *p UNNEEDED, struct preimage *preimage UNNEEDED)

View File

@ -47,7 +47,7 @@ bool fromwire_onchain_dev_memleak(const void *p UNNEEDED)
bool fromwire_onchain_htlc(const void *p UNNEEDED, struct htlc_stub *htlc UNNEEDED, bool *tell_if_missing UNNEEDED, bool *tell_immediately UNNEEDED)
{ fprintf(stderr, "fromwire_onchain_htlc called!\n"); abort(); }
/* Generated stub for fromwire_onchain_init */
bool fromwire_onchain_init(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct shachain *shachain UNNEEDED, bool *is_elements UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct amount_sat *funding_amount_satoshi UNNEEDED, struct pubkey *old_remote_per_commitment_point UNNEEDED, struct pubkey *remote_per_commitment_point UNNEEDED, u32 *local_to_self_delay UNNEEDED, u32 *remote_to_self_delay UNNEEDED, u32 *feerate_per_kw UNNEEDED, struct amount_sat *local_dust_limit_satoshi UNNEEDED, struct bitcoin_txid *our_broadcast_txid UNNEEDED, u8 **local_scriptpubkey UNNEEDED, u8 **remote_scriptpubkey UNNEEDED, struct pubkey *ourwallet_pubkey UNNEEDED, enum side *funder UNNEEDED, struct basepoints *local_basepoints UNNEEDED, struct basepoints *remote_basepoints UNNEEDED, struct bitcoin_tx **tx UNNEEDED, u32 *tx_blockheight UNNEEDED, u32 *reasonable_depth UNNEEDED, secp256k1_ecdsa_signature **htlc_signature UNNEEDED, u64 *num_htlcs UNNEEDED, u32 *min_possible_feerate UNNEEDED, u32 *max_possible_feerate UNNEEDED, struct pubkey **possible_remote_per_commit_point UNNEEDED, bool *option_static_remotekey UNNEEDED)
bool fromwire_onchain_init(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct shachain *shachain UNNEEDED, const struct chainparams **chainparams UNNEEDED, struct amount_sat *funding_amount_satoshi UNNEEDED, struct pubkey *old_remote_per_commitment_point UNNEEDED, struct pubkey *remote_per_commitment_point UNNEEDED, u32 *local_to_self_delay UNNEEDED, u32 *remote_to_self_delay UNNEEDED, u32 *feerate_per_kw UNNEEDED, struct amount_sat *local_dust_limit_satoshi UNNEEDED, struct bitcoin_txid *our_broadcast_txid UNNEEDED, u8 **local_scriptpubkey UNNEEDED, u8 **remote_scriptpubkey UNNEEDED, struct pubkey *ourwallet_pubkey UNNEEDED, enum side *funder UNNEEDED, struct basepoints *local_basepoints UNNEEDED, struct basepoints *remote_basepoints UNNEEDED, struct bitcoin_tx **tx UNNEEDED, u32 *tx_blockheight UNNEEDED, u32 *reasonable_depth UNNEEDED, secp256k1_ecdsa_signature **htlc_signature UNNEEDED, u64 *num_htlcs UNNEEDED, u32 *min_possible_feerate UNNEEDED, u32 *max_possible_feerate UNNEEDED, struct pubkey **possible_remote_per_commit_point UNNEEDED, bool *option_static_remotekey UNNEEDED)
{ fprintf(stderr, "fromwire_onchain_init called!\n"); abort(); }
/* Generated stub for fromwire_onchain_known_preimage */
bool fromwire_onchain_known_preimage(const void *p UNNEEDED, struct preimage *preimage UNNEEDED)

View File

@ -5,7 +5,7 @@
msgtype,opening_init,6000
# Which network are we configured for?
msgdata,opening_init,chain_hash,bitcoin_blkid,
msgdata,opening_init,chainparams,chainparams,
# Base configuration we'll offer (channel reserve will vary with amount)
msgdata,opening_init,our_config,channel_config,
# Minimum/maximum configuration values we'll accept

1 #include <common/cryptomsg.h>
5 msgtype,opening_init,6000
6 # Which network are we configured for?
7 msgdata,opening_init,chain_hash,bitcoin_blkid, msgdata,opening_init,chainparams,chainparams,
8 # Base configuration we'll offer (channel reserve will vary with amount)
9 msgdata,opening_init,our_config,channel_config,
10 # Minimum/maximum configuration values we'll accept
11 msgdata,opening_init,max_to_self_delay,u32,

View File

@ -1410,7 +1410,6 @@ int main(int argc, char *argv[])
u8 *msg, *inner;
struct pollfd pollfd[3];
struct state *state = tal(NULL, struct state);
struct bitcoin_blkid chain_hash;
struct secret *none;
subdaemon_setup(argc, argv);
@ -1422,7 +1421,7 @@ int main(int argc, char *argv[])
/*~ The very first thing we read from lightningd is our init msg */
msg = wire_sync_read(tmpctx, REQ_FD);
if (!fromwire_opening_init(state, msg,
&chain_hash,
&chainparams,
&state->localconf,
&state->max_to_self_delay,
&state->min_effective_htlc_capacity,
@ -1451,7 +1450,7 @@ int main(int argc, char *argv[])
/*~ Even though I only care about bitcoin, there's still testnet and
* regtest modes, so we have a general "parameters for this chain"
* function. */
state->chainparams = chainparams_by_chainhash(&chain_hash);
state->chainparams = chainparams;
is_elements = state->chainparams->is_elements;
/*~ Initially we're not associated with a channel, but

View File

@ -115,9 +115,12 @@ class Field(object):
return ', const {} *{}'.format(type_name, self.name)
def arg_desc_from(self):
type_name = self.type_obj.type_name()
if self.type_obj.is_const_ptr_ptr_type():
return ', const {} **{}'.format(type_name, self.name)
if self.len_field_of:
return ''
type_name = self.type_obj.type_name()
if self.is_array():
return ', {} {}[{}]'.format(type_name, self.name, self.count)
ptrs = '*'
@ -244,6 +247,12 @@ class Type(FieldSet):
# FIXME: omits 'pad'
}
# Types that are const pointer-to-pointers, such as chainparams, i.e.,
# they set a reference to some const entry.
const_ptr_ptr_types = [
'chainparams'
]
@staticmethod
def true_type(type_name, field_name=None, outer_name=None):
""" Returns 'true' type of a given type and a flag if
@ -308,6 +317,9 @@ class Type(FieldSet):
def is_subtype(self):
return bool(self.fields)
def is_const_ptr_ptr_type(self):
return self.name in self.const_ptr_ptr_types
def is_truncated(self):
return self.name in self.truncated_typedefs

View File

@ -19,6 +19,8 @@
#define SUPERVERBOSE(...)
#endif
extern const struct chainparams *chainparams;
/* Sets *cursor to NULL and returns NULL when extraction fails. */
const void *fromwire_fail(const u8 **cursor, size_t *max)
{
@ -389,3 +391,12 @@ struct bitcoin_tx_output *fromwire_bitcoin_tx_output(const tal_t *ctx,
fromwire_u8_array(cursor, max, output->script, script_len);
return output;
}
void fromwire_chainparams(const u8 **cursor, size_t *max,
const struct chainparams **chainparams)
{
struct bitcoin_blkid genesis;
fromwire_bitcoin_blkid(cursor, max, &genesis);
*chainparams = chainparams_by_chainhash(&genesis);
is_elements = (*chainparams)->is_elements;
}

View File

@ -256,3 +256,8 @@ void towire_bitcoin_tx_output(u8 **pptr, const struct bitcoin_tx_output *output)
towire_u16(pptr, tal_count(output->script));
towire_u8_array(pptr, output->script, tal_count(output->script));
}
void towire_chainparams(u8 **cursor, const struct chainparams *chainparams)
{
towire_bitcoin_blkid(cursor, &chainparams->genesis_blockhash);
}

View File

@ -89,6 +89,7 @@ void towire_siphash_seed(u8 **cursor, const struct siphash_seed *seed);
void towire_bip32_key_version(u8 **cursor, const struct bip32_key_version *version);
void towire_bitcoin_tx_output(u8 **pptr, const struct bitcoin_tx_output *output);
void towire_chainparams(u8 **cursor, const struct chainparams *chainparams);
const u8 *fromwire(const u8 **cursor, size_t *max, void *copy, size_t n);
u8 fromwire_u8(const u8 **cursor, size_t *max);
@ -141,4 +142,8 @@ void fromwire_bip32_key_version(const u8 **cursor, size_t *max,
struct bip32_key_version *version);
struct bitcoin_tx_output *fromwire_bitcoin_tx_output(const tal_t *ctx,
const u8 **cursor, size_t *max);
void fromwire_chainparams(const u8 **cursor, size_t *max,
const struct chainparams **chainparams);
#endif /* LIGHTNING_WIRE_WIRE_H */