diff --git a/.gitignore b/.gitignore index 8b58443ac..f396cc58c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ *.gcno *.dSYM *.rej -*.po *.pyc .cppcheck-suppress .mypy_cache diff --git a/Makefile b/Makefile index 0a0fc25a9..5c791ea0a 100644 --- a/Makefile +++ b/Makefile @@ -297,6 +297,9 @@ ALL_GEN_HEADERS := $(filter gen%.h %printgen.h %wiregen.h,$(ALL_C_HEADERS)) ALL_GEN_SOURCES := $(filter gen%.c %printgen.c %wiregen.c,$(ALL_C_SOURCES)) ALL_NONGEN_SRCFILES := $(filter-out gen%.h %printgen.h %wiregen.h,$(ALL_C_HEADERS)) $(filter-out gen%.c %printgen.c %wiregen.c,$(ALL_C_SOURCES)) +# Don't delete these intermediaries. +.PRECIOUS: $(ALL_GEN_HEADERS) $(ALL_GEN_SOURCES) + # Every single object file. ALL_OBJS := $(ALL_C_SOURCES:.c=.o) diff --git a/channeld/channeld_wiregen.c b/channeld/channeld_wiregen.c new file mode 100644 index 000000000..e6f55b777 --- /dev/null +++ b/channeld/channeld_wiregen.c @@ -0,0 +1,1188 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Original template can be found at tools/gen/impl_template */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef SUPERVERBOSE +#define SUPERVERBOSE(...) +#endif + + +const char *channeld_wire_name(int e) +{ + static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; + + switch ((enum channeld_wire)e) { + case WIRE_CHANNELD_INIT: return "WIRE_CHANNELD_INIT"; + case WIRE_CHANNELD_FUNDING_DEPTH: return "WIRE_CHANNELD_FUNDING_DEPTH"; + case WIRE_CHANNELD_OFFER_HTLC: return "WIRE_CHANNELD_OFFER_HTLC"; + case WIRE_CHANNELD_OFFER_HTLC_REPLY: return "WIRE_CHANNELD_OFFER_HTLC_REPLY"; + case WIRE_CHANNELD_FULFILL_HTLC: return "WIRE_CHANNELD_FULFILL_HTLC"; + case WIRE_CHANNELD_FAIL_HTLC: return "WIRE_CHANNELD_FAIL_HTLC"; + case WIRE_CHANNELD_GOT_FUNDING_LOCKED: return "WIRE_CHANNELD_GOT_FUNDING_LOCKED"; + case WIRE_CHANNELD_SENDING_COMMITSIG: return "WIRE_CHANNELD_SENDING_COMMITSIG"; + case WIRE_CHANNELD_SENDING_COMMITSIG_REPLY: return "WIRE_CHANNELD_SENDING_COMMITSIG_REPLY"; + case WIRE_CHANNELD_GOT_COMMITSIG: return "WIRE_CHANNELD_GOT_COMMITSIG"; + case WIRE_CHANNELD_GOT_COMMITSIG_REPLY: return "WIRE_CHANNELD_GOT_COMMITSIG_REPLY"; + case WIRE_CHANNELD_GOT_REVOKE: return "WIRE_CHANNELD_GOT_REVOKE"; + case WIRE_CHANNELD_GOT_REVOKE_REPLY: return "WIRE_CHANNELD_GOT_REVOKE_REPLY"; + case WIRE_CHANNELD_SEND_SHUTDOWN: return "WIRE_CHANNELD_SEND_SHUTDOWN"; + case WIRE_CHANNELD_GOT_SHUTDOWN: return "WIRE_CHANNELD_GOT_SHUTDOWN"; + case WIRE_CHANNELD_SHUTDOWN_COMPLETE: return "WIRE_CHANNELD_SHUTDOWN_COMPLETE"; + case WIRE_CHANNELD_DEV_REENABLE_COMMIT: return "WIRE_CHANNELD_DEV_REENABLE_COMMIT"; + case WIRE_CHANNELD_DEV_REENABLE_COMMIT_REPLY: return "WIRE_CHANNELD_DEV_REENABLE_COMMIT_REPLY"; + case WIRE_CHANNELD_FEERATES: return "WIRE_CHANNELD_FEERATES"; + case WIRE_CHANNELD_DEV_MEMLEAK: return "WIRE_CHANNELD_DEV_MEMLEAK"; + case WIRE_CHANNELD_DEV_MEMLEAK_REPLY: return "WIRE_CHANNELD_DEV_MEMLEAK_REPLY"; + case WIRE_CHANNELD_FAIL_FALLEN_BEHIND: return "WIRE_CHANNELD_FAIL_FALLEN_BEHIND"; + case WIRE_CHANNELD_SPECIFIC_FEERATES: return "WIRE_CHANNELD_SPECIFIC_FEERATES"; + case WIRE_CHANNELD_GOT_ANNOUNCEMENT: return "WIRE_CHANNELD_GOT_ANNOUNCEMENT"; + case WIRE_CHANNELD_SEND_ERROR: return "WIRE_CHANNELD_SEND_ERROR"; + case WIRE_CHANNELD_SEND_ERROR_REPLY: return "WIRE_CHANNELD_SEND_ERROR_REPLY"; + case WIRE_GOT_ONIONMSG_TO_US: return "WIRE_GOT_ONIONMSG_TO_US"; + case WIRE_GOT_ONIONMSG_FORWARD: return "WIRE_GOT_ONIONMSG_FORWARD"; + case WIRE_SEND_ONIONMSG: return "WIRE_SEND_ONIONMSG"; + } + + snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); + return invalidbuf; +} + +bool channeld_wire_is_defined(u16 type) +{ + switch ((enum channeld_wire)type) { + case WIRE_CHANNELD_INIT:; + case WIRE_CHANNELD_FUNDING_DEPTH:; + case WIRE_CHANNELD_OFFER_HTLC:; + case WIRE_CHANNELD_OFFER_HTLC_REPLY:; + case WIRE_CHANNELD_FULFILL_HTLC:; + case WIRE_CHANNELD_FAIL_HTLC:; + case WIRE_CHANNELD_GOT_FUNDING_LOCKED:; + case WIRE_CHANNELD_SENDING_COMMITSIG:; + case WIRE_CHANNELD_SENDING_COMMITSIG_REPLY:; + case WIRE_CHANNELD_GOT_COMMITSIG:; + case WIRE_CHANNELD_GOT_COMMITSIG_REPLY:; + case WIRE_CHANNELD_GOT_REVOKE:; + case WIRE_CHANNELD_GOT_REVOKE_REPLY:; + case WIRE_CHANNELD_SEND_SHUTDOWN:; + case WIRE_CHANNELD_GOT_SHUTDOWN:; + case WIRE_CHANNELD_SHUTDOWN_COMPLETE:; + case WIRE_CHANNELD_DEV_REENABLE_COMMIT:; + case WIRE_CHANNELD_DEV_REENABLE_COMMIT_REPLY:; + case WIRE_CHANNELD_FEERATES:; + case WIRE_CHANNELD_DEV_MEMLEAK:; + case WIRE_CHANNELD_DEV_MEMLEAK_REPLY:; + case WIRE_CHANNELD_FAIL_FALLEN_BEHIND:; + case WIRE_CHANNELD_SPECIFIC_FEERATES:; + case WIRE_CHANNELD_GOT_ANNOUNCEMENT:; + case WIRE_CHANNELD_SEND_ERROR:; + case WIRE_CHANNELD_SEND_ERROR_REPLY:; + case WIRE_GOT_ONIONMSG_TO_US:; + case WIRE_GOT_ONIONMSG_FORWARD:; + case WIRE_SEND_ONIONMSG:; + return true; + } + return false; +} + + + + + +/* WIRE: CHANNELD_INIT */ +/* Begin! (passes gossipd-client fd) */ +u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, u32 minimum_depth, const struct channel_config *our_config, const struct channel_config *their_config, const struct fee_states *fee_states, u32 feerate_min, u32 feerate_max, u32 feerate_penalty, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *per_peer_state, const struct pubkey *remote_fundingkey, const struct basepoints *remote_basepoints, const struct pubkey *remote_per_commit, const struct pubkey *old_remote_per_commit, enum side opener, u32 fee_base, u32 fee_proportional, struct amount_msat local_msatoshi, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, const struct node_id *local_node_id, const struct node_id *remote_node_id, u32 commit_msec, u16 cltv_delta, bool last_was_revoke, const struct changed_htlc *last_sent_commit, u64 next_index_local, u64 next_index_remote, u64 revocations_received, u64 next_htlc_id, const struct existing_htlc **htlcs, bool local_funding_locked, bool remote_funding_locked, const struct short_channel_id *funding_short_id, bool reestablish, bool send_shutdown, bool remote_shutdown_received, const u8 *final_scriptpubkey, u8 flags, const u8 *init_peer_pkt, bool reached_announce_depth, const struct secret *last_remote_secret, const u8 *their_features, const u8 *upfront_shutdown_script, const secp256k1_ecdsa_signature *remote_ann_node_sig, const secp256k1_ecdsa_signature *remote_ann_bitcoin_sig, bool option_static_remotekey, bool option_anchor_outputs, bool dev_fast_gossip, bool dev_fail_process_onionpacket, const struct penalty_base *pbases) +{ + u16 num_last_sent_commit = tal_count(last_sent_commit); + u16 num_existing_htlcs = tal_count(htlcs); + u16 final_scriptpubkey_len = tal_count(final_scriptpubkey); + u16 init_peer_pkt_len = tal_count(init_peer_pkt); + u16 flen = tal_count(their_features); + u16 upfront_shutdown_script_len = tal_count(upfront_shutdown_script); + u32 num_penalty_bases = tal_count(pbases); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_INIT); + towire_chainparams(&p, chainparams); + towire_feature_set(&p, our_features); + towire_bitcoin_txid(&p, funding_txid); + towire_u16(&p, funding_txout); + towire_amount_sat(&p, funding_satoshi); + towire_u32(&p, minimum_depth); + towire_channel_config(&p, our_config); + towire_channel_config(&p, their_config); + towire_fee_states(&p, fee_states); + towire_u32(&p, feerate_min); + towire_u32(&p, feerate_max); + towire_u32(&p, feerate_penalty); + towire_bitcoin_signature(&p, first_commit_sig); + towire_per_peer_state(&p, per_peer_state); + towire_pubkey(&p, remote_fundingkey); + towire_basepoints(&p, remote_basepoints); + towire_pubkey(&p, remote_per_commit); + towire_pubkey(&p, old_remote_per_commit); + towire_side(&p, opener); + towire_u32(&p, fee_base); + towire_u32(&p, fee_proportional); + towire_amount_msat(&p, local_msatoshi); + towire_basepoints(&p, our_basepoints); + towire_pubkey(&p, our_funding_pubkey); + towire_node_id(&p, local_node_id); + towire_node_id(&p, remote_node_id); + towire_u32(&p, commit_msec); + towire_u16(&p, cltv_delta); + towire_bool(&p, last_was_revoke); + towire_u16(&p, num_last_sent_commit); + for (size_t i = 0; i < num_last_sent_commit; i++) + towire_changed_htlc(&p, last_sent_commit + i); + towire_u64(&p, next_index_local); + towire_u64(&p, next_index_remote); + towire_u64(&p, revocations_received); + towire_u64(&p, next_htlc_id); + towire_u16(&p, num_existing_htlcs); + for (size_t i = 0; i < num_existing_htlcs; i++) + towire_existing_htlc(&p, htlcs[i]); + towire_bool(&p, local_funding_locked); + towire_bool(&p, remote_funding_locked); + towire_short_channel_id(&p, funding_short_id); + towire_bool(&p, reestablish); + towire_bool(&p, send_shutdown); + towire_bool(&p, remote_shutdown_received); + towire_u16(&p, final_scriptpubkey_len); + towire_u8_array(&p, final_scriptpubkey, final_scriptpubkey_len); + towire_u8(&p, flags); + towire_u16(&p, init_peer_pkt_len); + towire_u8_array(&p, init_peer_pkt, init_peer_pkt_len); + towire_bool(&p, reached_announce_depth); + towire_secret(&p, last_remote_secret); + towire_u16(&p, flen); + towire_u8_array(&p, their_features, flen); + towire_u16(&p, upfront_shutdown_script_len); + towire_u8_array(&p, upfront_shutdown_script, upfront_shutdown_script_len); + if (!remote_ann_node_sig) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_secp256k1_ecdsa_signature(&p, remote_ann_node_sig); + } + if (!remote_ann_bitcoin_sig) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_secp256k1_ecdsa_signature(&p, remote_ann_bitcoin_sig); + } + towire_bool(&p, option_static_remotekey); + towire_bool(&p, option_anchor_outputs); + towire_bool(&p, dev_fast_gossip); + towire_bool(&p, dev_fail_process_onionpacket); + towire_u32(&p, num_penalty_bases); + for (size_t i = 0; i < num_penalty_bases; i++) + towire_penalty_base(&p, pbases + i); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, u32 *minimum_depth, struct channel_config *our_config, struct channel_config *their_config, struct fee_states **fee_states, u32 *feerate_min, u32 *feerate_max, u32 *feerate_penalty, struct bitcoin_signature *first_commit_sig, struct per_peer_state **per_peer_state, struct pubkey *remote_fundingkey, struct basepoints *remote_basepoints, struct pubkey *remote_per_commit, struct pubkey *old_remote_per_commit, enum side *opener, u32 *fee_base, u32 *fee_proportional, struct amount_msat *local_msatoshi, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, struct node_id *local_node_id, struct node_id *remote_node_id, u32 *commit_msec, u16 *cltv_delta, bool *last_was_revoke, struct changed_htlc **last_sent_commit, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u64 *next_htlc_id, struct existing_htlc ***htlcs, bool *local_funding_locked, bool *remote_funding_locked, struct short_channel_id *funding_short_id, bool *reestablish, bool *send_shutdown, bool *remote_shutdown_received, u8 **final_scriptpubkey, u8 *flags, u8 **init_peer_pkt, bool *reached_announce_depth, struct secret *last_remote_secret, u8 **their_features, u8 **upfront_shutdown_script, secp256k1_ecdsa_signature **remote_ann_node_sig, secp256k1_ecdsa_signature **remote_ann_bitcoin_sig, bool *option_static_remotekey, bool *option_anchor_outputs, bool *dev_fast_gossip, bool *dev_fail_process_onionpacket, struct penalty_base **pbases) +{ + u16 num_last_sent_commit; + u16 num_existing_htlcs; + u16 final_scriptpubkey_len; + u16 init_peer_pkt_len; + u16 flen; + u16 upfront_shutdown_script_len; + u32 num_penalty_bases; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_INIT) + return false; + fromwire_chainparams(&cursor, &plen, chainparams); + *our_features = fromwire_feature_set(ctx, &cursor, &plen); + fromwire_bitcoin_txid(&cursor, &plen, funding_txid); + *funding_txout = fromwire_u16(&cursor, &plen); + *funding_satoshi = fromwire_amount_sat(&cursor, &plen); + *minimum_depth = fromwire_u32(&cursor, &plen); + fromwire_channel_config(&cursor, &plen, our_config); + fromwire_channel_config(&cursor, &plen, their_config); + *fee_states = fromwire_fee_states(ctx, &cursor, &plen); + *feerate_min = fromwire_u32(&cursor, &plen); + *feerate_max = fromwire_u32(&cursor, &plen); + *feerate_penalty = fromwire_u32(&cursor, &plen); + fromwire_bitcoin_signature(&cursor, &plen, first_commit_sig); + *per_peer_state = fromwire_per_peer_state(ctx, &cursor, &plen); + fromwire_pubkey(&cursor, &plen, remote_fundingkey); + fromwire_basepoints(&cursor, &plen, remote_basepoints); + fromwire_pubkey(&cursor, &plen, remote_per_commit); + fromwire_pubkey(&cursor, &plen, old_remote_per_commit); + *opener = fromwire_side(&cursor, &plen); + *fee_base = fromwire_u32(&cursor, &plen); + *fee_proportional = fromwire_u32(&cursor, &plen); + *local_msatoshi = fromwire_amount_msat(&cursor, &plen); + fromwire_basepoints(&cursor, &plen, our_basepoints); + fromwire_pubkey(&cursor, &plen, our_funding_pubkey); + fromwire_node_id(&cursor, &plen, local_node_id); + fromwire_node_id(&cursor, &plen, remote_node_id); + *commit_msec = fromwire_u32(&cursor, &plen); + *cltv_delta = fromwire_u16(&cursor, &plen); + *last_was_revoke = fromwire_bool(&cursor, &plen); + num_last_sent_commit = fromwire_u16(&cursor, &plen); + // 2nd case last_sent_commit + *last_sent_commit = num_last_sent_commit ? tal_arr(ctx, struct changed_htlc, num_last_sent_commit) : NULL; + for (size_t i = 0; i < num_last_sent_commit; i++) + fromwire_changed_htlc(&cursor, &plen, *last_sent_commit + i); + *next_index_local = fromwire_u64(&cursor, &plen); + *next_index_remote = fromwire_u64(&cursor, &plen); + *revocations_received = fromwire_u64(&cursor, &plen); + *next_htlc_id = fromwire_u64(&cursor, &plen); + num_existing_htlcs = fromwire_u16(&cursor, &plen); + // 2nd case htlcs + *htlcs = num_existing_htlcs ? tal_arr(ctx, struct existing_htlc *, num_existing_htlcs) : NULL; + for (size_t i = 0; i < num_existing_htlcs; i++) + (*htlcs)[i] = fromwire_existing_htlc(*htlcs, &cursor, &plen); + *local_funding_locked = fromwire_bool(&cursor, &plen); + *remote_funding_locked = fromwire_bool(&cursor, &plen); + fromwire_short_channel_id(&cursor, &plen, funding_short_id); + *reestablish = fromwire_bool(&cursor, &plen); + *send_shutdown = fromwire_bool(&cursor, &plen); + *remote_shutdown_received = fromwire_bool(&cursor, &plen); + final_scriptpubkey_len = fromwire_u16(&cursor, &plen); + // 2nd case final_scriptpubkey + *final_scriptpubkey = final_scriptpubkey_len ? tal_arr(ctx, u8, final_scriptpubkey_len) : NULL; + fromwire_u8_array(&cursor, &plen, *final_scriptpubkey, final_scriptpubkey_len); + *flags = fromwire_u8(&cursor, &plen); + init_peer_pkt_len = fromwire_u16(&cursor, &plen); + // 2nd case init_peer_pkt + *init_peer_pkt = init_peer_pkt_len ? tal_arr(ctx, u8, init_peer_pkt_len) : NULL; + fromwire_u8_array(&cursor, &plen, *init_peer_pkt, init_peer_pkt_len); + *reached_announce_depth = fromwire_bool(&cursor, &plen); + fromwire_secret(&cursor, &plen, last_remote_secret); + flen = fromwire_u16(&cursor, &plen); + // 2nd case their_features + *their_features = flen ? tal_arr(ctx, u8, flen) : NULL; + fromwire_u8_array(&cursor, &plen, *their_features, flen); + upfront_shutdown_script_len = fromwire_u16(&cursor, &plen); + // 2nd case upfront_shutdown_script + *upfront_shutdown_script = upfront_shutdown_script_len ? tal_arr(ctx, u8, upfront_shutdown_script_len) : NULL; + fromwire_u8_array(&cursor, &plen, *upfront_shutdown_script, upfront_shutdown_script_len); + if (!fromwire_bool(&cursor, &plen)) + *remote_ann_node_sig = NULL; + else { + *remote_ann_node_sig = tal(ctx, secp256k1_ecdsa_signature); + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, *remote_ann_node_sig); + } + if (!fromwire_bool(&cursor, &plen)) + *remote_ann_bitcoin_sig = NULL; + else { + *remote_ann_bitcoin_sig = tal(ctx, secp256k1_ecdsa_signature); + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, *remote_ann_bitcoin_sig); + } + *option_static_remotekey = fromwire_bool(&cursor, &plen); + *option_anchor_outputs = fromwire_bool(&cursor, &plen); + *dev_fast_gossip = fromwire_bool(&cursor, &plen); + *dev_fail_process_onionpacket = fromwire_bool(&cursor, &plen); + num_penalty_bases = fromwire_u32(&cursor, &plen); + // 2nd case pbases + *pbases = num_penalty_bases ? tal_arr(ctx, struct penalty_base, num_penalty_bases) : NULL; + for (size_t i = 0; i < num_penalty_bases; i++) + fromwire_penalty_base(&cursor, &plen, *pbases + i); + return cursor != NULL; +} + +/* WIRE: CHANNELD_FUNDING_DEPTH */ +/* master->channeld funding hit new depth(funding locked if >= lock depth) */ +u8 *towire_channeld_funding_depth(const tal_t *ctx, const struct short_channel_id *short_channel_id, u32 depth) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_FUNDING_DEPTH); + if (!short_channel_id) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_short_channel_id(&p, short_channel_id); + } + towire_u32(&p, depth); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_funding_depth(const tal_t *ctx, const void *p, struct short_channel_id **short_channel_id, u32 *depth) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_FUNDING_DEPTH) + return false; + if (!fromwire_bool(&cursor, &plen)) + *short_channel_id = NULL; + else { + *short_channel_id = tal(ctx, struct short_channel_id); + fromwire_short_channel_id(&cursor, &plen, *short_channel_id); + } + *depth = fromwire_u32(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CHANNELD_OFFER_HTLC */ +/* Tell channel to offer this htlc */ +u8 *towire_channeld_offer_htlc(const tal_t *ctx, struct amount_msat amount_msat, u32 cltv_expiry, const struct sha256 *payment_hash, const u8 onion_routing_packet[1366], const struct pubkey *blinding) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_OFFER_HTLC); + towire_amount_msat(&p, amount_msat); + towire_u32(&p, cltv_expiry); + towire_sha256(&p, payment_hash); + towire_u8_array(&p, onion_routing_packet, 1366); + if (!blinding) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_pubkey(&p, blinding); + } + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_offer_htlc(const tal_t *ctx, const void *p, struct amount_msat *amount_msat, u32 *cltv_expiry, struct sha256 *payment_hash, u8 onion_routing_packet[1366], struct pubkey **blinding) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_OFFER_HTLC) + return false; + *amount_msat = fromwire_amount_msat(&cursor, &plen); + *cltv_expiry = fromwire_u32(&cursor, &plen); + fromwire_sha256(&cursor, &plen, payment_hash); + fromwire_u8_array(&cursor, &plen, onion_routing_packet, 1366); + if (!fromwire_bool(&cursor, &plen)) + *blinding = NULL; + else { + *blinding = tal(ctx, struct pubkey); + fromwire_pubkey(&cursor, &plen, *blinding); + } + return cursor != NULL; +} + +/* WIRE: CHANNELD_OFFER_HTLC_REPLY */ +/* Reply; synchronous since IDs have to increment. */ +u8 *towire_channeld_offer_htlc_reply(const tal_t *ctx, u64 id, const u8 *failuremsg, const wirestring *failurestr) +{ + u16 len = tal_count(failuremsg); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_OFFER_HTLC_REPLY); + towire_u64(&p, id); + /* Empty failure message means success. */ + towire_u16(&p, len); + towire_u8_array(&p, failuremsg, len); + towire_wirestring(&p, failurestr); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_offer_htlc_reply(const tal_t *ctx, const void *p, u64 *id, u8 **failuremsg, wirestring **failurestr) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_OFFER_HTLC_REPLY) + return false; + *id = fromwire_u64(&cursor, &plen); + /* Empty failure message means success. */ + len = fromwire_u16(&cursor, &plen); + // 2nd case failuremsg + *failuremsg = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *failuremsg, len); + *failurestr = fromwire_wirestring(ctx, &cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CHANNELD_FULFILL_HTLC */ +/* Main daemon found out the preimage for an HTLC */ +u8 *towire_channeld_fulfill_htlc(const tal_t *ctx, const struct fulfilled_htlc *fulfilled_htlc) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_FULFILL_HTLC); + towire_fulfilled_htlc(&p, fulfilled_htlc); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_fulfill_htlc(const void *p, struct fulfilled_htlc *fulfilled_htlc) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_FULFILL_HTLC) + return false; + fromwire_fulfilled_htlc(&cursor, &plen, fulfilled_htlc); + return cursor != NULL; +} + +/* WIRE: CHANNELD_FAIL_HTLC */ +/* Main daemon says HTLC failed */ +u8 *towire_channeld_fail_htlc(const tal_t *ctx, const struct failed_htlc *failed_htlc) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_FAIL_HTLC); + towire_failed_htlc(&p, failed_htlc); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_fail_htlc(const tal_t *ctx, const void *p, struct failed_htlc **failed_htlc) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_FAIL_HTLC) + return false; + *failed_htlc = fromwire_failed_htlc(ctx, &cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CHANNELD_GOT_FUNDING_LOCKED */ +/* When we receive funding_locked. */ +u8 *towire_channeld_got_funding_locked(const tal_t *ctx, const struct pubkey *next_per_commit_point) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_GOT_FUNDING_LOCKED); + towire_pubkey(&p, next_per_commit_point); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_got_funding_locked(const void *p, struct pubkey *next_per_commit_point) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_GOT_FUNDING_LOCKED) + return false; + fromwire_pubkey(&cursor, &plen, next_per_commit_point); + return cursor != NULL; +} + +/* WIRE: CHANNELD_SENDING_COMMITSIG */ +/* When we send a commitment_signed message */ +u8 *towire_channeld_sending_commitsig(const tal_t *ctx, u64 commitnum, const struct penalty_base *pbase, const struct fee_states *fee_states, const struct changed_htlc *changed, const struct bitcoin_signature *commit_sig, const struct bitcoin_signature *htlc_sigs) +{ + u16 num_changed = tal_count(changed); + u16 num_htlc_sigs = tal_count(htlc_sigs); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_SENDING_COMMITSIG); + towire_u64(&p, commitnum); + if (!pbase) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_penalty_base(&p, pbase); + } + towire_fee_states(&p, fee_states); + /* SENT_ADD_COMMIT */ + towire_u16(&p, num_changed); + for (size_t i = 0; i < num_changed; i++) + towire_changed_htlc(&p, changed + i); + towire_bitcoin_signature(&p, commit_sig); + towire_u16(&p, num_htlc_sigs); + for (size_t i = 0; i < num_htlc_sigs; i++) + towire_bitcoin_signature(&p, htlc_sigs + i); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_sending_commitsig(const tal_t *ctx, const void *p, u64 *commitnum, struct penalty_base **pbase, struct fee_states **fee_states, struct changed_htlc **changed, struct bitcoin_signature *commit_sig, struct bitcoin_signature **htlc_sigs) +{ + u16 num_changed; + u16 num_htlc_sigs; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_SENDING_COMMITSIG) + return false; + *commitnum = fromwire_u64(&cursor, &plen); + if (!fromwire_bool(&cursor, &plen)) + *pbase = NULL; + else { + *pbase = tal(ctx, struct penalty_base); + fromwire_penalty_base(&cursor, &plen, *pbase); + } + *fee_states = fromwire_fee_states(ctx, &cursor, &plen); + /* SENT_ADD_COMMIT */ + num_changed = fromwire_u16(&cursor, &plen); + // 2nd case changed + *changed = num_changed ? tal_arr(ctx, struct changed_htlc, num_changed) : NULL; + for (size_t i = 0; i < num_changed; i++) + fromwire_changed_htlc(&cursor, &plen, *changed + i); + fromwire_bitcoin_signature(&cursor, &plen, commit_sig); + num_htlc_sigs = fromwire_u16(&cursor, &plen); + // 2nd case htlc_sigs + *htlc_sigs = num_htlc_sigs ? tal_arr(ctx, struct bitcoin_signature, num_htlc_sigs) : NULL; + for (size_t i = 0; i < num_htlc_sigs; i++) + fromwire_bitcoin_signature(&cursor, &plen, *htlc_sigs + i); + return cursor != NULL; +} + +/* WIRE: CHANNELD_SENDING_COMMITSIG_REPLY */ +/* Wait for reply */ +u8 *towire_channeld_sending_commitsig_reply(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_SENDING_COMMITSIG_REPLY); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_sending_commitsig_reply(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_SENDING_COMMITSIG_REPLY) + return false; + return cursor != NULL; +} + +/* WIRE: CHANNELD_GOT_COMMITSIG */ +/* When we have a commitment_signed message */ +u8 *towire_channeld_got_commitsig(const tal_t *ctx, u64 commitnum, const struct fee_states *fee_states, const struct bitcoin_signature *signature, const struct bitcoin_signature *htlc_signature, const struct added_htlc *added, const struct fulfilled_htlc *fulfilled, const struct failed_htlc **failed, const struct changed_htlc *changed, const struct bitcoin_tx *tx) +{ + u16 num_htlcs = tal_count(htlc_signature); + u16 num_added = tal_count(added); + u16 num_fulfilled = tal_count(fulfilled); + u16 num_failed = tal_count(failed); + u16 num_changed = tal_count(changed); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_GOT_COMMITSIG); + towire_u64(&p, commitnum); + towire_fee_states(&p, fee_states); + towire_bitcoin_signature(&p, signature); + towire_u16(&p, num_htlcs); + for (size_t i = 0; i < num_htlcs; i++) + towire_bitcoin_signature(&p, htlc_signature + i); + /* RCVD_ADD_COMMIT: we're now committed to their new offered HTLCs. */ + towire_u16(&p, num_added); + for (size_t i = 0; i < num_added; i++) + towire_added_htlc(&p, added + i); + /* RCVD_REMOVE_COMMIT: we're now no longer committed to these HTLCs. */ + towire_u16(&p, num_fulfilled); + for (size_t i = 0; i < num_fulfilled; i++) + towire_fulfilled_htlc(&p, fulfilled + i); + towire_u16(&p, num_failed); + for (size_t i = 0; i < num_failed; i++) + towire_failed_htlc(&p, failed[i]); + /* RCVD_ADD_ACK_COMMIT */ + towire_u16(&p, num_changed); + for (size_t i = 0; i < num_changed; i++) + towire_changed_htlc(&p, changed + i); + towire_bitcoin_tx(&p, tx); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_got_commitsig(const tal_t *ctx, const void *p, u64 *commitnum, struct fee_states **fee_states, struct bitcoin_signature *signature, struct bitcoin_signature **htlc_signature, struct added_htlc **added, struct fulfilled_htlc **fulfilled, struct failed_htlc ***failed, struct changed_htlc **changed, struct bitcoin_tx **tx) +{ + u16 num_htlcs; + u16 num_added; + u16 num_fulfilled; + u16 num_failed; + u16 num_changed; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_GOT_COMMITSIG) + return false; + *commitnum = fromwire_u64(&cursor, &plen); + *fee_states = fromwire_fee_states(ctx, &cursor, &plen); + fromwire_bitcoin_signature(&cursor, &plen, signature); + num_htlcs = fromwire_u16(&cursor, &plen); + // 2nd case htlc_signature + *htlc_signature = num_htlcs ? tal_arr(ctx, struct bitcoin_signature, num_htlcs) : NULL; + for (size_t i = 0; i < num_htlcs; i++) + fromwire_bitcoin_signature(&cursor, &plen, *htlc_signature + i); + /* RCVD_ADD_COMMIT: we're now committed to their new offered HTLCs. */ + num_added = fromwire_u16(&cursor, &plen); + // 2nd case added + *added = num_added ? tal_arr(ctx, struct added_htlc, num_added) : NULL; + for (size_t i = 0; i < num_added; i++) + fromwire_added_htlc(&cursor, &plen, *added + i); + /* RCVD_REMOVE_COMMIT: we're now no longer committed to these HTLCs. */ + num_fulfilled = fromwire_u16(&cursor, &plen); + // 2nd case fulfilled + *fulfilled = num_fulfilled ? tal_arr(ctx, struct fulfilled_htlc, num_fulfilled) : NULL; + for (size_t i = 0; i < num_fulfilled; i++) + fromwire_fulfilled_htlc(&cursor, &plen, *fulfilled + i); + num_failed = fromwire_u16(&cursor, &plen); + // 2nd case failed + *failed = num_failed ? tal_arr(ctx, struct failed_htlc *, num_failed) : NULL; + for (size_t i = 0; i < num_failed; i++) + (*failed)[i] = fromwire_failed_htlc(*failed, &cursor, &plen); + /* RCVD_ADD_ACK_COMMIT */ + num_changed = fromwire_u16(&cursor, &plen); + // 2nd case changed + *changed = num_changed ? tal_arr(ctx, struct changed_htlc, num_changed) : NULL; + for (size_t i = 0; i < num_changed; i++) + fromwire_changed_htlc(&cursor, &plen, *changed + i); + *tx = fromwire_bitcoin_tx(ctx, &cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CHANNELD_GOT_COMMITSIG_REPLY */ +/* Wait for reply */ +u8 *towire_channeld_got_commitsig_reply(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_GOT_COMMITSIG_REPLY); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_got_commitsig_reply(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_GOT_COMMITSIG_REPLY) + return false; + return cursor != NULL; +} + +/* WIRE: CHANNELD_GOT_REVOKE */ +u8 *towire_channeld_got_revoke(const tal_t *ctx, u64 revokenum, const struct secret *per_commitment_secret, const struct pubkey *next_per_commit_point, const struct fee_states *fee_states, const struct changed_htlc *changed, const struct penalty_base *pbase, const struct bitcoin_tx *penalty_tx) +{ + u16 num_changed = tal_count(changed); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_GOT_REVOKE); + towire_u64(&p, revokenum); + towire_secret(&p, per_commitment_secret); + towire_pubkey(&p, next_per_commit_point); + /* RCVD_ADD_ACK_REVOCATION */ + towire_fee_states(&p, fee_states); + towire_u16(&p, num_changed); + for (size_t i = 0; i < num_changed; i++) + towire_changed_htlc(&p, changed + i); + if (!pbase) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_penalty_base(&p, pbase); + } + if (!penalty_tx) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_bitcoin_tx(&p, penalty_tx); + } + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_got_revoke(const tal_t *ctx, const void *p, u64 *revokenum, struct secret *per_commitment_secret, struct pubkey *next_per_commit_point, struct fee_states **fee_states, struct changed_htlc **changed, struct penalty_base **pbase, struct bitcoin_tx **penalty_tx) +{ + u16 num_changed; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_GOT_REVOKE) + return false; + *revokenum = fromwire_u64(&cursor, &plen); + fromwire_secret(&cursor, &plen, per_commitment_secret); + fromwire_pubkey(&cursor, &plen, next_per_commit_point); + /* RCVD_ADD_ACK_REVOCATION */ + *fee_states = fromwire_fee_states(ctx, &cursor, &plen); + num_changed = fromwire_u16(&cursor, &plen); + // 2nd case changed + *changed = num_changed ? tal_arr(ctx, struct changed_htlc, num_changed) : NULL; + for (size_t i = 0; i < num_changed; i++) + fromwire_changed_htlc(&cursor, &plen, *changed + i); + if (!fromwire_bool(&cursor, &plen)) + *pbase = NULL; + else { + *pbase = tal(ctx, struct penalty_base); + fromwire_penalty_base(&cursor, &plen, *pbase); + } + if (!fromwire_bool(&cursor, &plen)) + *penalty_tx = NULL; + else { + *penalty_tx = fromwire_bitcoin_tx(ctx, &cursor, &plen); + } + return cursor != NULL; +} + +/* WIRE: CHANNELD_GOT_REVOKE_REPLY */ +/* Wait for reply */ +/* (eg. if we sent another commitment_signed */ +u8 *towire_channeld_got_revoke_reply(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_GOT_REVOKE_REPLY); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_got_revoke_reply(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_GOT_REVOKE_REPLY) + return false; + return cursor != NULL; +} + +/* WIRE: CHANNELD_SEND_SHUTDOWN */ +/* Tell peer to shut down channel. */ +u8 *towire_channeld_send_shutdown(const tal_t *ctx, const u8 *shutdown_scriptpubkey) +{ + u16 shutdown_len = tal_count(shutdown_scriptpubkey); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_SEND_SHUTDOWN); + towire_u16(&p, shutdown_len); + towire_u8_array(&p, shutdown_scriptpubkey, shutdown_len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_send_shutdown(const tal_t *ctx, const void *p, u8 **shutdown_scriptpubkey) +{ + u16 shutdown_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_SEND_SHUTDOWN) + return false; + shutdown_len = fromwire_u16(&cursor, &plen); + // 2nd case shutdown_scriptpubkey + *shutdown_scriptpubkey = shutdown_len ? tal_arr(ctx, u8, shutdown_len) : NULL; + fromwire_u8_array(&cursor, &plen, *shutdown_scriptpubkey, shutdown_len); + return cursor != NULL; +} + +/* WIRE: CHANNELD_GOT_SHUTDOWN */ +/* Peer told us that channel is shutting down */ +u8 *towire_channeld_got_shutdown(const tal_t *ctx, const u8 *scriptpubkey) +{ + u16 scriptpubkey_len = tal_count(scriptpubkey); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_GOT_SHUTDOWN); + towire_u16(&p, scriptpubkey_len); + towire_u8_array(&p, scriptpubkey, scriptpubkey_len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_got_shutdown(const tal_t *ctx, const void *p, u8 **scriptpubkey) +{ + u16 scriptpubkey_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_GOT_SHUTDOWN) + return false; + scriptpubkey_len = fromwire_u16(&cursor, &plen); + // 2nd case scriptpubkey + *scriptpubkey = scriptpubkey_len ? tal_arr(ctx, u8, scriptpubkey_len) : NULL; + fromwire_u8_array(&cursor, &plen, *scriptpubkey, scriptpubkey_len); + return cursor != NULL; +} + +/* WIRE: CHANNELD_SHUTDOWN_COMPLETE */ +/* Shutdown is complete */ +u8 *towire_channeld_shutdown_complete(const tal_t *ctx, const struct per_peer_state *per_peer_state) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_SHUTDOWN_COMPLETE); + towire_per_peer_state(&p, per_peer_state); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_shutdown_complete(const tal_t *ctx, const void *p, struct per_peer_state **per_peer_state) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_SHUTDOWN_COMPLETE) + return false; + *per_peer_state = fromwire_per_peer_state(ctx, &cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CHANNELD_DEV_REENABLE_COMMIT */ +/* Re-enable commit timer. */ +u8 *towire_channeld_dev_reenable_commit(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_DEV_REENABLE_COMMIT); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_dev_reenable_commit(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_DEV_REENABLE_COMMIT) + return false; + return cursor != NULL; +} + +/* WIRE: CHANNELD_DEV_REENABLE_COMMIT_REPLY */ +u8 *towire_channeld_dev_reenable_commit_reply(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_DEV_REENABLE_COMMIT_REPLY); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_dev_reenable_commit_reply(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_DEV_REENABLE_COMMIT_REPLY) + return false; + return cursor != NULL; +} + +/* WIRE: CHANNELD_FEERATES */ +u8 *towire_channeld_feerates(const tal_t *ctx, u32 feerate, u32 min_feerate, u32 max_feerate, u32 penalty_feerate) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_FEERATES); + towire_u32(&p, feerate); + towire_u32(&p, min_feerate); + towire_u32(&p, max_feerate); + towire_u32(&p, penalty_feerate); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_feerates(const void *p, u32 *feerate, u32 *min_feerate, u32 *max_feerate, u32 *penalty_feerate) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_FEERATES) + return false; + *feerate = fromwire_u32(&cursor, &plen); + *min_feerate = fromwire_u32(&cursor, &plen); + *max_feerate = fromwire_u32(&cursor, &plen); + *penalty_feerate = fromwire_u32(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CHANNELD_DEV_MEMLEAK */ +/* master -> channeld: do you have a memleak? */ +u8 *towire_channeld_dev_memleak(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_DEV_MEMLEAK); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_dev_memleak(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_DEV_MEMLEAK) + return false; + return cursor != NULL; +} + +/* WIRE: CHANNELD_DEV_MEMLEAK_REPLY */ +u8 *towire_channeld_dev_memleak_reply(const tal_t *ctx, bool leak) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_DEV_MEMLEAK_REPLY); + towire_bool(&p, leak); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_dev_memleak_reply(const void *p, bool *leak) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_DEV_MEMLEAK_REPLY) + return false; + *leak = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CHANNELD_FAIL_FALLEN_BEHIND */ +/* Peer presented proof it was from the future. */ +u8 *towire_channeld_fail_fallen_behind(const tal_t *ctx, const struct pubkey *remote_per_commitment_point) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_FAIL_FALLEN_BEHIND); + /* This is NULL if option_static_remotekey. */ + if (!remote_per_commitment_point) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_pubkey(&p, remote_per_commitment_point); + } + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_fail_fallen_behind(const tal_t *ctx, const void *p, struct pubkey **remote_per_commitment_point) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_FAIL_FALLEN_BEHIND) + return false; + /* This is NULL if option_static_remotekey. */ + if (!fromwire_bool(&cursor, &plen)) + *remote_per_commitment_point = NULL; + else { + *remote_per_commitment_point = tal(ctx, struct pubkey); + fromwire_pubkey(&cursor, &plen, *remote_per_commitment_point); + } + return cursor != NULL; +} + +/* WIRE: CHANNELD_SPECIFIC_FEERATES */ +/* Handle a channel specific feerate base ppm configuration */ +u8 *towire_channeld_specific_feerates(const tal_t *ctx, u32 feerate_base, u32 feerate_ppm) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_SPECIFIC_FEERATES); + towire_u32(&p, feerate_base); + towire_u32(&p, feerate_ppm); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_specific_feerates(const void *p, u32 *feerate_base, u32 *feerate_ppm) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_SPECIFIC_FEERATES) + return false; + *feerate_base = fromwire_u32(&cursor, &plen); + *feerate_ppm = fromwire_u32(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CHANNELD_GOT_ANNOUNCEMENT */ +/* When we receive announcement_signatures for channel announce */ +u8 *towire_channeld_got_announcement(const tal_t *ctx, const secp256k1_ecdsa_signature *remote_ann_node_sig, const secp256k1_ecdsa_signature *remote_ann_bitcoin_sig) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_GOT_ANNOUNCEMENT); + towire_secp256k1_ecdsa_signature(&p, remote_ann_node_sig); + towire_secp256k1_ecdsa_signature(&p, remote_ann_bitcoin_sig); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_got_announcement(const void *p, secp256k1_ecdsa_signature *remote_ann_node_sig, secp256k1_ecdsa_signature *remote_ann_bitcoin_sig) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_GOT_ANNOUNCEMENT) + return false; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, remote_ann_node_sig); + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, remote_ann_bitcoin_sig); + return cursor != NULL; +} + +/* WIRE: CHANNELD_SEND_ERROR */ +/* Ask channeld to send a error message. Used in forgetting channel case. */ +u8 *towire_channeld_send_error(const tal_t *ctx, const wirestring *reason) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_SEND_ERROR); + towire_wirestring(&p, reason); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_send_error(const tal_t *ctx, const void *p, wirestring **reason) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_SEND_ERROR) + return false; + *reason = fromwire_wirestring(ctx, &cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CHANNELD_SEND_ERROR_REPLY */ +/* Tell master channeld has sent the error message. */ +u8 *towire_channeld_send_error_reply(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNELD_SEND_ERROR_REPLY); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channeld_send_error_reply(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_SEND_ERROR_REPLY) + return false; + return cursor != NULL; +} + +/* WIRE: GOT_ONIONMSG_TO_US */ +/* Tell lightningd we got a onion message (for us */ +u8 *towire_got_onionmsg_to_us(const tal_t *ctx, const struct pubkey *reply_blinding, const struct onionmsg_path **reply_path) +{ + u16 reply_path_len = tal_count(reply_path); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOT_ONIONMSG_TO_US); + if (!reply_blinding) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_pubkey(&p, reply_blinding); + } + towire_u16(&p, reply_path_len); + for (size_t i = 0; i < reply_path_len; i++) + towire_onionmsg_path(&p, reply_path[i]); + + return memcheck(p, tal_count(p)); +} +bool fromwire_got_onionmsg_to_us(const tal_t *ctx, const void *p, struct pubkey **reply_blinding, struct onionmsg_path ***reply_path) +{ + u16 reply_path_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOT_ONIONMSG_TO_US) + return false; + if (!fromwire_bool(&cursor, &plen)) + *reply_blinding = NULL; + else { + *reply_blinding = tal(ctx, struct pubkey); + fromwire_pubkey(&cursor, &plen, *reply_blinding); + } + reply_path_len = fromwire_u16(&cursor, &plen); + // 2nd case reply_path + *reply_path = reply_path_len ? tal_arr(ctx, struct onionmsg_path *, reply_path_len) : NULL; + for (size_t i = 0; i < reply_path_len; i++) + (*reply_path)[i] = fromwire_onionmsg_path(*reply_path, &cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOT_ONIONMSG_FORWARD */ +u8 *towire_got_onionmsg_forward(const tal_t *ctx, const struct short_channel_id *next_scid, const struct node_id *next_node_id, const struct pubkey *next_blinding, const u8 next_onion[1366]) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOT_ONIONMSG_FORWARD); + if (!next_scid) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_short_channel_id(&p, next_scid); + } + if (!next_node_id) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_node_id(&p, next_node_id); + } + if (!next_blinding) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_pubkey(&p, next_blinding); + } + towire_u8_array(&p, next_onion, 1366); + + return memcheck(p, tal_count(p)); +} +bool fromwire_got_onionmsg_forward(const tal_t *ctx, const void *p, struct short_channel_id **next_scid, struct node_id **next_node_id, struct pubkey **next_blinding, u8 next_onion[1366]) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOT_ONIONMSG_FORWARD) + return false; + if (!fromwire_bool(&cursor, &plen)) + *next_scid = NULL; + else { + *next_scid = tal(ctx, struct short_channel_id); + fromwire_short_channel_id(&cursor, &plen, *next_scid); + } + if (!fromwire_bool(&cursor, &plen)) + *next_node_id = NULL; + else { + *next_node_id = tal(ctx, struct node_id); + fromwire_node_id(&cursor, &plen, *next_node_id); + } + if (!fromwire_bool(&cursor, &plen)) + *next_blinding = NULL; + else { + *next_blinding = tal(ctx, struct pubkey); + fromwire_pubkey(&cursor, &plen, *next_blinding); + } + fromwire_u8_array(&cursor, &plen, next_onion, 1366); + return cursor != NULL; +} + +/* WIRE: SEND_ONIONMSG */ +/* Lightningd tells us to send a onion message. */ +u8 *towire_send_onionmsg(const tal_t *ctx, const u8 onion[1366], const struct pubkey *blinding) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_SEND_ONIONMSG); + towire_u8_array(&p, onion, 1366); + if (!blinding) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_pubkey(&p, blinding); + } + + return memcheck(p, tal_count(p)); +} +bool fromwire_send_onionmsg(const tal_t *ctx, const void *p, u8 onion[1366], struct pubkey **blinding) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_SEND_ONIONMSG) + return false; + fromwire_u8_array(&cursor, &plen, onion, 1366); + if (!fromwire_bool(&cursor, &plen)) + *blinding = NULL; + else { + *blinding = tal(ctx, struct pubkey); + fromwire_pubkey(&cursor, &plen, *blinding); + } + return cursor != NULL; +} + +// SHA256STAMP:exp-0-1b6f8d6af6aeb028ca014ecd646ecff1fc72b6b47f4ae04a0d6b24b92efb6eda diff --git a/channeld/channeld_wiregen.h b/channeld/channeld_wiregen.h new file mode 100644 index 000000000..cfb25c802 --- /dev/null +++ b/channeld/channeld_wiregen.h @@ -0,0 +1,233 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the _csv file it was generated from. */ +/* Original template can be found at tools/gen/header_template */ + +#ifndef LIGHTNING_CHANNELD_CHANNELD_WIREGEN_H +#define LIGHTNING_CHANNELD_CHANNELD_WIREGEN_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum channeld_wire { + /* Begin! (passes gossipd-client fd) */ + WIRE_CHANNELD_INIT = 1000, + /* master->channeld funding hit new depth(funding locked if >= lock depth) */ + WIRE_CHANNELD_FUNDING_DEPTH = 1002, + /* Tell channel to offer this htlc */ + WIRE_CHANNELD_OFFER_HTLC = 1004, + /* Reply; synchronous since IDs have to increment. */ + WIRE_CHANNELD_OFFER_HTLC_REPLY = 1104, + /* Main daemon found out the preimage for an HTLC */ + WIRE_CHANNELD_FULFILL_HTLC = 1005, + /* Main daemon says HTLC failed */ + WIRE_CHANNELD_FAIL_HTLC = 1006, + /* When we receive funding_locked. */ + WIRE_CHANNELD_GOT_FUNDING_LOCKED = 1019, + /* When we send a commitment_signed message */ + WIRE_CHANNELD_SENDING_COMMITSIG = 1020, + /* Wait for reply */ + WIRE_CHANNELD_SENDING_COMMITSIG_REPLY = 1120, + /* When we have a commitment_signed message */ + WIRE_CHANNELD_GOT_COMMITSIG = 1021, + /* Wait for reply */ + WIRE_CHANNELD_GOT_COMMITSIG_REPLY = 1121, + WIRE_CHANNELD_GOT_REVOKE = 1022, + /* Wait for reply */ + /* (eg. if we sent another commitment_signed */ + WIRE_CHANNELD_GOT_REVOKE_REPLY = 1122, + /* Tell peer to shut down channel. */ + WIRE_CHANNELD_SEND_SHUTDOWN = 1023, + /* Peer told us that channel is shutting down */ + WIRE_CHANNELD_GOT_SHUTDOWN = 1024, + /* Shutdown is complete */ + WIRE_CHANNELD_SHUTDOWN_COMPLETE = 1025, + /* Re-enable commit timer. */ + WIRE_CHANNELD_DEV_REENABLE_COMMIT = 1026, + WIRE_CHANNELD_DEV_REENABLE_COMMIT_REPLY = 1126, + WIRE_CHANNELD_FEERATES = 1027, + /* master -> channeld: do you have a memleak? */ + WIRE_CHANNELD_DEV_MEMLEAK = 1033, + WIRE_CHANNELD_DEV_MEMLEAK_REPLY = 1133, + /* Peer presented proof it was from the future. */ + WIRE_CHANNELD_FAIL_FALLEN_BEHIND = 1028, + /* Handle a channel specific feerate base ppm configuration */ + WIRE_CHANNELD_SPECIFIC_FEERATES = 1029, + /* When we receive announcement_signatures for channel announce */ + WIRE_CHANNELD_GOT_ANNOUNCEMENT = 1017, + /* Ask channeld to send a error message. Used in forgetting channel case. */ + WIRE_CHANNELD_SEND_ERROR = 1008, + /* Tell master channeld has sent the error message. */ + WIRE_CHANNELD_SEND_ERROR_REPLY = 1108, + /* Tell lightningd we got a onion message (for us */ + WIRE_GOT_ONIONMSG_TO_US = 1142, + WIRE_GOT_ONIONMSG_FORWARD = 1143, + /* Lightningd tells us to send a onion message. */ + WIRE_SEND_ONIONMSG = 1040, +}; + +const char *channeld_wire_name(int e); + +/** + * Determine whether a given message type is defined as a message. + * + * Returns true if the message type is part of the message definitions we have + * generated parsers for, false if it is a custom message that cannot be + * handled internally. + */ +bool channeld_wire_is_defined(u16 type); + + +/* WIRE: CHANNELD_INIT */ +/* Begin! (passes gossipd-client fd) */ +u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, u32 minimum_depth, const struct channel_config *our_config, const struct channel_config *their_config, const struct fee_states *fee_states, u32 feerate_min, u32 feerate_max, u32 feerate_penalty, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *per_peer_state, const struct pubkey *remote_fundingkey, const struct basepoints *remote_basepoints, const struct pubkey *remote_per_commit, const struct pubkey *old_remote_per_commit, enum side opener, u32 fee_base, u32 fee_proportional, struct amount_msat local_msatoshi, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, const struct node_id *local_node_id, const struct node_id *remote_node_id, u32 commit_msec, u16 cltv_delta, bool last_was_revoke, const struct changed_htlc *last_sent_commit, u64 next_index_local, u64 next_index_remote, u64 revocations_received, u64 next_htlc_id, const struct existing_htlc **htlcs, bool local_funding_locked, bool remote_funding_locked, const struct short_channel_id *funding_short_id, bool reestablish, bool send_shutdown, bool remote_shutdown_received, const u8 *final_scriptpubkey, u8 flags, const u8 *init_peer_pkt, bool reached_announce_depth, const struct secret *last_remote_secret, const u8 *their_features, const u8 *upfront_shutdown_script, const secp256k1_ecdsa_signature *remote_ann_node_sig, const secp256k1_ecdsa_signature *remote_ann_bitcoin_sig, bool option_static_remotekey, bool option_anchor_outputs, bool dev_fast_gossip, bool dev_fail_process_onionpacket, const struct penalty_base *pbases); +bool fromwire_channeld_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, u32 *minimum_depth, struct channel_config *our_config, struct channel_config *their_config, struct fee_states **fee_states, u32 *feerate_min, u32 *feerate_max, u32 *feerate_penalty, struct bitcoin_signature *first_commit_sig, struct per_peer_state **per_peer_state, struct pubkey *remote_fundingkey, struct basepoints *remote_basepoints, struct pubkey *remote_per_commit, struct pubkey *old_remote_per_commit, enum side *opener, u32 *fee_base, u32 *fee_proportional, struct amount_msat *local_msatoshi, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, struct node_id *local_node_id, struct node_id *remote_node_id, u32 *commit_msec, u16 *cltv_delta, bool *last_was_revoke, struct changed_htlc **last_sent_commit, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u64 *next_htlc_id, struct existing_htlc ***htlcs, bool *local_funding_locked, bool *remote_funding_locked, struct short_channel_id *funding_short_id, bool *reestablish, bool *send_shutdown, bool *remote_shutdown_received, u8 **final_scriptpubkey, u8 *flags, u8 **init_peer_pkt, bool *reached_announce_depth, struct secret *last_remote_secret, u8 **their_features, u8 **upfront_shutdown_script, secp256k1_ecdsa_signature **remote_ann_node_sig, secp256k1_ecdsa_signature **remote_ann_bitcoin_sig, bool *option_static_remotekey, bool *option_anchor_outputs, bool *dev_fast_gossip, bool *dev_fail_process_onionpacket, struct penalty_base **pbases); + +/* WIRE: CHANNELD_FUNDING_DEPTH */ +/* master->channeld funding hit new depth(funding locked if >= lock depth) */ +u8 *towire_channeld_funding_depth(const tal_t *ctx, const struct short_channel_id *short_channel_id, u32 depth); +bool fromwire_channeld_funding_depth(const tal_t *ctx, const void *p, struct short_channel_id **short_channel_id, u32 *depth); + +/* WIRE: CHANNELD_OFFER_HTLC */ +/* Tell channel to offer this htlc */ +u8 *towire_channeld_offer_htlc(const tal_t *ctx, struct amount_msat amount_msat, u32 cltv_expiry, const struct sha256 *payment_hash, const u8 onion_routing_packet[1366], const struct pubkey *blinding); +bool fromwire_channeld_offer_htlc(const tal_t *ctx, const void *p, struct amount_msat *amount_msat, u32 *cltv_expiry, struct sha256 *payment_hash, u8 onion_routing_packet[1366], struct pubkey **blinding); + +/* WIRE: CHANNELD_OFFER_HTLC_REPLY */ +/* Reply; synchronous since IDs have to increment. */ +u8 *towire_channeld_offer_htlc_reply(const tal_t *ctx, u64 id, const u8 *failuremsg, const wirestring *failurestr); +bool fromwire_channeld_offer_htlc_reply(const tal_t *ctx, const void *p, u64 *id, u8 **failuremsg, wirestring **failurestr); + +/* WIRE: CHANNELD_FULFILL_HTLC */ +/* Main daemon found out the preimage for an HTLC */ +u8 *towire_channeld_fulfill_htlc(const tal_t *ctx, const struct fulfilled_htlc *fulfilled_htlc); +bool fromwire_channeld_fulfill_htlc(const void *p, struct fulfilled_htlc *fulfilled_htlc); + +/* WIRE: CHANNELD_FAIL_HTLC */ +/* Main daemon says HTLC failed */ +u8 *towire_channeld_fail_htlc(const tal_t *ctx, const struct failed_htlc *failed_htlc); +bool fromwire_channeld_fail_htlc(const tal_t *ctx, const void *p, struct failed_htlc **failed_htlc); + +/* WIRE: CHANNELD_GOT_FUNDING_LOCKED */ +/* When we receive funding_locked. */ +u8 *towire_channeld_got_funding_locked(const tal_t *ctx, const struct pubkey *next_per_commit_point); +bool fromwire_channeld_got_funding_locked(const void *p, struct pubkey *next_per_commit_point); + +/* WIRE: CHANNELD_SENDING_COMMITSIG */ +/* When we send a commitment_signed message */ +u8 *towire_channeld_sending_commitsig(const tal_t *ctx, u64 commitnum, const struct penalty_base *pbase, const struct fee_states *fee_states, const struct changed_htlc *changed, const struct bitcoin_signature *commit_sig, const struct bitcoin_signature *htlc_sigs); +bool fromwire_channeld_sending_commitsig(const tal_t *ctx, const void *p, u64 *commitnum, struct penalty_base **pbase, struct fee_states **fee_states, struct changed_htlc **changed, struct bitcoin_signature *commit_sig, struct bitcoin_signature **htlc_sigs); + +/* WIRE: CHANNELD_SENDING_COMMITSIG_REPLY */ +/* Wait for reply */ +u8 *towire_channeld_sending_commitsig_reply(const tal_t *ctx); +bool fromwire_channeld_sending_commitsig_reply(const void *p); + +/* WIRE: CHANNELD_GOT_COMMITSIG */ +/* When we have a commitment_signed message */ +u8 *towire_channeld_got_commitsig(const tal_t *ctx, u64 commitnum, const struct fee_states *fee_states, const struct bitcoin_signature *signature, const struct bitcoin_signature *htlc_signature, const struct added_htlc *added, const struct fulfilled_htlc *fulfilled, const struct failed_htlc **failed, const struct changed_htlc *changed, const struct bitcoin_tx *tx); +bool fromwire_channeld_got_commitsig(const tal_t *ctx, const void *p, u64 *commitnum, struct fee_states **fee_states, struct bitcoin_signature *signature, struct bitcoin_signature **htlc_signature, struct added_htlc **added, struct fulfilled_htlc **fulfilled, struct failed_htlc ***failed, struct changed_htlc **changed, struct bitcoin_tx **tx); + +/* WIRE: CHANNELD_GOT_COMMITSIG_REPLY */ +/* Wait for reply */ +u8 *towire_channeld_got_commitsig_reply(const tal_t *ctx); +bool fromwire_channeld_got_commitsig_reply(const void *p); + +/* WIRE: CHANNELD_GOT_REVOKE */ +u8 *towire_channeld_got_revoke(const tal_t *ctx, u64 revokenum, const struct secret *per_commitment_secret, const struct pubkey *next_per_commit_point, const struct fee_states *fee_states, const struct changed_htlc *changed, const struct penalty_base *pbase, const struct bitcoin_tx *penalty_tx); +bool fromwire_channeld_got_revoke(const tal_t *ctx, const void *p, u64 *revokenum, struct secret *per_commitment_secret, struct pubkey *next_per_commit_point, struct fee_states **fee_states, struct changed_htlc **changed, struct penalty_base **pbase, struct bitcoin_tx **penalty_tx); + +/* WIRE: CHANNELD_GOT_REVOKE_REPLY */ +/* Wait for reply */ +/* (eg. if we sent another commitment_signed */ +u8 *towire_channeld_got_revoke_reply(const tal_t *ctx); +bool fromwire_channeld_got_revoke_reply(const void *p); + +/* WIRE: CHANNELD_SEND_SHUTDOWN */ +/* Tell peer to shut down channel. */ +u8 *towire_channeld_send_shutdown(const tal_t *ctx, const u8 *shutdown_scriptpubkey); +bool fromwire_channeld_send_shutdown(const tal_t *ctx, const void *p, u8 **shutdown_scriptpubkey); + +/* WIRE: CHANNELD_GOT_SHUTDOWN */ +/* Peer told us that channel is shutting down */ +u8 *towire_channeld_got_shutdown(const tal_t *ctx, const u8 *scriptpubkey); +bool fromwire_channeld_got_shutdown(const tal_t *ctx, const void *p, u8 **scriptpubkey); + +/* WIRE: CHANNELD_SHUTDOWN_COMPLETE */ +/* Shutdown is complete */ +u8 *towire_channeld_shutdown_complete(const tal_t *ctx, const struct per_peer_state *per_peer_state); +bool fromwire_channeld_shutdown_complete(const tal_t *ctx, const void *p, struct per_peer_state **per_peer_state); + +/* WIRE: CHANNELD_DEV_REENABLE_COMMIT */ +/* Re-enable commit timer. */ +u8 *towire_channeld_dev_reenable_commit(const tal_t *ctx); +bool fromwire_channeld_dev_reenable_commit(const void *p); + +/* WIRE: CHANNELD_DEV_REENABLE_COMMIT_REPLY */ +u8 *towire_channeld_dev_reenable_commit_reply(const tal_t *ctx); +bool fromwire_channeld_dev_reenable_commit_reply(const void *p); + +/* WIRE: CHANNELD_FEERATES */ +u8 *towire_channeld_feerates(const tal_t *ctx, u32 feerate, u32 min_feerate, u32 max_feerate, u32 penalty_feerate); +bool fromwire_channeld_feerates(const void *p, u32 *feerate, u32 *min_feerate, u32 *max_feerate, u32 *penalty_feerate); + +/* WIRE: CHANNELD_DEV_MEMLEAK */ +/* master -> channeld: do you have a memleak? */ +u8 *towire_channeld_dev_memleak(const tal_t *ctx); +bool fromwire_channeld_dev_memleak(const void *p); + +/* WIRE: CHANNELD_DEV_MEMLEAK_REPLY */ +u8 *towire_channeld_dev_memleak_reply(const tal_t *ctx, bool leak); +bool fromwire_channeld_dev_memleak_reply(const void *p, bool *leak); + +/* WIRE: CHANNELD_FAIL_FALLEN_BEHIND */ +/* Peer presented proof it was from the future. */ +u8 *towire_channeld_fail_fallen_behind(const tal_t *ctx, const struct pubkey *remote_per_commitment_point); +bool fromwire_channeld_fail_fallen_behind(const tal_t *ctx, const void *p, struct pubkey **remote_per_commitment_point); + +/* WIRE: CHANNELD_SPECIFIC_FEERATES */ +/* Handle a channel specific feerate base ppm configuration */ +u8 *towire_channeld_specific_feerates(const tal_t *ctx, u32 feerate_base, u32 feerate_ppm); +bool fromwire_channeld_specific_feerates(const void *p, u32 *feerate_base, u32 *feerate_ppm); + +/* WIRE: CHANNELD_GOT_ANNOUNCEMENT */ +/* When we receive announcement_signatures for channel announce */ +u8 *towire_channeld_got_announcement(const tal_t *ctx, const secp256k1_ecdsa_signature *remote_ann_node_sig, const secp256k1_ecdsa_signature *remote_ann_bitcoin_sig); +bool fromwire_channeld_got_announcement(const void *p, secp256k1_ecdsa_signature *remote_ann_node_sig, secp256k1_ecdsa_signature *remote_ann_bitcoin_sig); + +/* WIRE: CHANNELD_SEND_ERROR */ +/* Ask channeld to send a error message. Used in forgetting channel case. */ +u8 *towire_channeld_send_error(const tal_t *ctx, const wirestring *reason); +bool fromwire_channeld_send_error(const tal_t *ctx, const void *p, wirestring **reason); + +/* WIRE: CHANNELD_SEND_ERROR_REPLY */ +/* Tell master channeld has sent the error message. */ +u8 *towire_channeld_send_error_reply(const tal_t *ctx); +bool fromwire_channeld_send_error_reply(const void *p); + +/* WIRE: GOT_ONIONMSG_TO_US */ +/* Tell lightningd we got a onion message (for us */ +u8 *towire_got_onionmsg_to_us(const tal_t *ctx, const struct pubkey *reply_blinding, const struct onionmsg_path **reply_path); +bool fromwire_got_onionmsg_to_us(const tal_t *ctx, const void *p, struct pubkey **reply_blinding, struct onionmsg_path ***reply_path); + +/* WIRE: GOT_ONIONMSG_FORWARD */ +u8 *towire_got_onionmsg_forward(const tal_t *ctx, const struct short_channel_id *next_scid, const struct node_id *next_node_id, const struct pubkey *next_blinding, const u8 next_onion[1366]); +bool fromwire_got_onionmsg_forward(const tal_t *ctx, const void *p, struct short_channel_id **next_scid, struct node_id **next_node_id, struct pubkey **next_blinding, u8 next_onion[1366]); + +/* WIRE: SEND_ONIONMSG */ +/* Lightningd tells us to send a onion message. */ +u8 *towire_send_onionmsg(const tal_t *ctx, const u8 onion[1366], const struct pubkey *blinding); +bool fromwire_send_onionmsg(const tal_t *ctx, const void *p, u8 onion[1366], struct pubkey **blinding); + + +#endif /* LIGHTNING_CHANNELD_CHANNELD_WIREGEN_H */ + +// SHA256STAMP:exp-0-1b6f8d6af6aeb028ca014ecd646ecff1fc72b6b47f4ae04a0d6b24b92efb6eda diff --git a/closingd/closingd_wiregen.c b/closingd/closingd_wiregen.c new file mode 100644 index 000000000..f6769ccea --- /dev/null +++ b/closingd/closingd_wiregen.c @@ -0,0 +1,203 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Original template can be found at tools/gen/impl_template */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef SUPERVERBOSE +#define SUPERVERBOSE(...) +#endif + + +const char *closingd_wire_name(int e) +{ + static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; + + switch ((enum closingd_wire)e) { + case WIRE_CLOSINGD_INIT: return "WIRE_CLOSINGD_INIT"; + case WIRE_CLOSINGD_RECEIVED_SIGNATURE: return "WIRE_CLOSINGD_RECEIVED_SIGNATURE"; + case WIRE_CLOSINGD_RECEIVED_SIGNATURE_REPLY: return "WIRE_CLOSINGD_RECEIVED_SIGNATURE_REPLY"; + case WIRE_CLOSINGD_COMPLETE: return "WIRE_CLOSINGD_COMPLETE"; + } + + snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); + return invalidbuf; +} + +bool closingd_wire_is_defined(u16 type) +{ + switch ((enum closingd_wire)type) { + case WIRE_CLOSINGD_INIT:; + case WIRE_CLOSINGD_RECEIVED_SIGNATURE:; + case WIRE_CLOSINGD_RECEIVED_SIGNATURE_REPLY:; + case WIRE_CLOSINGD_COMPLETE:; + return true; + } + return false; +} + + + + + +/* WIRE: CLOSINGD_INIT */ +/* Begin! (passes peer fd */ +u8 *towire_closingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct per_peer_state *pps, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, const struct pubkey *local_fundingkey, const struct pubkey *remote_fundingkey, enum side opener, struct amount_sat local_sat, struct amount_sat remote_sat, struct amount_sat our_dust_limit, struct amount_sat min_fee_satoshi, struct amount_sat fee_limit_satoshi, struct amount_sat initial_fee_satoshi, const u8 *local_scriptpubkey, const u8 *remote_scriptpubkey, u64 fee_negotiation_step, u8 fee_negotiation_step_unit, bool reconnected, u64 next_index_local, u64 next_index_remote, u64 revocations_received, const u8 *channel_reestablish, const struct secret *last_remote_secret, bool dev_fast_gossip) +{ + u16 local_scriptpubkey_len = tal_count(local_scriptpubkey); + u16 remote_scriptpubkey_len = tal_count(remote_scriptpubkey); + u16 channel_reestablish_len = tal_count(channel_reestablish); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CLOSINGD_INIT); + towire_chainparams(&p, chainparams); + towire_per_peer_state(&p, pps); + towire_bitcoin_txid(&p, funding_txid); + towire_u16(&p, funding_txout); + towire_amount_sat(&p, funding_satoshi); + towire_pubkey(&p, local_fundingkey); + towire_pubkey(&p, remote_fundingkey); + towire_side(&p, opener); + towire_amount_sat(&p, local_sat); + towire_amount_sat(&p, remote_sat); + towire_amount_sat(&p, our_dust_limit); + towire_amount_sat(&p, min_fee_satoshi); + towire_amount_sat(&p, fee_limit_satoshi); + towire_amount_sat(&p, initial_fee_satoshi); + towire_u16(&p, local_scriptpubkey_len); + towire_u8_array(&p, local_scriptpubkey, local_scriptpubkey_len); + towire_u16(&p, remote_scriptpubkey_len); + towire_u8_array(&p, remote_scriptpubkey, remote_scriptpubkey_len); + towire_u64(&p, fee_negotiation_step); + towire_u8(&p, fee_negotiation_step_unit); + towire_bool(&p, reconnected); + towire_u64(&p, next_index_local); + towire_u64(&p, next_index_remote); + towire_u64(&p, revocations_received); + towire_u16(&p, channel_reestablish_len); + towire_u8_array(&p, channel_reestablish, channel_reestablish_len); + towire_secret(&p, last_remote_secret); + towire_bool(&p, dev_fast_gossip); + + return memcheck(p, tal_count(p)); +} +bool fromwire_closingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct per_peer_state **pps, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, struct pubkey *local_fundingkey, struct pubkey *remote_fundingkey, enum side *opener, struct amount_sat *local_sat, struct amount_sat *remote_sat, struct amount_sat *our_dust_limit, struct amount_sat *min_fee_satoshi, struct amount_sat *fee_limit_satoshi, struct amount_sat *initial_fee_satoshi, u8 **local_scriptpubkey, u8 **remote_scriptpubkey, u64 *fee_negotiation_step, u8 *fee_negotiation_step_unit, bool *reconnected, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u8 **channel_reestablish, struct secret *last_remote_secret, bool *dev_fast_gossip) +{ + u16 local_scriptpubkey_len; + u16 remote_scriptpubkey_len; + u16 channel_reestablish_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CLOSINGD_INIT) + return false; + fromwire_chainparams(&cursor, &plen, chainparams); + *pps = fromwire_per_peer_state(ctx, &cursor, &plen); + fromwire_bitcoin_txid(&cursor, &plen, funding_txid); + *funding_txout = fromwire_u16(&cursor, &plen); + *funding_satoshi = fromwire_amount_sat(&cursor, &plen); + fromwire_pubkey(&cursor, &plen, local_fundingkey); + fromwire_pubkey(&cursor, &plen, remote_fundingkey); + *opener = fromwire_side(&cursor, &plen); + *local_sat = fromwire_amount_sat(&cursor, &plen); + *remote_sat = fromwire_amount_sat(&cursor, &plen); + *our_dust_limit = fromwire_amount_sat(&cursor, &plen); + *min_fee_satoshi = fromwire_amount_sat(&cursor, &plen); + *fee_limit_satoshi = fromwire_amount_sat(&cursor, &plen); + *initial_fee_satoshi = fromwire_amount_sat(&cursor, &plen); + local_scriptpubkey_len = fromwire_u16(&cursor, &plen); + // 2nd case local_scriptpubkey + *local_scriptpubkey = local_scriptpubkey_len ? tal_arr(ctx, u8, local_scriptpubkey_len) : NULL; + fromwire_u8_array(&cursor, &plen, *local_scriptpubkey, local_scriptpubkey_len); + remote_scriptpubkey_len = fromwire_u16(&cursor, &plen); + // 2nd case remote_scriptpubkey + *remote_scriptpubkey = remote_scriptpubkey_len ? tal_arr(ctx, u8, remote_scriptpubkey_len) : NULL; + fromwire_u8_array(&cursor, &plen, *remote_scriptpubkey, remote_scriptpubkey_len); + *fee_negotiation_step = fromwire_u64(&cursor, &plen); + *fee_negotiation_step_unit = fromwire_u8(&cursor, &plen); + *reconnected = fromwire_bool(&cursor, &plen); + *next_index_local = fromwire_u64(&cursor, &plen); + *next_index_remote = fromwire_u64(&cursor, &plen); + *revocations_received = fromwire_u64(&cursor, &plen); + channel_reestablish_len = fromwire_u16(&cursor, &plen); + // 2nd case channel_reestablish + *channel_reestablish = channel_reestablish_len ? tal_arr(ctx, u8, channel_reestablish_len) : NULL; + fromwire_u8_array(&cursor, &plen, *channel_reestablish, channel_reestablish_len); + fromwire_secret(&cursor, &plen, last_remote_secret); + *dev_fast_gossip = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CLOSINGD_RECEIVED_SIGNATURE */ +/* We received an offer */ +u8 *towire_closingd_received_signature(const tal_t *ctx, const struct bitcoin_signature *signature, const struct bitcoin_tx *tx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CLOSINGD_RECEIVED_SIGNATURE); + towire_bitcoin_signature(&p, signature); + towire_bitcoin_tx(&p, tx); + + return memcheck(p, tal_count(p)); +} +bool fromwire_closingd_received_signature(const tal_t *ctx, const void *p, struct bitcoin_signature *signature, struct bitcoin_tx **tx) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CLOSINGD_RECEIVED_SIGNATURE) + return false; + fromwire_bitcoin_signature(&cursor, &plen, signature); + *tx = fromwire_bitcoin_tx(ctx, &cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CLOSINGD_RECEIVED_SIGNATURE_REPLY */ +u8 *towire_closingd_received_signature_reply(const tal_t *ctx, const struct bitcoin_txid *closing_txid) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CLOSINGD_RECEIVED_SIGNATURE_REPLY); + towire_bitcoin_txid(&p, closing_txid); + + return memcheck(p, tal_count(p)); +} +bool fromwire_closingd_received_signature_reply(const void *p, struct bitcoin_txid *closing_txid) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CLOSINGD_RECEIVED_SIGNATURE_REPLY) + return false; + fromwire_bitcoin_txid(&cursor, &plen, closing_txid); + return cursor != NULL; +} + +/* WIRE: CLOSINGD_COMPLETE */ +/* Negotiations complete */ +u8 *towire_closingd_complete(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CLOSINGD_COMPLETE); + + return memcheck(p, tal_count(p)); +} +bool fromwire_closingd_complete(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CLOSINGD_COMPLETE) + return false; + return cursor != NULL; +} + +// SHA256STAMP:exp-0-b2eb7dca2466d016dd438807ca18e00f21b0dd59cfa74fe2875b3b57ef831d0f diff --git a/closingd/closingd_wiregen.h b/closingd/closingd_wiregen.h new file mode 100644 index 000000000..1ebe4d9ce --- /dev/null +++ b/closingd/closingd_wiregen.h @@ -0,0 +1,59 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the _csv file it was generated from. */ +/* Original template can be found at tools/gen/header_template */ + +#ifndef LIGHTNING_CLOSINGD_CLOSINGD_WIREGEN_H +#define LIGHTNING_CLOSINGD_CLOSINGD_WIREGEN_H +#include +#include +#include +#include +#include +#include +#include + +enum closingd_wire { + /* Begin! (passes peer fd */ + WIRE_CLOSINGD_INIT = 2001, + /* We received an offer */ + WIRE_CLOSINGD_RECEIVED_SIGNATURE = 2002, + WIRE_CLOSINGD_RECEIVED_SIGNATURE_REPLY = 2102, + /* Negotiations complete */ + WIRE_CLOSINGD_COMPLETE = 2004, +}; + +const char *closingd_wire_name(int e); + +/** + * Determine whether a given message type is defined as a message. + * + * Returns true if the message type is part of the message definitions we have + * generated parsers for, false if it is a custom message that cannot be + * handled internally. + */ +bool closingd_wire_is_defined(u16 type); + + +/* WIRE: CLOSINGD_INIT */ +/* Begin! (passes peer fd */ +u8 *towire_closingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct per_peer_state *pps, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, const struct pubkey *local_fundingkey, const struct pubkey *remote_fundingkey, enum side opener, struct amount_sat local_sat, struct amount_sat remote_sat, struct amount_sat our_dust_limit, struct amount_sat min_fee_satoshi, struct amount_sat fee_limit_satoshi, struct amount_sat initial_fee_satoshi, const u8 *local_scriptpubkey, const u8 *remote_scriptpubkey, u64 fee_negotiation_step, u8 fee_negotiation_step_unit, bool reconnected, u64 next_index_local, u64 next_index_remote, u64 revocations_received, const u8 *channel_reestablish, const struct secret *last_remote_secret, bool dev_fast_gossip); +bool fromwire_closingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct per_peer_state **pps, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, struct pubkey *local_fundingkey, struct pubkey *remote_fundingkey, enum side *opener, struct amount_sat *local_sat, struct amount_sat *remote_sat, struct amount_sat *our_dust_limit, struct amount_sat *min_fee_satoshi, struct amount_sat *fee_limit_satoshi, struct amount_sat *initial_fee_satoshi, u8 **local_scriptpubkey, u8 **remote_scriptpubkey, u64 *fee_negotiation_step, u8 *fee_negotiation_step_unit, bool *reconnected, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u8 **channel_reestablish, struct secret *last_remote_secret, bool *dev_fast_gossip); + +/* WIRE: CLOSINGD_RECEIVED_SIGNATURE */ +/* We received an offer */ +u8 *towire_closingd_received_signature(const tal_t *ctx, const struct bitcoin_signature *signature, const struct bitcoin_tx *tx); +bool fromwire_closingd_received_signature(const tal_t *ctx, const void *p, struct bitcoin_signature *signature, struct bitcoin_tx **tx); + +/* WIRE: CLOSINGD_RECEIVED_SIGNATURE_REPLY */ +u8 *towire_closingd_received_signature_reply(const tal_t *ctx, const struct bitcoin_txid *closing_txid); +bool fromwire_closingd_received_signature_reply(const void *p, struct bitcoin_txid *closing_txid); + +/* WIRE: CLOSINGD_COMPLETE */ +/* Negotiations complete */ +u8 *towire_closingd_complete(const tal_t *ctx); +bool fromwire_closingd_complete(const void *p); + + +#endif /* LIGHTNING_CLOSINGD_CLOSINGD_WIREGEN_H */ + +// SHA256STAMP:exp-0-b2eb7dca2466d016dd438807ca18e00f21b0dd59cfa74fe2875b3b57ef831d0f diff --git a/common/peer_status_wiregen.c b/common/peer_status_wiregen.c new file mode 100644 index 000000000..4555b448a --- /dev/null +++ b/common/peer_status_wiregen.c @@ -0,0 +1,84 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Original template can be found at tools/gen/impl_template */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef SUPERVERBOSE +#define SUPERVERBOSE(...) +#endif + + +const char *peer_status_wire_name(int e) +{ + static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; + + switch ((enum peer_status_wire)e) { + case WIRE_STATUS_PEER_ERROR: return "WIRE_STATUS_PEER_ERROR"; + } + + snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); + return invalidbuf; +} + +bool peer_status_wire_is_defined(u16 type) +{ + switch ((enum peer_status_wire)type) { + case WIRE_STATUS_PEER_ERROR:; + return true; + } + return false; +} + + + + + +/* WIRE: STATUS_PEER_ERROR */ +/* An error occurred: if error_for_them */ +u8 *towire_status_peer_error(const tal_t *ctx, const struct channel_id *channel, const wirestring *desc, bool soft_error, const struct per_peer_state *pps, const u8 *error_for_them) +{ + u16 len = tal_count(error_for_them); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_STATUS_PEER_ERROR); + /* This is implied if error_for_them */ + towire_channel_id(&p, channel); + towire_wirestring(&p, desc); + /* Take a deep breath */ + towire_bool(&p, soft_error); + towire_per_peer_state(&p, pps); + towire_u16(&p, len); + towire_u8_array(&p, error_for_them, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_status_peer_error(const tal_t *ctx, const void *p, struct channel_id *channel, wirestring **desc, bool *soft_error, struct per_peer_state **pps, u8 **error_for_them) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_STATUS_PEER_ERROR) + return false; + /* This is implied if error_for_them */ + fromwire_channel_id(&cursor, &plen, channel); + *desc = fromwire_wirestring(ctx, &cursor, &plen); + /* Take a deep breath */ + *soft_error = fromwire_bool(&cursor, &plen); + *pps = fromwire_per_peer_state(ctx, &cursor, &plen); + len = fromwire_u16(&cursor, &plen); + // 2nd case error_for_them + *error_for_them = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *error_for_them, len); + return cursor != NULL; +} + +// SHA256STAMP:exp-0-447e0325cb958a5eab33bc5a220a3cbf671d7a39edb7f9c3065ea04a8545cbd1 diff --git a/common/peer_status_wiregen.h b/common/peer_status_wiregen.h new file mode 100644 index 000000000..9b4b03970 --- /dev/null +++ b/common/peer_status_wiregen.h @@ -0,0 +1,38 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the _csv file it was generated from. */ +/* Original template can be found at tools/gen/header_template */ + +#ifndef LIGHTNING_COMMON_PEER_STATUS_WIREGEN_H +#define LIGHTNING_COMMON_PEER_STATUS_WIREGEN_H +#include +#include +#include +#include +#include + +enum peer_status_wire { + /* An error occurred: if error_for_them */ + WIRE_STATUS_PEER_ERROR = 0xFFF4, +}; + +const char *peer_status_wire_name(int e); + +/** + * Determine whether a given message type is defined as a message. + * + * Returns true if the message type is part of the message definitions we have + * generated parsers for, false if it is a custom message that cannot be + * handled internally. + */ +bool peer_status_wire_is_defined(u16 type); + + +/* WIRE: STATUS_PEER_ERROR */ +/* An error occurred: if error_for_them */ +u8 *towire_status_peer_error(const tal_t *ctx, const struct channel_id *channel, const wirestring *desc, bool soft_error, const struct per_peer_state *pps, const u8 *error_for_them); +bool fromwire_status_peer_error(const tal_t *ctx, const void *p, struct channel_id *channel, wirestring **desc, bool *soft_error, struct per_peer_state **pps, u8 **error_for_them); + + +#endif /* LIGHTNING_COMMON_PEER_STATUS_WIREGEN_H */ + +// SHA256STAMP:exp-0-56acee14dc485105152d9cd4d3015fa6d2f7ce1883d49ccece82e068b7f1af13 diff --git a/common/status_wiregen.c b/common/status_wiregen.c new file mode 100644 index 000000000..703c00666 --- /dev/null +++ b/common/status_wiregen.c @@ -0,0 +1,195 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Original template can be found at tools/gen/impl_template */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef SUPERVERBOSE +#define SUPERVERBOSE(...) +#endif + + +const char *status_wire_name(int e) +{ + static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; + + switch ((enum status_wire)e) { + case WIRE_STATUS_LOG: return "WIRE_STATUS_LOG"; + case WIRE_STATUS_IO: return "WIRE_STATUS_IO"; + case WIRE_STATUS_FAIL: return "WIRE_STATUS_FAIL"; + case WIRE_STATUS_PEER_CONNECTION_LOST: return "WIRE_STATUS_PEER_CONNECTION_LOST"; + case WIRE_STATUS_PEER_BILLBOARD: return "WIRE_STATUS_PEER_BILLBOARD"; + } + + snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); + return invalidbuf; +} + +bool status_wire_is_defined(u16 type) +{ + switch ((enum status_wire)type) { + case WIRE_STATUS_LOG:; + case WIRE_STATUS_IO:; + case WIRE_STATUS_FAIL:; + case WIRE_STATUS_PEER_CONNECTION_LOST:; + case WIRE_STATUS_PEER_BILLBOARD:; + return true; + } + return false; +} + + + + + +/* WIRE: STATUS_LOG */ +u8 *towire_status_log(const tal_t *ctx, enum log_level level, const struct node_id *peer, const wirestring *entry) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_STATUS_LOG); + towire_log_level(&p, level); + if (!peer) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_node_id(&p, peer); + } + towire_wirestring(&p, entry); + + return memcheck(p, tal_count(p)); +} +bool fromwire_status_log(const tal_t *ctx, const void *p, enum log_level *level, struct node_id **peer, wirestring **entry) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_STATUS_LOG) + return false; + *level = fromwire_log_level(&cursor, &plen); + if (!fromwire_bool(&cursor, &plen)) + *peer = NULL; + else { + *peer = tal(ctx, struct node_id); + fromwire_node_id(&cursor, &plen, *peer); + } + *entry = fromwire_wirestring(ctx, &cursor, &plen); + return cursor != NULL; +} + +/* WIRE: STATUS_IO */ +u8 *towire_status_io(const tal_t *ctx, enum log_level iodir, const struct node_id *peer, const wirestring *who, const u8 *data) +{ + u16 len = tal_count(data); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_STATUS_IO); + towire_log_level(&p, iodir); + if (!peer) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_node_id(&p, peer); + } + towire_wirestring(&p, who); + towire_u16(&p, len); + towire_u8_array(&p, data, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_status_io(const tal_t *ctx, const void *p, enum log_level *iodir, struct node_id **peer, wirestring **who, u8 **data) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_STATUS_IO) + return false; + *iodir = fromwire_log_level(&cursor, &plen); + if (!fromwire_bool(&cursor, &plen)) + *peer = NULL; + else { + *peer = tal(ctx, struct node_id); + fromwire_node_id(&cursor, &plen, *peer); + } + *who = fromwire_wirestring(ctx, &cursor, &plen); + len = fromwire_u16(&cursor, &plen); + // 2nd case data + *data = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *data, len); + return cursor != NULL; +} + +/* WIRE: STATUS_FAIL */ +u8 *towire_status_fail(const tal_t *ctx, enum status_failreason failreason, const wirestring *desc) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_STATUS_FAIL); + towire_status_failreason(&p, failreason); + towire_wirestring(&p, desc); + + return memcheck(p, tal_count(p)); +} +bool fromwire_status_fail(const tal_t *ctx, const void *p, enum status_failreason *failreason, wirestring **desc) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_STATUS_FAIL) + return false; + *failreason = fromwire_status_failreason(&cursor, &plen); + *desc = fromwire_wirestring(ctx, &cursor, &plen); + return cursor != NULL; +} + +/* WIRE: STATUS_PEER_CONNECTION_LOST */ +u8 *towire_status_peer_connection_lost(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_STATUS_PEER_CONNECTION_LOST); + + return memcheck(p, tal_count(p)); +} +bool fromwire_status_peer_connection_lost(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_STATUS_PEER_CONNECTION_LOST) + return false; + return cursor != NULL; +} + +/* WIRE: STATUS_PEER_BILLBOARD */ +u8 *towire_status_peer_billboard(const tal_t *ctx, bool perm, const wirestring *happenings) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_STATUS_PEER_BILLBOARD); + towire_bool(&p, perm); + towire_wirestring(&p, happenings); + + return memcheck(p, tal_count(p)); +} +bool fromwire_status_peer_billboard(const tal_t *ctx, const void *p, bool *perm, wirestring **happenings) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_STATUS_PEER_BILLBOARD) + return false; + *perm = fromwire_bool(&cursor, &plen); + *happenings = fromwire_wirestring(ctx, &cursor, &plen); + return cursor != NULL; +} + +// SHA256STAMP:exp-0-4d2dbdbf0583d8c35594ef3c14ec80fc1ad4e8d00ee8f1dca0c57293ac41d17e diff --git a/common/status_wiregen.h b/common/status_wiregen.h new file mode 100644 index 000000000..ee0fd17c3 --- /dev/null +++ b/common/status_wiregen.h @@ -0,0 +1,57 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the _csv file it was generated from. */ +/* Original template can be found at tools/gen/header_template */ + +#ifndef LIGHTNING_COMMON_STATUS_WIREGEN_H +#define LIGHTNING_COMMON_STATUS_WIREGEN_H +#include +#include +#include +#include +#include +#include + +enum status_wire { + WIRE_STATUS_LOG = 0xFFF0, + WIRE_STATUS_IO = 0xFFF1, + WIRE_STATUS_FAIL = 0xFFF2, + WIRE_STATUS_PEER_CONNECTION_LOST = 0xFFF3, + WIRE_STATUS_PEER_BILLBOARD = 0xFFF5, +}; + +const char *status_wire_name(int e); + +/** + * Determine whether a given message type is defined as a message. + * + * Returns true if the message type is part of the message definitions we have + * generated parsers for, false if it is a custom message that cannot be + * handled internally. + */ +bool status_wire_is_defined(u16 type); + + +/* WIRE: STATUS_LOG */ +u8 *towire_status_log(const tal_t *ctx, enum log_level level, const struct node_id *peer, const wirestring *entry); +bool fromwire_status_log(const tal_t *ctx, const void *p, enum log_level *level, struct node_id **peer, wirestring **entry); + +/* WIRE: STATUS_IO */ +u8 *towire_status_io(const tal_t *ctx, enum log_level iodir, const struct node_id *peer, const wirestring *who, const u8 *data); +bool fromwire_status_io(const tal_t *ctx, const void *p, enum log_level *iodir, struct node_id **peer, wirestring **who, u8 **data); + +/* WIRE: STATUS_FAIL */ +u8 *towire_status_fail(const tal_t *ctx, enum status_failreason failreason, const wirestring *desc); +bool fromwire_status_fail(const tal_t *ctx, const void *p, enum status_failreason *failreason, wirestring **desc); + +/* WIRE: STATUS_PEER_CONNECTION_LOST */ +u8 *towire_status_peer_connection_lost(const tal_t *ctx); +bool fromwire_status_peer_connection_lost(const void *p); + +/* WIRE: STATUS_PEER_BILLBOARD */ +u8 *towire_status_peer_billboard(const tal_t *ctx, bool perm, const wirestring *happenings); +bool fromwire_status_peer_billboard(const tal_t *ctx, const void *p, bool *perm, wirestring **happenings); + + +#endif /* LIGHTNING_COMMON_STATUS_WIREGEN_H */ + +// SHA256STAMP:exp-0-6b371939fcb8fc39758a17167e1b95bae1ac2cf61f207e530711aeba6838eb4f diff --git a/connectd/connectd_gossipd_wiregen.c b/connectd/connectd_gossipd_wiregen.c new file mode 100644 index 000000000..68d28688d --- /dev/null +++ b/connectd/connectd_gossipd_wiregen.c @@ -0,0 +1,165 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Original template can be found at tools/gen/impl_template */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef SUPERVERBOSE +#define SUPERVERBOSE(...) +#endif + + +const char *connectd_gossipd_wire_name(int e) +{ + static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; + + switch ((enum connectd_gossipd_wire)e) { + case WIRE_GOSSIPD_NEW_PEER: return "WIRE_GOSSIPD_NEW_PEER"; + case WIRE_GOSSIPD_NEW_PEER_REPLY: return "WIRE_GOSSIPD_NEW_PEER_REPLY"; + case WIRE_GOSSIPD_GET_ADDRS: return "WIRE_GOSSIPD_GET_ADDRS"; + case WIRE_GOSSIPD_GET_ADDRS_REPLY: return "WIRE_GOSSIPD_GET_ADDRS_REPLY"; + } + + snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); + return invalidbuf; +} + +bool connectd_gossipd_wire_is_defined(u16 type) +{ + switch ((enum connectd_gossipd_wire)type) { + case WIRE_GOSSIPD_NEW_PEER:; + case WIRE_GOSSIPD_NEW_PEER_REPLY:; + case WIRE_GOSSIPD_GET_ADDRS:; + case WIRE_GOSSIPD_GET_ADDRS_REPLY:; + return true; + } + return false; +} + + + + + +/* WIRE: GOSSIPD_NEW_PEER */ +/* Communication between gossipd and connectd. */ +u8 *towire_gossipd_new_peer(const tal_t *ctx, const struct node_id *id, bool gossip_queries_feature, bool initial_routing_sync) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_NEW_PEER); + towire_node_id(&p, id); + /* Did we negotiate LOCAL_GOSSIP_QUERIES? */ + towire_bool(&p, gossip_queries_feature); + /* Did they offer LOCAL_INITIAL_ROUTING_SYNC? */ + towire_bool(&p, initial_routing_sync); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_new_peer(const void *p, struct node_id *id, bool *gossip_queries_feature, bool *initial_routing_sync) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_NEW_PEER) + return false; + fromwire_node_id(&cursor, &plen, id); + /* Did we negotiate LOCAL_GOSSIP_QUERIES? */ + *gossip_queries_feature = fromwire_bool(&cursor, &plen); + /* Did they offer LOCAL_INITIAL_ROUTING_SYNC? */ + *initial_routing_sync = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_NEW_PEER_REPLY */ +/* if success: + gossip fd and gossip_store fd */ +u8 *towire_gossipd_new_peer_reply(const tal_t *ctx, bool success, const struct gossip_state *gs) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_NEW_PEER_REPLY); + towire_bool(&p, success); + if (!gs) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_gossip_state(&p, gs); + } + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_new_peer_reply(const tal_t *ctx, const void *p, bool *success, struct gossip_state **gs) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_NEW_PEER_REPLY) + return false; + *success = fromwire_bool(&cursor, &plen); + if (!fromwire_bool(&cursor, &plen)) + *gs = NULL; + else { + *gs = tal(ctx, struct gossip_state); + fromwire_gossip_state(&cursor, &plen, *gs); + } + return cursor != NULL; +} + +/* WIRE: GOSSIPD_GET_ADDRS */ +/* Connectd asks gossipd for any known addresses for that node. */ +u8 *towire_gossipd_get_addrs(const tal_t *ctx, const struct node_id *id) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GET_ADDRS); + towire_node_id(&p, id); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_get_addrs(const void *p, struct node_id *id) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GET_ADDRS) + return false; + fromwire_node_id(&cursor, &plen, id); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_GET_ADDRS_REPLY */ +u8 *towire_gossipd_get_addrs_reply(const tal_t *ctx, const struct wireaddr *addrs) +{ + u16 num = tal_count(addrs); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GET_ADDRS_REPLY); + towire_u16(&p, num); + for (size_t i = 0; i < num; i++) + towire_wireaddr(&p, addrs + i); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_get_addrs_reply(const tal_t *ctx, const void *p, struct wireaddr **addrs) +{ + u16 num; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GET_ADDRS_REPLY) + return false; + num = fromwire_u16(&cursor, &plen); + // 2nd case addrs + *addrs = num ? tal_arr(ctx, struct wireaddr, num) : NULL; + for (size_t i = 0; i < num; i++) + fromwire_wireaddr(&cursor, &plen, *addrs + i); + return cursor != NULL; +} + +// SHA256STAMP:exp-0-bd0f96afda71fed3790c8a0a1596bafff24b5b7b648d68e7c31d5e44970cda47 diff --git a/connectd/connectd_gossipd_wiregen.h b/connectd/connectd_gossipd_wiregen.h new file mode 100644 index 000000000..2c44cb830 --- /dev/null +++ b/connectd/connectd_gossipd_wiregen.h @@ -0,0 +1,58 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the _csv file it was generated from. */ +/* Original template can be found at tools/gen/header_template */ + +#ifndef LIGHTNING_CONNECTD_CONNECTD_GOSSIPD_WIREGEN_H +#define LIGHTNING_CONNECTD_CONNECTD_GOSSIPD_WIREGEN_H +#include +#include +#include +#include +#include +#include + +enum connectd_gossipd_wire { + /* Communication between gossipd and connectd. */ + WIRE_GOSSIPD_NEW_PEER = 4000, + /* if success: + gossip fd and gossip_store fd */ + WIRE_GOSSIPD_NEW_PEER_REPLY = 4100, + /* Connectd asks gossipd for any known addresses for that node. */ + WIRE_GOSSIPD_GET_ADDRS = 4001, + WIRE_GOSSIPD_GET_ADDRS_REPLY = 4101, +}; + +const char *connectd_gossipd_wire_name(int e); + +/** + * Determine whether a given message type is defined as a message. + * + * Returns true if the message type is part of the message definitions we have + * generated parsers for, false if it is a custom message that cannot be + * handled internally. + */ +bool connectd_gossipd_wire_is_defined(u16 type); + + +/* WIRE: GOSSIPD_NEW_PEER */ +/* Communication between gossipd and connectd. */ +u8 *towire_gossipd_new_peer(const tal_t *ctx, const struct node_id *id, bool gossip_queries_feature, bool initial_routing_sync); +bool fromwire_gossipd_new_peer(const void *p, struct node_id *id, bool *gossip_queries_feature, bool *initial_routing_sync); + +/* WIRE: GOSSIPD_NEW_PEER_REPLY */ +/* if success: + gossip fd and gossip_store fd */ +u8 *towire_gossipd_new_peer_reply(const tal_t *ctx, bool success, const struct gossip_state *gs); +bool fromwire_gossipd_new_peer_reply(const tal_t *ctx, const void *p, bool *success, struct gossip_state **gs); + +/* WIRE: GOSSIPD_GET_ADDRS */ +/* Connectd asks gossipd for any known addresses for that node. */ +u8 *towire_gossipd_get_addrs(const tal_t *ctx, const struct node_id *id); +bool fromwire_gossipd_get_addrs(const void *p, struct node_id *id); + +/* WIRE: GOSSIPD_GET_ADDRS_REPLY */ +u8 *towire_gossipd_get_addrs_reply(const tal_t *ctx, const struct wireaddr *addrs); +bool fromwire_gossipd_get_addrs_reply(const tal_t *ctx, const void *p, struct wireaddr **addrs); + + +#endif /* LIGHTNING_CONNECTD_CONNECTD_GOSSIPD_WIREGEN_H */ + +// SHA256STAMP:exp-0-bd0f96afda71fed3790c8a0a1596bafff24b5b7b648d68e7c31d5e44970cda47 diff --git a/connectd/connectd_wiregen.c b/connectd/connectd_wiregen.c new file mode 100644 index 000000000..0dedcdaaa --- /dev/null +++ b/connectd/connectd_wiregen.c @@ -0,0 +1,408 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Original template can be found at tools/gen/impl_template */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef SUPERVERBOSE +#define SUPERVERBOSE(...) +#endif + + +const char *connectd_wire_name(int e) +{ + static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; + + switch ((enum connectd_wire)e) { + case WIRE_CONNECTD_INIT: return "WIRE_CONNECTD_INIT"; + case WIRE_CONNECTD_INIT_REPLY: return "WIRE_CONNECTD_INIT_REPLY"; + case WIRE_CONNECTD_ACTIVATE: return "WIRE_CONNECTD_ACTIVATE"; + case WIRE_CONNECTD_ACTIVATE_REPLY: return "WIRE_CONNECTD_ACTIVATE_REPLY"; + case WIRE_CONNECTD_RECONNECTED: return "WIRE_CONNECTD_RECONNECTED"; + case WIRE_CONNECTD_CONNECT_TO_PEER: return "WIRE_CONNECTD_CONNECT_TO_PEER"; + case WIRE_CONNECTD_CONNECT_FAILED: return "WIRE_CONNECTD_CONNECT_FAILED"; + case WIRE_CONNECTD_PEER_CONNECTED: return "WIRE_CONNECTD_PEER_CONNECTED"; + case WIRE_CONNECTD_PEER_DISCONNECTED: return "WIRE_CONNECTD_PEER_DISCONNECTED"; + case WIRE_CONNECTD_DEV_MEMLEAK: return "WIRE_CONNECTD_DEV_MEMLEAK"; + case WIRE_CONNECTD_DEV_MEMLEAK_REPLY: return "WIRE_CONNECTD_DEV_MEMLEAK_REPLY"; + } + + snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); + return invalidbuf; +} + +bool connectd_wire_is_defined(u16 type) +{ + switch ((enum connectd_wire)type) { + case WIRE_CONNECTD_INIT:; + case WIRE_CONNECTD_INIT_REPLY:; + case WIRE_CONNECTD_ACTIVATE:; + case WIRE_CONNECTD_ACTIVATE_REPLY:; + case WIRE_CONNECTD_RECONNECTED:; + case WIRE_CONNECTD_CONNECT_TO_PEER:; + case WIRE_CONNECTD_CONNECT_FAILED:; + case WIRE_CONNECTD_PEER_CONNECTED:; + case WIRE_CONNECTD_PEER_DISCONNECTED:; + case WIRE_CONNECTD_DEV_MEMLEAK:; + case WIRE_CONNECTD_DEV_MEMLEAK_REPLY:; + return true; + } + return false; +} + + + + + +/* WIRE: CONNECTD_INIT */ +u8 *towire_connectd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct node_id *id, const struct wireaddr_internal *wireaddrs, const enum addr_listen_announce *listen_announce, const struct wireaddr *tor_proxyaddr, bool use_tor_proxy_always, bool dev_allow_localhost, bool use_dns, const wirestring *tor_password, bool use_v3_autotor) +{ + u16 num_wireaddrs = tal_count(listen_announce); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CONNECTD_INIT); + towire_chainparams(&p, chainparams); + towire_feature_set(&p, our_features); + towire_node_id(&p, id); + towire_u16(&p, num_wireaddrs); + for (size_t i = 0; i < num_wireaddrs; i++) + towire_wireaddr_internal(&p, wireaddrs + i); + for (size_t i = 0; i < num_wireaddrs; i++) + towire_addr_listen_announce(&p, listen_announce[i]); + if (!tor_proxyaddr) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_wireaddr(&p, tor_proxyaddr); + } + towire_bool(&p, use_tor_proxy_always); + towire_bool(&p, dev_allow_localhost); + towire_bool(&p, use_dns); + towire_wirestring(&p, tor_password); + towire_bool(&p, use_v3_autotor); + + return memcheck(p, tal_count(p)); +} +bool fromwire_connectd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct node_id *id, struct wireaddr_internal **wireaddrs, enum addr_listen_announce **listen_announce, struct wireaddr **tor_proxyaddr, bool *use_tor_proxy_always, bool *dev_allow_localhost, bool *use_dns, wirestring **tor_password, bool *use_v3_autotor) +{ + u16 num_wireaddrs; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CONNECTD_INIT) + return false; + fromwire_chainparams(&cursor, &plen, chainparams); + *our_features = fromwire_feature_set(ctx, &cursor, &plen); + fromwire_node_id(&cursor, &plen, id); + num_wireaddrs = fromwire_u16(&cursor, &plen); + // 2nd case wireaddrs + *wireaddrs = num_wireaddrs ? tal_arr(ctx, struct wireaddr_internal, num_wireaddrs) : NULL; + for (size_t i = 0; i < num_wireaddrs; i++) + fromwire_wireaddr_internal(&cursor, &plen, *wireaddrs + i); + // 2nd case listen_announce + *listen_announce = num_wireaddrs ? tal_arr(ctx, enum addr_listen_announce, num_wireaddrs) : NULL; + for (size_t i = 0; i < num_wireaddrs; i++) + (*listen_announce)[i] = fromwire_addr_listen_announce(&cursor, &plen); + if (!fromwire_bool(&cursor, &plen)) + *tor_proxyaddr = NULL; + else { + *tor_proxyaddr = tal(ctx, struct wireaddr); + fromwire_wireaddr(&cursor, &plen, *tor_proxyaddr); + } + *use_tor_proxy_always = fromwire_bool(&cursor, &plen); + *dev_allow_localhost = fromwire_bool(&cursor, &plen); + *use_dns = fromwire_bool(&cursor, &plen); + *tor_password = fromwire_wirestring(ctx, &cursor, &plen); + *use_v3_autotor = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CONNECTD_INIT_REPLY */ +/* Connectd->master */ +u8 *towire_connectd_init_reply(const tal_t *ctx, const struct wireaddr_internal *bindings, const struct wireaddr *announcable) +{ + u16 num_bindings = tal_count(bindings); + u16 num_announcable = tal_count(announcable); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CONNECTD_INIT_REPLY); + towire_u16(&p, num_bindings); + for (size_t i = 0; i < num_bindings; i++) + towire_wireaddr_internal(&p, bindings + i); + towire_u16(&p, num_announcable); + for (size_t i = 0; i < num_announcable; i++) + towire_wireaddr(&p, announcable + i); + + return memcheck(p, tal_count(p)); +} +bool fromwire_connectd_init_reply(const tal_t *ctx, const void *p, struct wireaddr_internal **bindings, struct wireaddr **announcable) +{ + u16 num_bindings; + u16 num_announcable; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CONNECTD_INIT_REPLY) + return false; + num_bindings = fromwire_u16(&cursor, &plen); + // 2nd case bindings + *bindings = num_bindings ? tal_arr(ctx, struct wireaddr_internal, num_bindings) : NULL; + for (size_t i = 0; i < num_bindings; i++) + fromwire_wireaddr_internal(&cursor, &plen, *bindings + i); + num_announcable = fromwire_u16(&cursor, &plen); + // 2nd case announcable + *announcable = num_announcable ? tal_arr(ctx, struct wireaddr, num_announcable) : NULL; + for (size_t i = 0; i < num_announcable; i++) + fromwire_wireaddr(&cursor, &plen, *announcable + i); + return cursor != NULL; +} + +/* WIRE: CONNECTD_ACTIVATE */ +/* Activate the connect daemon */ +u8 *towire_connectd_activate(const tal_t *ctx, bool listen) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CONNECTD_ACTIVATE); + /* Do we listen? */ + towire_bool(&p, listen); + + return memcheck(p, tal_count(p)); +} +bool fromwire_connectd_activate(const void *p, bool *listen) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CONNECTD_ACTIVATE) + return false; + /* Do we listen? */ + *listen = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CONNECTD_ACTIVATE_REPLY */ +/* Connectd->master */ +u8 *towire_connectd_activate_reply(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CONNECTD_ACTIVATE_REPLY); + + return memcheck(p, tal_count(p)); +} +bool fromwire_connectd_activate_reply(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CONNECTD_ACTIVATE_REPLY) + return false; + return cursor != NULL; +} + +/* WIRE: CONNECTD_RECONNECTED */ +/* connectd->master: disconnect this peer please (due to reconnect). */ +u8 *towire_connectd_reconnected(const tal_t *ctx, const struct node_id *id) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CONNECTD_RECONNECTED); + towire_node_id(&p, id); + + return memcheck(p, tal_count(p)); +} +bool fromwire_connectd_reconnected(const void *p, struct node_id *id) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CONNECTD_RECONNECTED) + return false; + fromwire_node_id(&cursor, &plen, id); + return cursor != NULL; +} + +/* WIRE: CONNECTD_CONNECT_TO_PEER */ +/* Master -> connectd: connect to a peer. */ +u8 *towire_connectd_connect_to_peer(const tal_t *ctx, const struct node_id *id, u32 seconds_waited, const struct wireaddr_internal *addrhint) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CONNECTD_CONNECT_TO_PEER); + towire_node_id(&p, id); + towire_u32(&p, seconds_waited); + if (!addrhint) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_wireaddr_internal(&p, addrhint); + } + + return memcheck(p, tal_count(p)); +} +bool fromwire_connectd_connect_to_peer(const tal_t *ctx, const void *p, struct node_id *id, u32 *seconds_waited, struct wireaddr_internal **addrhint) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CONNECTD_CONNECT_TO_PEER) + return false; + fromwire_node_id(&cursor, &plen, id); + *seconds_waited = fromwire_u32(&cursor, &plen); + if (!fromwire_bool(&cursor, &plen)) + *addrhint = NULL; + else { + *addrhint = tal(ctx, struct wireaddr_internal); + fromwire_wireaddr_internal(&cursor, &plen, *addrhint); + } + return cursor != NULL; +} + +/* WIRE: CONNECTD_CONNECT_FAILED */ +/* Connectd->master: connect failed. */ +u8 *towire_connectd_connect_failed(const tal_t *ctx, const struct node_id *id, errcode_t failcode, const wirestring *failreason, u32 seconds_to_delay, const struct wireaddr_internal *addrhint) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CONNECTD_CONNECT_FAILED); + towire_node_id(&p, id); + towire_errcode_t(&p, failcode); + towire_wirestring(&p, failreason); + towire_u32(&p, seconds_to_delay); + if (!addrhint) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_wireaddr_internal(&p, addrhint); + } + + return memcheck(p, tal_count(p)); +} +bool fromwire_connectd_connect_failed(const tal_t *ctx, const void *p, struct node_id *id, errcode_t *failcode, wirestring **failreason, u32 *seconds_to_delay, struct wireaddr_internal **addrhint) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CONNECTD_CONNECT_FAILED) + return false; + fromwire_node_id(&cursor, &plen, id); + *failcode = fromwire_errcode_t(&cursor, &plen); + *failreason = fromwire_wirestring(ctx, &cursor, &plen); + *seconds_to_delay = fromwire_u32(&cursor, &plen); + if (!fromwire_bool(&cursor, &plen)) + *addrhint = NULL; + else { + *addrhint = tal(ctx, struct wireaddr_internal); + fromwire_wireaddr_internal(&cursor, &plen, *addrhint); + } + return cursor != NULL; +} + +/* WIRE: CONNECTD_PEER_CONNECTED */ +/* Connectd -> master: we got a peer. Three fds: peer */ +u8 *towire_connectd_peer_connected(const tal_t *ctx, const struct node_id *id, const struct wireaddr_internal *addr, const struct per_peer_state *pps, const u8 *features) +{ + u16 flen = tal_count(features); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CONNECTD_PEER_CONNECTED); + towire_node_id(&p, id); + towire_wireaddr_internal(&p, addr); + towire_per_peer_state(&p, pps); + towire_u16(&p, flen); + towire_u8_array(&p, features, flen); + + return memcheck(p, tal_count(p)); +} +bool fromwire_connectd_peer_connected(const tal_t *ctx, const void *p, struct node_id *id, struct wireaddr_internal *addr, struct per_peer_state **pps, u8 **features) +{ + u16 flen; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CONNECTD_PEER_CONNECTED) + return false; + fromwire_node_id(&cursor, &plen, id); + fromwire_wireaddr_internal(&cursor, &plen, addr); + *pps = fromwire_per_peer_state(ctx, &cursor, &plen); + flen = fromwire_u16(&cursor, &plen); + // 2nd case features + *features = flen ? tal_arr(ctx, u8, flen) : NULL; + fromwire_u8_array(&cursor, &plen, *features, flen); + return cursor != NULL; +} + +/* WIRE: CONNECTD_PEER_DISCONNECTED */ +/* master -> connectd: peer has disconnected. */ +u8 *towire_connectd_peer_disconnected(const tal_t *ctx, const struct node_id *id) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CONNECTD_PEER_DISCONNECTED); + towire_node_id(&p, id); + + return memcheck(p, tal_count(p)); +} +bool fromwire_connectd_peer_disconnected(const void *p, struct node_id *id) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CONNECTD_PEER_DISCONNECTED) + return false; + fromwire_node_id(&cursor, &plen, id); + return cursor != NULL; +} + +/* WIRE: CONNECTD_DEV_MEMLEAK */ +/* master -> connectd: do you have a memleak? */ +u8 *towire_connectd_dev_memleak(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CONNECTD_DEV_MEMLEAK); + + return memcheck(p, tal_count(p)); +} +bool fromwire_connectd_dev_memleak(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CONNECTD_DEV_MEMLEAK) + return false; + return cursor != NULL; +} + +/* WIRE: CONNECTD_DEV_MEMLEAK_REPLY */ +u8 *towire_connectd_dev_memleak_reply(const tal_t *ctx, bool leak) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CONNECTD_DEV_MEMLEAK_REPLY); + towire_bool(&p, leak); + + return memcheck(p, tal_count(p)); +} +bool fromwire_connectd_dev_memleak_reply(const void *p, bool *leak) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CONNECTD_DEV_MEMLEAK_REPLY) + return false; + *leak = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +// SHA256STAMP:exp-0-ccc7cf60dccc364d13a7516e726d17d3f90664d91d4fc845ac77c23d4af298f5 diff --git a/connectd/connectd_wiregen.h b/connectd/connectd_wiregen.h new file mode 100644 index 000000000..58955d06c --- /dev/null +++ b/connectd/connectd_wiregen.h @@ -0,0 +1,107 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the _csv file it was generated from. */ +/* Original template can be found at tools/gen/header_template */ + +#ifndef LIGHTNING_CONNECTD_CONNECTD_WIREGEN_H +#define LIGHTNING_CONNECTD_CONNECTD_WIREGEN_H +#include +#include +#include +#include +#include +#include +#include +#include + +enum connectd_wire { + WIRE_CONNECTD_INIT = 2000, + /* Connectd->master */ + WIRE_CONNECTD_INIT_REPLY = 2100, + /* Activate the connect daemon */ + WIRE_CONNECTD_ACTIVATE = 2025, + /* Connectd->master */ + WIRE_CONNECTD_ACTIVATE_REPLY = 2125, + /* connectd->master: disconnect this peer please (due to reconnect). */ + WIRE_CONNECTD_RECONNECTED = 2112, + /* Master -> connectd: connect to a peer. */ + WIRE_CONNECTD_CONNECT_TO_PEER = 2001, + /* Connectd->master: connect failed. */ + WIRE_CONNECTD_CONNECT_FAILED = 2020, + /* Connectd -> master: we got a peer. Three fds: peer */ + WIRE_CONNECTD_PEER_CONNECTED = 2002, + /* master -> connectd: peer has disconnected. */ + WIRE_CONNECTD_PEER_DISCONNECTED = 2015, + /* master -> connectd: do you have a memleak? */ + WIRE_CONNECTD_DEV_MEMLEAK = 2033, + WIRE_CONNECTD_DEV_MEMLEAK_REPLY = 2133, +}; + +const char *connectd_wire_name(int e); + +/** + * Determine whether a given message type is defined as a message. + * + * Returns true if the message type is part of the message definitions we have + * generated parsers for, false if it is a custom message that cannot be + * handled internally. + */ +bool connectd_wire_is_defined(u16 type); + + +/* WIRE: CONNECTD_INIT */ +u8 *towire_connectd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct node_id *id, const struct wireaddr_internal *wireaddrs, const enum addr_listen_announce *listen_announce, const struct wireaddr *tor_proxyaddr, bool use_tor_proxy_always, bool dev_allow_localhost, bool use_dns, const wirestring *tor_password, bool use_v3_autotor); +bool fromwire_connectd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct node_id *id, struct wireaddr_internal **wireaddrs, enum addr_listen_announce **listen_announce, struct wireaddr **tor_proxyaddr, bool *use_tor_proxy_always, bool *dev_allow_localhost, bool *use_dns, wirestring **tor_password, bool *use_v3_autotor); + +/* WIRE: CONNECTD_INIT_REPLY */ +/* Connectd->master */ +u8 *towire_connectd_init_reply(const tal_t *ctx, const struct wireaddr_internal *bindings, const struct wireaddr *announcable); +bool fromwire_connectd_init_reply(const tal_t *ctx, const void *p, struct wireaddr_internal **bindings, struct wireaddr **announcable); + +/* WIRE: CONNECTD_ACTIVATE */ +/* Activate the connect daemon */ +u8 *towire_connectd_activate(const tal_t *ctx, bool listen); +bool fromwire_connectd_activate(const void *p, bool *listen); + +/* WIRE: CONNECTD_ACTIVATE_REPLY */ +/* Connectd->master */ +u8 *towire_connectd_activate_reply(const tal_t *ctx); +bool fromwire_connectd_activate_reply(const void *p); + +/* WIRE: CONNECTD_RECONNECTED */ +/* connectd->master: disconnect this peer please (due to reconnect). */ +u8 *towire_connectd_reconnected(const tal_t *ctx, const struct node_id *id); +bool fromwire_connectd_reconnected(const void *p, struct node_id *id); + +/* WIRE: CONNECTD_CONNECT_TO_PEER */ +/* Master -> connectd: connect to a peer. */ +u8 *towire_connectd_connect_to_peer(const tal_t *ctx, const struct node_id *id, u32 seconds_waited, const struct wireaddr_internal *addrhint); +bool fromwire_connectd_connect_to_peer(const tal_t *ctx, const void *p, struct node_id *id, u32 *seconds_waited, struct wireaddr_internal **addrhint); + +/* WIRE: CONNECTD_CONNECT_FAILED */ +/* Connectd->master: connect failed. */ +u8 *towire_connectd_connect_failed(const tal_t *ctx, const struct node_id *id, errcode_t failcode, const wirestring *failreason, u32 seconds_to_delay, const struct wireaddr_internal *addrhint); +bool fromwire_connectd_connect_failed(const tal_t *ctx, const void *p, struct node_id *id, errcode_t *failcode, wirestring **failreason, u32 *seconds_to_delay, struct wireaddr_internal **addrhint); + +/* WIRE: CONNECTD_PEER_CONNECTED */ +/* Connectd -> master: we got a peer. Three fds: peer */ +u8 *towire_connectd_peer_connected(const tal_t *ctx, const struct node_id *id, const struct wireaddr_internal *addr, const struct per_peer_state *pps, const u8 *features); +bool fromwire_connectd_peer_connected(const tal_t *ctx, const void *p, struct node_id *id, struct wireaddr_internal *addr, struct per_peer_state **pps, u8 **features); + +/* WIRE: CONNECTD_PEER_DISCONNECTED */ +/* master -> connectd: peer has disconnected. */ +u8 *towire_connectd_peer_disconnected(const tal_t *ctx, const struct node_id *id); +bool fromwire_connectd_peer_disconnected(const void *p, struct node_id *id); + +/* WIRE: CONNECTD_DEV_MEMLEAK */ +/* master -> connectd: do you have a memleak? */ +u8 *towire_connectd_dev_memleak(const tal_t *ctx); +bool fromwire_connectd_dev_memleak(const void *p); + +/* WIRE: CONNECTD_DEV_MEMLEAK_REPLY */ +u8 *towire_connectd_dev_memleak_reply(const tal_t *ctx, bool leak); +bool fromwire_connectd_dev_memleak_reply(const void *p, bool *leak); + + +#endif /* LIGHTNING_CONNECTD_CONNECTD_WIREGEN_H */ + +// SHA256STAMP:exp-0-ccc7cf60dccc364d13a7516e726d17d3f90664d91d4fc845ac77c23d4af298f5 diff --git a/gossipd/gossip_store_wiregen.c b/gossipd/gossip_store_wiregen.c new file mode 100644 index 000000000..d5c0ab224 --- /dev/null +++ b/gossipd/gossip_store_wiregen.c @@ -0,0 +1,121 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Original template can be found at tools/gen/impl_template */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef SUPERVERBOSE +#define SUPERVERBOSE(...) +#endif + +/* gossip_store messages: messages persisted in the gossip_store */ +/* We store raw messages here */ +/* 256/257/258 or gossipd_local_add_channel (3503) */ + +const char *gossip_store_wire_name(int e) +{ + static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; + + switch ((enum gossip_store_wire)e) { + case WIRE_GOSSIP_STORE_CHANNEL_AMOUNT: return "WIRE_GOSSIP_STORE_CHANNEL_AMOUNT"; + case WIRE_GOSSIP_STORE_PRIVATE_UPDATE: return "WIRE_GOSSIP_STORE_PRIVATE_UPDATE"; + case WIRE_GOSSIP_STORE_DELETE_CHAN: return "WIRE_GOSSIP_STORE_DELETE_CHAN"; + } + + snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); + return invalidbuf; +} + +bool gossip_store_wire_is_defined(u16 type) +{ + switch ((enum gossip_store_wire)type) { + case WIRE_GOSSIP_STORE_CHANNEL_AMOUNT:; + case WIRE_GOSSIP_STORE_PRIVATE_UPDATE:; + case WIRE_GOSSIP_STORE_DELETE_CHAN:; + return true; + } + return false; +} + + + + + +/* WIRE: GOSSIP_STORE_CHANNEL_AMOUNT */ +/* This always follows the channel_announce. */ +u8 *towire_gossip_store_channel_amount(const tal_t *ctx, struct amount_sat satoshis) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIP_STORE_CHANNEL_AMOUNT); + towire_amount_sat(&p, satoshis); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossip_store_channel_amount(const void *p, struct amount_sat *satoshis) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIP_STORE_CHANNEL_AMOUNT) + return false; + *satoshis = fromwire_amount_sat(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIP_STORE_PRIVATE_UPDATE */ +u8 *towire_gossip_store_private_update(const tal_t *ctx, const u8 *update) +{ + u16 len = tal_count(update); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIP_STORE_PRIVATE_UPDATE); + towire_u16(&p, len); + towire_u8_array(&p, update, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossip_store_private_update(const tal_t *ctx, const void *p, u8 **update) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIP_STORE_PRIVATE_UPDATE) + return false; + len = fromwire_u16(&cursor, &plen); + // 2nd case update + *update = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *update, len); + return cursor != NULL; +} + +/* WIRE: GOSSIP_STORE_DELETE_CHAN */ +u8 *towire_gossip_store_delete_chan(const tal_t *ctx, const struct short_channel_id *scid) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIP_STORE_DELETE_CHAN); + towire_short_channel_id(&p, scid); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossip_store_delete_chan(const void *p, struct short_channel_id *scid) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIP_STORE_DELETE_CHAN) + return false; + fromwire_short_channel_id(&cursor, &plen, scid); + return cursor != NULL; +} + +// SHA256STAMP:exp-0-184dda49fa00adc7b82ffc843580a139d17d915c890228fc1a2a8a4383e016ae diff --git a/gossipd/gossip_store_wiregen.h b/gossipd/gossip_store_wiregen.h new file mode 100644 index 000000000..81a7e2db1 --- /dev/null +++ b/gossipd/gossip_store_wiregen.h @@ -0,0 +1,47 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the _csv file it was generated from. */ +/* Original template can be found at tools/gen/header_template */ + +#ifndef LIGHTNING_GOSSIPD_GOSSIP_STORE_WIREGEN_H +#define LIGHTNING_GOSSIPD_GOSSIP_STORE_WIREGEN_H +#include +#include +#include +#include + +enum gossip_store_wire { + /* This always follows the channel_announce. */ + WIRE_GOSSIP_STORE_CHANNEL_AMOUNT = 4101, + WIRE_GOSSIP_STORE_PRIVATE_UPDATE = 4102, + WIRE_GOSSIP_STORE_DELETE_CHAN = 4103, +}; + +const char *gossip_store_wire_name(int e); + +/** + * Determine whether a given message type is defined as a message. + * + * Returns true if the message type is part of the message definitions we have + * generated parsers for, false if it is a custom message that cannot be + * handled internally. + */ +bool gossip_store_wire_is_defined(u16 type); + + +/* WIRE: GOSSIP_STORE_CHANNEL_AMOUNT */ +/* This always follows the channel_announce. */ +u8 *towire_gossip_store_channel_amount(const tal_t *ctx, struct amount_sat satoshis); +bool fromwire_gossip_store_channel_amount(const void *p, struct amount_sat *satoshis); + +/* WIRE: GOSSIP_STORE_PRIVATE_UPDATE */ +u8 *towire_gossip_store_private_update(const tal_t *ctx, const u8 *update); +bool fromwire_gossip_store_private_update(const tal_t *ctx, const void *p, u8 **update); + +/* WIRE: GOSSIP_STORE_DELETE_CHAN */ +u8 *towire_gossip_store_delete_chan(const tal_t *ctx, const struct short_channel_id *scid); +bool fromwire_gossip_store_delete_chan(const void *p, struct short_channel_id *scid); + + +#endif /* LIGHTNING_GOSSIPD_GOSSIP_STORE_WIREGEN_H */ + +// SHA256STAMP:exp-0-184dda49fa00adc7b82ffc843580a139d17d915c890228fc1a2a8a4383e016ae diff --git a/gossipd/gossipd_peerd_wiregen.c b/gossipd/gossipd_peerd_wiregen.c new file mode 100644 index 000000000..998dbe71c --- /dev/null +++ b/gossipd/gossipd_peerd_wiregen.c @@ -0,0 +1,230 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Original template can be found at tools/gen/impl_template */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef SUPERVERBOSE +#define SUPERVERBOSE(...) +#endif + +/* These must be distinct from WIRE_CHANNEL_ANNOUNCEMENT etc. gossip msgs! */ + +const char *gossipd_peerd_wire_name(int e) +{ + static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; + + switch ((enum gossipd_peerd_wire)e) { + case WIRE_GOSSIPD_GET_UPDATE: return "WIRE_GOSSIPD_GET_UPDATE"; + case WIRE_GOSSIPD_GET_UPDATE_REPLY: return "WIRE_GOSSIPD_GET_UPDATE_REPLY"; + case WIRE_GOSSIPD_LOCAL_ADD_CHANNEL: return "WIRE_GOSSIPD_LOCAL_ADD_CHANNEL"; + case WIRE_GOSSIPD_LOCAL_CHANNEL_UPDATE: return "WIRE_GOSSIPD_LOCAL_CHANNEL_UPDATE"; + case WIRE_GOSSIPD_NEW_STORE_FD: return "WIRE_GOSSIPD_NEW_STORE_FD"; + case WIRE_GOSSIPD_LOCAL_CHANNEL_ANNOUNCEMENT: return "WIRE_GOSSIPD_LOCAL_CHANNEL_ANNOUNCEMENT"; + } + + snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); + return invalidbuf; +} + +bool gossipd_peerd_wire_is_defined(u16 type) +{ + switch ((enum gossipd_peerd_wire)type) { + case WIRE_GOSSIPD_GET_UPDATE:; + case WIRE_GOSSIPD_GET_UPDATE_REPLY:; + case WIRE_GOSSIPD_LOCAL_ADD_CHANNEL:; + case WIRE_GOSSIPD_LOCAL_CHANNEL_UPDATE:; + case WIRE_GOSSIPD_NEW_STORE_FD:; + case WIRE_GOSSIPD_LOCAL_CHANNEL_ANNOUNCEMENT:; + return true; + } + return false; +} + + + + + +/* WIRE: GOSSIPD_GET_UPDATE */ +/* Channel daemon can ask for updates for a specific channel */ +/* errors. */ +u8 *towire_gossipd_get_update(const tal_t *ctx, const struct short_channel_id *short_channel_id) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GET_UPDATE); + towire_short_channel_id(&p, short_channel_id); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_get_update(const void *p, struct short_channel_id *short_channel_id) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GET_UPDATE) + return false; + fromwire_short_channel_id(&cursor, &plen, short_channel_id); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_GET_UPDATE_REPLY */ +/* If channel isn't known */ +u8 *towire_gossipd_get_update_reply(const tal_t *ctx, const u8 *update) +{ + u16 len = tal_count(update); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GET_UPDATE_REPLY); + towire_u16(&p, len); + towire_u8_array(&p, update, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_get_update_reply(const tal_t *ctx, const void *p, u8 **update) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GET_UPDATE_REPLY) + return false; + len = fromwire_u16(&cursor, &plen); + // 2nd case update + *update = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *update, len); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_LOCAL_ADD_CHANNEL */ +/* Both sides have seen the funding tx being locked */ +/* yet reached the announcement depth. So we add the channel locally so */ +/* we (and peer) can update it already. */ +u8 *towire_gossipd_local_add_channel(const tal_t *ctx, const struct short_channel_id *short_channel_id, const struct node_id *remote_node_id, struct amount_sat satoshis, const u8 *features) +{ + u16 flen = tal_count(features); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_LOCAL_ADD_CHANNEL); + towire_short_channel_id(&p, short_channel_id); + towire_node_id(&p, remote_node_id); + towire_amount_sat(&p, satoshis); + towire_u16(&p, flen); + towire_u8_array(&p, features, flen); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_local_add_channel(const tal_t *ctx, const void *p, struct short_channel_id *short_channel_id, struct node_id *remote_node_id, struct amount_sat *satoshis, u8 **features) +{ + u16 flen; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_LOCAL_ADD_CHANNEL) + return false; + fromwire_short_channel_id(&cursor, &plen, short_channel_id); + fromwire_node_id(&cursor, &plen, remote_node_id); + *satoshis = fromwire_amount_sat(&cursor, &plen); + flen = fromwire_u16(&cursor, &plen); + // 2nd case features + *features = flen ? tal_arr(ctx, u8, flen) : NULL; + fromwire_u8_array(&cursor, &plen, *features, flen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_LOCAL_CHANNEL_UPDATE */ +/* Send this channel_update. */ +u8 *towire_gossipd_local_channel_update(const tal_t *ctx, const struct short_channel_id *short_channel_id, bool disable, u16 cltv_expiry_delta, struct amount_msat htlc_minimum_msat, u32 fee_base_msat, u32 fee_proportional_millionths, struct amount_msat htlc_maximum_msat) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_LOCAL_CHANNEL_UPDATE); + towire_short_channel_id(&p, short_channel_id); + towire_bool(&p, disable); + towire_u16(&p, cltv_expiry_delta); + towire_amount_msat(&p, htlc_minimum_msat); + towire_u32(&p, fee_base_msat); + towire_u32(&p, fee_proportional_millionths); + towire_amount_msat(&p, htlc_maximum_msat); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_local_channel_update(const void *p, struct short_channel_id *short_channel_id, bool *disable, u16 *cltv_expiry_delta, struct amount_msat *htlc_minimum_msat, u32 *fee_base_msat, u32 *fee_proportional_millionths, struct amount_msat *htlc_maximum_msat) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_LOCAL_CHANNEL_UPDATE) + return false; + fromwire_short_channel_id(&cursor, &plen, short_channel_id); + *disable = fromwire_bool(&cursor, &plen); + *cltv_expiry_delta = fromwire_u16(&cursor, &plen); + *htlc_minimum_msat = fromwire_amount_msat(&cursor, &plen); + *fee_base_msat = fromwire_u32(&cursor, &plen); + *fee_proportional_millionths = fromwire_u32(&cursor, &plen); + *htlc_maximum_msat = fromwire_amount_msat(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_NEW_STORE_FD */ +/* Update your gossip_store fd: + gossip_store_fd */ +u8 *towire_gossipd_new_store_fd(const tal_t *ctx, u64 offset_shorter) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_NEW_STORE_FD); + /* How much shorter the new store is */ + towire_u64(&p, offset_shorter); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_new_store_fd(const void *p, u64 *offset_shorter) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_NEW_STORE_FD) + return false; + /* How much shorter the new store is */ + *offset_shorter = fromwire_u64(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_LOCAL_CHANNEL_ANNOUNCEMENT */ +/* Send this channel_announcement */ +u8 *towire_gossipd_local_channel_announcement(const tal_t *ctx, const u8 *cannount) +{ + u16 len = tal_count(cannount); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_LOCAL_CHANNEL_ANNOUNCEMENT); + towire_u16(&p, len); + towire_u8_array(&p, cannount, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_local_channel_announcement(const tal_t *ctx, const void *p, u8 **cannount) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_LOCAL_CHANNEL_ANNOUNCEMENT) + return false; + len = fromwire_u16(&cursor, &plen); + // 2nd case cannount + *cannount = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *cannount, len); + return cursor != NULL; +} + +// SHA256STAMP:exp-0-c3a2252dbb4648cc0fb0766797d4e69fd7afd59565f133bb6c24df54b5c42ad6 diff --git a/gossipd/gossipd_peerd_wiregen.h b/gossipd/gossipd_peerd_wiregen.h new file mode 100644 index 000000000..4a8d594b6 --- /dev/null +++ b/gossipd/gossipd_peerd_wiregen.h @@ -0,0 +1,80 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the _csv file it was generated from. */ +/* Original template can be found at tools/gen/header_template */ + +#ifndef LIGHTNING_GOSSIPD_GOSSIPD_PEERD_WIREGEN_H +#define LIGHTNING_GOSSIPD_GOSSIPD_PEERD_WIREGEN_H +#include +#include +#include +#include +#include +#include + +enum gossipd_peerd_wire { + /* Channel daemon can ask for updates for a specific channel */ + /* errors. */ + WIRE_GOSSIPD_GET_UPDATE = 3501, + /* If channel isn't known */ + WIRE_GOSSIPD_GET_UPDATE_REPLY = 3601, + /* Both sides have seen the funding tx being locked */ + /* yet reached the announcement depth. So we add the channel locally so */ + /* we (and peer) can update it already. */ + WIRE_GOSSIPD_LOCAL_ADD_CHANNEL = 3503, + /* Send this channel_update. */ + WIRE_GOSSIPD_LOCAL_CHANNEL_UPDATE = 3504, + /* Update your gossip_store fd: + gossip_store_fd */ + WIRE_GOSSIPD_NEW_STORE_FD = 3505, + /* Send this channel_announcement */ + WIRE_GOSSIPD_LOCAL_CHANNEL_ANNOUNCEMENT = 3506, +}; + +const char *gossipd_peerd_wire_name(int e); + +/** + * Determine whether a given message type is defined as a message. + * + * Returns true if the message type is part of the message definitions we have + * generated parsers for, false if it is a custom message that cannot be + * handled internally. + */ +bool gossipd_peerd_wire_is_defined(u16 type); + + +/* WIRE: GOSSIPD_GET_UPDATE */ +/* Channel daemon can ask for updates for a specific channel */ +/* errors. */ +u8 *towire_gossipd_get_update(const tal_t *ctx, const struct short_channel_id *short_channel_id); +bool fromwire_gossipd_get_update(const void *p, struct short_channel_id *short_channel_id); + +/* WIRE: GOSSIPD_GET_UPDATE_REPLY */ +/* If channel isn't known */ +u8 *towire_gossipd_get_update_reply(const tal_t *ctx, const u8 *update); +bool fromwire_gossipd_get_update_reply(const tal_t *ctx, const void *p, u8 **update); + +/* WIRE: GOSSIPD_LOCAL_ADD_CHANNEL */ +/* Both sides have seen the funding tx being locked */ +/* yet reached the announcement depth. So we add the channel locally so */ +/* we (and peer) can update it already. */ +u8 *towire_gossipd_local_add_channel(const tal_t *ctx, const struct short_channel_id *short_channel_id, const struct node_id *remote_node_id, struct amount_sat satoshis, const u8 *features); +bool fromwire_gossipd_local_add_channel(const tal_t *ctx, const void *p, struct short_channel_id *short_channel_id, struct node_id *remote_node_id, struct amount_sat *satoshis, u8 **features); + +/* WIRE: GOSSIPD_LOCAL_CHANNEL_UPDATE */ +/* Send this channel_update. */ +u8 *towire_gossipd_local_channel_update(const tal_t *ctx, const struct short_channel_id *short_channel_id, bool disable, u16 cltv_expiry_delta, struct amount_msat htlc_minimum_msat, u32 fee_base_msat, u32 fee_proportional_millionths, struct amount_msat htlc_maximum_msat); +bool fromwire_gossipd_local_channel_update(const void *p, struct short_channel_id *short_channel_id, bool *disable, u16 *cltv_expiry_delta, struct amount_msat *htlc_minimum_msat, u32 *fee_base_msat, u32 *fee_proportional_millionths, struct amount_msat *htlc_maximum_msat); + +/* WIRE: GOSSIPD_NEW_STORE_FD */ +/* Update your gossip_store fd: + gossip_store_fd */ +u8 *towire_gossipd_new_store_fd(const tal_t *ctx, u64 offset_shorter); +bool fromwire_gossipd_new_store_fd(const void *p, u64 *offset_shorter); + +/* WIRE: GOSSIPD_LOCAL_CHANNEL_ANNOUNCEMENT */ +/* Send this channel_announcement */ +u8 *towire_gossipd_local_channel_announcement(const tal_t *ctx, const u8 *cannount); +bool fromwire_gossipd_local_channel_announcement(const tal_t *ctx, const void *p, u8 **cannount); + + +#endif /* LIGHTNING_GOSSIPD_GOSSIPD_PEERD_WIREGEN_H */ + +// SHA256STAMP:exp-0-c3a2252dbb4648cc0fb0766797d4e69fd7afd59565f133bb6c24df54b5c42ad6 diff --git a/gossipd/gossipd_wiregen.c b/gossipd/gossipd_wiregen.c new file mode 100644 index 000000000..635db108c --- /dev/null +++ b/gossipd/gossipd_wiregen.c @@ -0,0 +1,861 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Original template can be found at tools/gen/impl_template */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef SUPERVERBOSE +#define SUPERVERBOSE(...) +#endif + + +const char *gossipd_wire_name(int e) +{ + static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; + + switch ((enum gossipd_wire)e) { + case WIRE_GOSSIPD_INIT: return "WIRE_GOSSIPD_INIT"; + case WIRE_GOSSIPD_DEV_SET_TIME: return "WIRE_GOSSIPD_DEV_SET_TIME"; + case WIRE_GOSSIPD_GETNODES_REQUEST: return "WIRE_GOSSIPD_GETNODES_REQUEST"; + case WIRE_GOSSIPD_GETNODES_REPLY: return "WIRE_GOSSIPD_GETNODES_REPLY"; + case WIRE_GOSSIPD_GETROUTE_REQUEST: return "WIRE_GOSSIPD_GETROUTE_REQUEST"; + case WIRE_GOSSIPD_GETROUTE_REPLY: return "WIRE_GOSSIPD_GETROUTE_REPLY"; + case WIRE_GOSSIPD_GETCHANNELS_REQUEST: return "WIRE_GOSSIPD_GETCHANNELS_REQUEST"; + case WIRE_GOSSIPD_GETCHANNELS_REPLY: return "WIRE_GOSSIPD_GETCHANNELS_REPLY"; + case WIRE_GOSSIPD_PING: return "WIRE_GOSSIPD_PING"; + case WIRE_GOSSIPD_PING_REPLY: return "WIRE_GOSSIPD_PING_REPLY"; + case WIRE_GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE: return "WIRE_GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE"; + case WIRE_GOSSIPD_GET_STRIPPED_CUPDATE: return "WIRE_GOSSIPD_GET_STRIPPED_CUPDATE"; + case WIRE_GOSSIPD_GET_STRIPPED_CUPDATE_REPLY: return "WIRE_GOSSIPD_GET_STRIPPED_CUPDATE_REPLY"; + case WIRE_GOSSIPD_LOCAL_CHANNEL_CLOSE: return "WIRE_GOSSIPD_LOCAL_CHANNEL_CLOSE"; + case WIRE_GOSSIPD_GET_TXOUT: return "WIRE_GOSSIPD_GET_TXOUT"; + case WIRE_GOSSIPD_GET_TXOUT_REPLY: return "WIRE_GOSSIPD_GET_TXOUT_REPLY"; + case WIRE_GOSSIPD_PAYMENT_FAILURE: return "WIRE_GOSSIPD_PAYMENT_FAILURE"; + case WIRE_GOSSIPD_OUTPOINT_SPENT: return "WIRE_GOSSIPD_OUTPOINT_SPENT"; + case WIRE_GOSSIPD_DEV_SUPPRESS: return "WIRE_GOSSIPD_DEV_SUPPRESS"; + case WIRE_GOSSIPD_DEV_MEMLEAK: return "WIRE_GOSSIPD_DEV_MEMLEAK"; + case WIRE_GOSSIPD_DEV_MEMLEAK_REPLY: return "WIRE_GOSSIPD_DEV_MEMLEAK_REPLY"; + case WIRE_GOSSIPD_DEV_COMPACT_STORE: return "WIRE_GOSSIPD_DEV_COMPACT_STORE"; + case WIRE_GOSSIPD_DEV_COMPACT_STORE_REPLY: return "WIRE_GOSSIPD_DEV_COMPACT_STORE_REPLY"; + case WIRE_GOSSIPD_GET_INCOMING_CHANNELS: return "WIRE_GOSSIPD_GET_INCOMING_CHANNELS"; + case WIRE_GOSSIPD_GET_INCOMING_CHANNELS_REPLY: return "WIRE_GOSSIPD_GET_INCOMING_CHANNELS_REPLY"; + case WIRE_GOSSIPD_NEW_BLOCKHEIGHT: return "WIRE_GOSSIPD_NEW_BLOCKHEIGHT"; + } + + snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); + return invalidbuf; +} + +bool gossipd_wire_is_defined(u16 type) +{ + switch ((enum gossipd_wire)type) { + case WIRE_GOSSIPD_INIT:; + case WIRE_GOSSIPD_DEV_SET_TIME:; + case WIRE_GOSSIPD_GETNODES_REQUEST:; + case WIRE_GOSSIPD_GETNODES_REPLY:; + case WIRE_GOSSIPD_GETROUTE_REQUEST:; + case WIRE_GOSSIPD_GETROUTE_REPLY:; + case WIRE_GOSSIPD_GETCHANNELS_REQUEST:; + case WIRE_GOSSIPD_GETCHANNELS_REPLY:; + case WIRE_GOSSIPD_PING:; + case WIRE_GOSSIPD_PING_REPLY:; + case WIRE_GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE:; + case WIRE_GOSSIPD_GET_STRIPPED_CUPDATE:; + case WIRE_GOSSIPD_GET_STRIPPED_CUPDATE_REPLY:; + case WIRE_GOSSIPD_LOCAL_CHANNEL_CLOSE:; + case WIRE_GOSSIPD_GET_TXOUT:; + case WIRE_GOSSIPD_GET_TXOUT_REPLY:; + case WIRE_GOSSIPD_PAYMENT_FAILURE:; + case WIRE_GOSSIPD_OUTPOINT_SPENT:; + case WIRE_GOSSIPD_DEV_SUPPRESS:; + case WIRE_GOSSIPD_DEV_MEMLEAK:; + case WIRE_GOSSIPD_DEV_MEMLEAK_REPLY:; + case WIRE_GOSSIPD_DEV_COMPACT_STORE:; + case WIRE_GOSSIPD_DEV_COMPACT_STORE_REPLY:; + case WIRE_GOSSIPD_GET_INCOMING_CHANNELS:; + case WIRE_GOSSIPD_GET_INCOMING_CHANNELS_REPLY:; + case WIRE_GOSSIPD_NEW_BLOCKHEIGHT:; + return true; + } + return false; +} + + + + + +/* WIRE: GOSSIPD_INIT */ +/* Initialize the gossip daemon. */ +u8 *towire_gossipd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct node_id *id, const u8 rgb[3], const u8 alias[32], const struct wireaddr *announcable, u32 *dev_gossip_time, bool dev_fast_gossip, bool dev_fast_gossip_prune) +{ + u16 num_announcable = tal_count(announcable); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_INIT); + towire_chainparams(&p, chainparams); + towire_feature_set(&p, our_features); + towire_node_id(&p, id); + towire_u8_array(&p, rgb, 3); + towire_u8_array(&p, alias, 32); + towire_u16(&p, num_announcable); + for (size_t i = 0; i < num_announcable; i++) + towire_wireaddr(&p, announcable + i); + if (!dev_gossip_time) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_u32(&p, *dev_gossip_time); + } + towire_bool(&p, dev_fast_gossip); + towire_bool(&p, dev_fast_gossip_prune); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct node_id *id, u8 rgb[3], u8 alias[32], struct wireaddr **announcable, u32 **dev_gossip_time, bool *dev_fast_gossip, bool *dev_fast_gossip_prune) +{ + u16 num_announcable; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_INIT) + return false; + fromwire_chainparams(&cursor, &plen, chainparams); + *our_features = fromwire_feature_set(ctx, &cursor, &plen); + fromwire_node_id(&cursor, &plen, id); + fromwire_u8_array(&cursor, &plen, rgb, 3); + fromwire_u8_array(&cursor, &plen, alias, 32); + num_announcable = fromwire_u16(&cursor, &plen); + // 2nd case announcable + *announcable = num_announcable ? tal_arr(ctx, struct wireaddr, num_announcable) : NULL; + for (size_t i = 0; i < num_announcable; i++) + fromwire_wireaddr(&cursor, &plen, *announcable + i); + if (!fromwire_bool(&cursor, &plen)) + *dev_gossip_time = NULL; + else { + *dev_gossip_time = tal(ctx, u32); + **dev_gossip_time = fromwire_u32(&cursor, &plen); + } + *dev_fast_gossip = fromwire_bool(&cursor, &plen); + *dev_fast_gossip_prune = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_DEV_SET_TIME */ +/* In developer mode */ +u8 *towire_gossipd_dev_set_time(const tal_t *ctx, u32 dev_gossip_time) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_DEV_SET_TIME); + towire_u32(&p, dev_gossip_time); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_dev_set_time(const void *p, u32 *dev_gossip_time) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_DEV_SET_TIME) + return false; + *dev_gossip_time = fromwire_u32(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_GETNODES_REQUEST */ +/* Pass JSON-RPC getnodes call through */ +u8 *towire_gossipd_getnodes_request(const tal_t *ctx, const struct node_id *id) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GETNODES_REQUEST); + if (!id) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_node_id(&p, id); + } + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_getnodes_request(const tal_t *ctx, const void *p, struct node_id **id) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GETNODES_REQUEST) + return false; + if (!fromwire_bool(&cursor, &plen)) + *id = NULL; + else { + *id = tal(ctx, struct node_id); + fromwire_node_id(&cursor, &plen, *id); + } + return cursor != NULL; +} + +/* WIRE: GOSSIPD_GETNODES_REPLY */ +u8 *towire_gossipd_getnodes_reply(const tal_t *ctx, const struct gossip_getnodes_entry **nodes) +{ + u32 num_nodes = tal_count(nodes); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GETNODES_REPLY); + towire_u32(&p, num_nodes); + for (size_t i = 0; i < num_nodes; i++) + towire_gossip_getnodes_entry(&p, nodes[i]); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_getnodes_reply(const tal_t *ctx, const void *p, struct gossip_getnodes_entry ***nodes) +{ + u32 num_nodes; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GETNODES_REPLY) + return false; + num_nodes = fromwire_u32(&cursor, &plen); + // 2nd case nodes + *nodes = num_nodes ? tal_arr(ctx, struct gossip_getnodes_entry *, num_nodes) : NULL; + for (size_t i = 0; i < num_nodes; i++) + (*nodes)[i] = fromwire_gossip_getnodes_entry(*nodes, &cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_GETROUTE_REQUEST */ +/* Pass JSON-RPC getroute call through */ +u8 *towire_gossipd_getroute_request(const tal_t *ctx, const struct node_id *source, const struct node_id *destination, struct amount_msat msatoshi, u64 riskfactor_millionths, u32 final_cltv, u64 fuzz_millionths, const struct exclude_entry **excluded, u32 max_hops) +{ + u16 num_excluded = tal_count(excluded); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GETROUTE_REQUEST); + /* Source defaults to "us" */ + if (!source) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_node_id(&p, source); + } + towire_node_id(&p, destination); + towire_amount_msat(&p, msatoshi); + towire_u64(&p, riskfactor_millionths); + towire_u32(&p, final_cltv); + towire_u64(&p, fuzz_millionths); + towire_u16(&p, num_excluded); + for (size_t i = 0; i < num_excluded; i++) + towire_exclude_entry(&p, excluded[i]); + towire_u32(&p, max_hops); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_getroute_request(const tal_t *ctx, const void *p, struct node_id **source, struct node_id *destination, struct amount_msat *msatoshi, u64 *riskfactor_millionths, u32 *final_cltv, u64 *fuzz_millionths, struct exclude_entry ***excluded, u32 *max_hops) +{ + u16 num_excluded; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GETROUTE_REQUEST) + return false; + /* Source defaults to "us" */ + if (!fromwire_bool(&cursor, &plen)) + *source = NULL; + else { + *source = tal(ctx, struct node_id); + fromwire_node_id(&cursor, &plen, *source); + } + fromwire_node_id(&cursor, &plen, destination); + *msatoshi = fromwire_amount_msat(&cursor, &plen); + *riskfactor_millionths = fromwire_u64(&cursor, &plen); + *final_cltv = fromwire_u32(&cursor, &plen); + *fuzz_millionths = fromwire_u64(&cursor, &plen); + num_excluded = fromwire_u16(&cursor, &plen); + // 2nd case excluded + *excluded = num_excluded ? tal_arr(ctx, struct exclude_entry *, num_excluded) : NULL; + for (size_t i = 0; i < num_excluded; i++) + (*excluded)[i] = fromwire_exclude_entry(*excluded, &cursor, &plen); + *max_hops = fromwire_u32(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_GETROUTE_REPLY */ +u8 *towire_gossipd_getroute_reply(const tal_t *ctx, const struct route_hop **hops) +{ + u16 num_hops = tal_count(hops); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GETROUTE_REPLY); + towire_u16(&p, num_hops); + for (size_t i = 0; i < num_hops; i++) + towire_route_hop(&p, hops[i]); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_getroute_reply(const tal_t *ctx, const void *p, struct route_hop ***hops) +{ + u16 num_hops; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GETROUTE_REPLY) + return false; + num_hops = fromwire_u16(&cursor, &plen); + // 2nd case hops + *hops = num_hops ? tal_arr(ctx, struct route_hop *, num_hops) : NULL; + for (size_t i = 0; i < num_hops; i++) + (*hops)[i] = fromwire_route_hop(*hops, &cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_GETCHANNELS_REQUEST */ +u8 *towire_gossipd_getchannels_request(const tal_t *ctx, const struct short_channel_id *short_channel_id, const struct node_id *source, const struct short_channel_id *prev) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GETCHANNELS_REQUEST); + if (!short_channel_id) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_short_channel_id(&p, short_channel_id); + } + if (!source) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_node_id(&p, source); + } + if (!prev) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_short_channel_id(&p, prev); + } + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_getchannels_request(const tal_t *ctx, const void *p, struct short_channel_id **short_channel_id, struct node_id **source, struct short_channel_id **prev) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GETCHANNELS_REQUEST) + return false; + if (!fromwire_bool(&cursor, &plen)) + *short_channel_id = NULL; + else { + *short_channel_id = tal(ctx, struct short_channel_id); + fromwire_short_channel_id(&cursor, &plen, *short_channel_id); + } + if (!fromwire_bool(&cursor, &plen)) + *source = NULL; + else { + *source = tal(ctx, struct node_id); + fromwire_node_id(&cursor, &plen, *source); + } + if (!fromwire_bool(&cursor, &plen)) + *prev = NULL; + else { + *prev = tal(ctx, struct short_channel_id); + fromwire_short_channel_id(&cursor, &plen, *prev); + } + return cursor != NULL; +} + +/* WIRE: GOSSIPD_GETCHANNELS_REPLY */ +u8 *towire_gossipd_getchannels_reply(const tal_t *ctx, bool complete, const struct gossip_getchannels_entry **nodes) +{ + u32 num_channels = tal_count(nodes); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GETCHANNELS_REPLY); + towire_bool(&p, complete); + towire_u32(&p, num_channels); + for (size_t i = 0; i < num_channels; i++) + towire_gossip_getchannels_entry(&p, nodes[i]); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_getchannels_reply(const tal_t *ctx, const void *p, bool *complete, struct gossip_getchannels_entry ***nodes) +{ + u32 num_channels; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GETCHANNELS_REPLY) + return false; + *complete = fromwire_bool(&cursor, &plen); + num_channels = fromwire_u32(&cursor, &plen); + // 2nd case nodes + *nodes = num_channels ? tal_arr(ctx, struct gossip_getchannels_entry *, num_channels) : NULL; + for (size_t i = 0; i < num_channels; i++) + (*nodes)[i] = fromwire_gossip_getchannels_entry(*nodes, &cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_PING */ +/* Ping/pong test. Waits for a reply if it expects one. */ +u8 *towire_gossipd_ping(const tal_t *ctx, const struct node_id *id, u16 num_pong_bytes, u16 len) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_PING); + towire_node_id(&p, id); + towire_u16(&p, num_pong_bytes); + towire_u16(&p, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_ping(const void *p, struct node_id *id, u16 *num_pong_bytes, u16 *len) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_PING) + return false; + fromwire_node_id(&cursor, &plen, id); + *num_pong_bytes = fromwire_u16(&cursor, &plen); + *len = fromwire_u16(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_PING_REPLY */ +u8 *towire_gossipd_ping_reply(const tal_t *ctx, const struct node_id *id, bool sent, u16 totlen) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_PING_REPLY); + towire_node_id(&p, id); + /* False if id in gossip_ping was unknown. */ + towire_bool(&p, sent); + /* 0 == no pong expected */ + towire_u16(&p, totlen); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_ping_reply(const void *p, struct node_id *id, bool *sent, u16 *totlen) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_PING_REPLY) + return false; + fromwire_node_id(&cursor, &plen, id); + /* False if id in gossip_ping was unknown. */ + *sent = fromwire_bool(&cursor, &plen); + /* 0 == no pong expected */ + *totlen = fromwire_u16(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE */ +/* Set artificial maximum reply_channel_range size. Master->gossipd */ +u8 *towire_gossipd_dev_set_max_scids_encode_size(const tal_t *ctx, u32 max) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE); + towire_u32(&p, max); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_dev_set_max_scids_encode_size(const void *p, u32 *max) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE) + return false; + *max = fromwire_u32(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_GET_STRIPPED_CUPDATE */ +/* Given a short_channel_id */ +u8 *towire_gossipd_get_stripped_cupdate(const tal_t *ctx, const struct short_channel_id *channel_id) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GET_STRIPPED_CUPDATE); + towire_short_channel_id(&p, channel_id); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_get_stripped_cupdate(const void *p, struct short_channel_id *channel_id) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GET_STRIPPED_CUPDATE) + return false; + fromwire_short_channel_id(&cursor, &plen, channel_id); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_GET_STRIPPED_CUPDATE_REPLY */ +u8 *towire_gossipd_get_stripped_cupdate_reply(const tal_t *ctx, const u8 *stripped_update) +{ + u16 stripped_update_len = tal_count(stripped_update); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GET_STRIPPED_CUPDATE_REPLY); + towire_u16(&p, stripped_update_len); + towire_u8_array(&p, stripped_update, stripped_update_len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_get_stripped_cupdate_reply(const tal_t *ctx, const void *p, u8 **stripped_update) +{ + u16 stripped_update_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GET_STRIPPED_CUPDATE_REPLY) + return false; + stripped_update_len = fromwire_u16(&cursor, &plen); + // 2nd case stripped_update + *stripped_update = stripped_update_len ? tal_arr(ctx, u8, stripped_update_len) : NULL; + fromwire_u8_array(&cursor, &plen, *stripped_update, stripped_update_len); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_LOCAL_CHANNEL_CLOSE */ +/* gossipd->master: we're closing this channel. */ +u8 *towire_gossipd_local_channel_close(const tal_t *ctx, const struct short_channel_id *short_channel_id) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_LOCAL_CHANNEL_CLOSE); + towire_short_channel_id(&p, short_channel_id); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_local_channel_close(const void *p, struct short_channel_id *short_channel_id) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_LOCAL_CHANNEL_CLOSE) + return false; + fromwire_short_channel_id(&cursor, &plen, short_channel_id); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_GET_TXOUT */ +/* Gossipd->master get this tx output please. */ +u8 *towire_gossipd_get_txout(const tal_t *ctx, const struct short_channel_id *short_channel_id) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GET_TXOUT); + towire_short_channel_id(&p, short_channel_id); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_get_txout(const void *p, struct short_channel_id *short_channel_id) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GET_TXOUT) + return false; + fromwire_short_channel_id(&cursor, &plen, short_channel_id); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_GET_TXOUT_REPLY */ +/* master->gossipd here is the output */ +u8 *towire_gossipd_get_txout_reply(const tal_t *ctx, const struct short_channel_id *short_channel_id, struct amount_sat satoshis, const u8 *outscript) +{ + u16 len = tal_count(outscript); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GET_TXOUT_REPLY); + towire_short_channel_id(&p, short_channel_id); + towire_amount_sat(&p, satoshis); + towire_u16(&p, len); + towire_u8_array(&p, outscript, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_get_txout_reply(const tal_t *ctx, const void *p, struct short_channel_id *short_channel_id, struct amount_sat *satoshis, u8 **outscript) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GET_TXOUT_REPLY) + return false; + fromwire_short_channel_id(&cursor, &plen, short_channel_id); + *satoshis = fromwire_amount_sat(&cursor, &plen); + len = fromwire_u16(&cursor, &plen); + // 2nd case outscript + *outscript = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *outscript, len); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_PAYMENT_FAILURE */ +/* master->gossipd an htlc failed with this onion error. */ +u8 *towire_gossipd_payment_failure(const tal_t *ctx, const u8 *error) +{ + u16 len = tal_count(error); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_PAYMENT_FAILURE); + towire_u16(&p, len); + towire_u8_array(&p, error, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_payment_failure(const tal_t *ctx, const void *p, u8 **error) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_PAYMENT_FAILURE) + return false; + len = fromwire_u16(&cursor, &plen); + // 2nd case error + *error = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *error, len); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_OUTPOINT_SPENT */ +/* master -> gossipd: a potential funding outpoint was spent */ +u8 *towire_gossipd_outpoint_spent(const tal_t *ctx, const struct short_channel_id *short_channel_id) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_OUTPOINT_SPENT); + towire_short_channel_id(&p, short_channel_id); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_outpoint_spent(const void *p, struct short_channel_id *short_channel_id) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_OUTPOINT_SPENT) + return false; + fromwire_short_channel_id(&cursor, &plen, short_channel_id); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_DEV_SUPPRESS */ +/* master -> gossipd: stop gossip timers. */ +u8 *towire_gossipd_dev_suppress(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_DEV_SUPPRESS); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_dev_suppress(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_DEV_SUPPRESS) + return false; + return cursor != NULL; +} + +/* WIRE: GOSSIPD_DEV_MEMLEAK */ +/* master -> gossipd: do you have a memleak? */ +u8 *towire_gossipd_dev_memleak(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_DEV_MEMLEAK); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_dev_memleak(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_DEV_MEMLEAK) + return false; + return cursor != NULL; +} + +/* WIRE: GOSSIPD_DEV_MEMLEAK_REPLY */ +u8 *towire_gossipd_dev_memleak_reply(const tal_t *ctx, bool leak) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_DEV_MEMLEAK_REPLY); + towire_bool(&p, leak); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_dev_memleak_reply(const void *p, bool *leak) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_DEV_MEMLEAK_REPLY) + return false; + *leak = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_DEV_COMPACT_STORE */ +/* master -> gossipd: please rewrite the gossip_store */ +u8 *towire_gossipd_dev_compact_store(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_DEV_COMPACT_STORE); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_dev_compact_store(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_DEV_COMPACT_STORE) + return false; + return cursor != NULL; +} + +/* WIRE: GOSSIPD_DEV_COMPACT_STORE_REPLY */ +/* gossipd -> master: ok */ +u8 *towire_gossipd_dev_compact_store_reply(const tal_t *ctx, bool success) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_DEV_COMPACT_STORE_REPLY); + towire_bool(&p, success); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_dev_compact_store_reply(const void *p, bool *success) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_DEV_COMPACT_STORE_REPLY) + return false; + *success = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_GET_INCOMING_CHANNELS */ +/* master -> gossipd: get route_info for our incoming channels */ +u8 *towire_gossipd_get_incoming_channels(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GET_INCOMING_CHANNELS); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_get_incoming_channels(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GET_INCOMING_CHANNELS) + return false; + return cursor != NULL; +} + +/* WIRE: GOSSIPD_GET_INCOMING_CHANNELS_REPLY */ +/* gossipd -> master: here they are. */ +u8 *towire_gossipd_get_incoming_channels_reply(const tal_t *ctx, const struct route_info *public_route_info, const bool *public_deadends, const struct route_info *private_route_info, const bool *private_deadends) +{ + u16 num_public = tal_count(public_deadends); + u16 num_private = tal_count(private_deadends); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GET_INCOMING_CHANNELS_REPLY); + towire_u16(&p, num_public); + for (size_t i = 0; i < num_public; i++) + towire_route_info(&p, public_route_info + i); + for (size_t i = 0; i < num_public; i++) + towire_bool(&p, public_deadends[i]); + towire_u16(&p, num_private); + for (size_t i = 0; i < num_private; i++) + towire_route_info(&p, private_route_info + i); + for (size_t i = 0; i < num_private; i++) + towire_bool(&p, private_deadends[i]); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_get_incoming_channels_reply(const tal_t *ctx, const void *p, struct route_info **public_route_info, bool **public_deadends, struct route_info **private_route_info, bool **private_deadends) +{ + u16 num_public; + u16 num_private; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GET_INCOMING_CHANNELS_REPLY) + return false; + num_public = fromwire_u16(&cursor, &plen); + // 2nd case public_route_info + *public_route_info = num_public ? tal_arr(ctx, struct route_info, num_public) : NULL; + for (size_t i = 0; i < num_public; i++) + fromwire_route_info(&cursor, &plen, *public_route_info + i); + // 2nd case public_deadends + *public_deadends = num_public ? tal_arr(ctx, bool, num_public) : NULL; + for (size_t i = 0; i < num_public; i++) + (*public_deadends)[i] = fromwire_bool(&cursor, &plen); + num_private = fromwire_u16(&cursor, &plen); + // 2nd case private_route_info + *private_route_info = num_private ? tal_arr(ctx, struct route_info, num_private) : NULL; + for (size_t i = 0; i < num_private; i++) + fromwire_route_info(&cursor, &plen, *private_route_info + i); + // 2nd case private_deadends + *private_deadends = num_private ? tal_arr(ctx, bool, num_private) : NULL; + for (size_t i = 0; i < num_private; i++) + (*private_deadends)[i] = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: GOSSIPD_NEW_BLOCKHEIGHT */ +/* master -> gossipd: blockheight increased. */ +u8 *towire_gossipd_new_blockheight(const tal_t *ctx, u32 blockheight) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_NEW_BLOCKHEIGHT); + towire_u32(&p, blockheight); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_new_blockheight(const void *p, u32 *blockheight) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_NEW_BLOCKHEIGHT) + return false; + *blockheight = fromwire_u32(&cursor, &plen); + return cursor != NULL; +} + +// SHA256STAMP:exp-0-6790ea53b0abf99e5595d11fe496d3ac5fe5b159f15205eca4c34a96856626d8 diff --git a/gossipd/gossipd_wiregen.h b/gossipd/gossipd_wiregen.h new file mode 100644 index 000000000..b667f8d81 --- /dev/null +++ b/gossipd/gossipd_wiregen.h @@ -0,0 +1,203 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the _csv file it was generated from. */ +/* Original template can be found at tools/gen/header_template */ + +#ifndef LIGHTNING_GOSSIPD_GOSSIPD_WIREGEN_H +#define LIGHTNING_GOSSIPD_GOSSIPD_WIREGEN_H +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum gossipd_wire { + /* Initialize the gossip daemon. */ + WIRE_GOSSIPD_INIT = 3000, + /* In developer mode */ + WIRE_GOSSIPD_DEV_SET_TIME = 3001, + /* Pass JSON-RPC getnodes call through */ + WIRE_GOSSIPD_GETNODES_REQUEST = 3005, + WIRE_GOSSIPD_GETNODES_REPLY = 3105, + /* Pass JSON-RPC getroute call through */ + WIRE_GOSSIPD_GETROUTE_REQUEST = 3006, + WIRE_GOSSIPD_GETROUTE_REPLY = 3106, + WIRE_GOSSIPD_GETCHANNELS_REQUEST = 3007, + WIRE_GOSSIPD_GETCHANNELS_REPLY = 3107, + /* Ping/pong test. Waits for a reply if it expects one. */ + WIRE_GOSSIPD_PING = 3008, + WIRE_GOSSIPD_PING_REPLY = 3108, + /* Set artificial maximum reply_channel_range size. Master->gossipd */ + WIRE_GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE = 3030, + /* Given a short_channel_id */ + WIRE_GOSSIPD_GET_STRIPPED_CUPDATE = 3010, + WIRE_GOSSIPD_GET_STRIPPED_CUPDATE_REPLY = 3110, + /* gossipd->master: we're closing this channel. */ + WIRE_GOSSIPD_LOCAL_CHANNEL_CLOSE = 3027, + /* Gossipd->master get this tx output please. */ + WIRE_GOSSIPD_GET_TXOUT = 3018, + /* master->gossipd here is the output */ + WIRE_GOSSIPD_GET_TXOUT_REPLY = 3118, + /* master->gossipd an htlc failed with this onion error. */ + WIRE_GOSSIPD_PAYMENT_FAILURE = 3021, + /* master -> gossipd: a potential funding outpoint was spent */ + WIRE_GOSSIPD_OUTPOINT_SPENT = 3024, + /* master -> gossipd: stop gossip timers. */ + WIRE_GOSSIPD_DEV_SUPPRESS = 3032, + /* master -> gossipd: do you have a memleak? */ + WIRE_GOSSIPD_DEV_MEMLEAK = 3033, + WIRE_GOSSIPD_DEV_MEMLEAK_REPLY = 3133, + /* master -> gossipd: please rewrite the gossip_store */ + WIRE_GOSSIPD_DEV_COMPACT_STORE = 3034, + /* gossipd -> master: ok */ + WIRE_GOSSIPD_DEV_COMPACT_STORE_REPLY = 3134, + /* master -> gossipd: get route_info for our incoming channels */ + WIRE_GOSSIPD_GET_INCOMING_CHANNELS = 3025, + /* gossipd -> master: here they are. */ + WIRE_GOSSIPD_GET_INCOMING_CHANNELS_REPLY = 3125, + /* master -> gossipd: blockheight increased. */ + WIRE_GOSSIPD_NEW_BLOCKHEIGHT = 3026, +}; + +const char *gossipd_wire_name(int e); + +/** + * Determine whether a given message type is defined as a message. + * + * Returns true if the message type is part of the message definitions we have + * generated parsers for, false if it is a custom message that cannot be + * handled internally. + */ +bool gossipd_wire_is_defined(u16 type); + + +/* WIRE: GOSSIPD_INIT */ +/* Initialize the gossip daemon. */ +u8 *towire_gossipd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct node_id *id, const u8 rgb[3], const u8 alias[32], const struct wireaddr *announcable, u32 *dev_gossip_time, bool dev_fast_gossip, bool dev_fast_gossip_prune); +bool fromwire_gossipd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct node_id *id, u8 rgb[3], u8 alias[32], struct wireaddr **announcable, u32 **dev_gossip_time, bool *dev_fast_gossip, bool *dev_fast_gossip_prune); + +/* WIRE: GOSSIPD_DEV_SET_TIME */ +/* In developer mode */ +u8 *towire_gossipd_dev_set_time(const tal_t *ctx, u32 dev_gossip_time); +bool fromwire_gossipd_dev_set_time(const void *p, u32 *dev_gossip_time); + +/* WIRE: GOSSIPD_GETNODES_REQUEST */ +/* Pass JSON-RPC getnodes call through */ +u8 *towire_gossipd_getnodes_request(const tal_t *ctx, const struct node_id *id); +bool fromwire_gossipd_getnodes_request(const tal_t *ctx, const void *p, struct node_id **id); + +/* WIRE: GOSSIPD_GETNODES_REPLY */ +u8 *towire_gossipd_getnodes_reply(const tal_t *ctx, const struct gossip_getnodes_entry **nodes); +bool fromwire_gossipd_getnodes_reply(const tal_t *ctx, const void *p, struct gossip_getnodes_entry ***nodes); + +/* WIRE: GOSSIPD_GETROUTE_REQUEST */ +/* Pass JSON-RPC getroute call through */ +u8 *towire_gossipd_getroute_request(const tal_t *ctx, const struct node_id *source, const struct node_id *destination, struct amount_msat msatoshi, u64 riskfactor_millionths, u32 final_cltv, u64 fuzz_millionths, const struct exclude_entry **excluded, u32 max_hops); +bool fromwire_gossipd_getroute_request(const tal_t *ctx, const void *p, struct node_id **source, struct node_id *destination, struct amount_msat *msatoshi, u64 *riskfactor_millionths, u32 *final_cltv, u64 *fuzz_millionths, struct exclude_entry ***excluded, u32 *max_hops); + +/* WIRE: GOSSIPD_GETROUTE_REPLY */ +u8 *towire_gossipd_getroute_reply(const tal_t *ctx, const struct route_hop **hops); +bool fromwire_gossipd_getroute_reply(const tal_t *ctx, const void *p, struct route_hop ***hops); + +/* WIRE: GOSSIPD_GETCHANNELS_REQUEST */ +u8 *towire_gossipd_getchannels_request(const tal_t *ctx, const struct short_channel_id *short_channel_id, const struct node_id *source, const struct short_channel_id *prev); +bool fromwire_gossipd_getchannels_request(const tal_t *ctx, const void *p, struct short_channel_id **short_channel_id, struct node_id **source, struct short_channel_id **prev); + +/* WIRE: GOSSIPD_GETCHANNELS_REPLY */ +u8 *towire_gossipd_getchannels_reply(const tal_t *ctx, bool complete, const struct gossip_getchannels_entry **nodes); +bool fromwire_gossipd_getchannels_reply(const tal_t *ctx, const void *p, bool *complete, struct gossip_getchannels_entry ***nodes); + +/* WIRE: GOSSIPD_PING */ +/* Ping/pong test. Waits for a reply if it expects one. */ +u8 *towire_gossipd_ping(const tal_t *ctx, const struct node_id *id, u16 num_pong_bytes, u16 len); +bool fromwire_gossipd_ping(const void *p, struct node_id *id, u16 *num_pong_bytes, u16 *len); + +/* WIRE: GOSSIPD_PING_REPLY */ +u8 *towire_gossipd_ping_reply(const tal_t *ctx, const struct node_id *id, bool sent, u16 totlen); +bool fromwire_gossipd_ping_reply(const void *p, struct node_id *id, bool *sent, u16 *totlen); + +/* WIRE: GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE */ +/* Set artificial maximum reply_channel_range size. Master->gossipd */ +u8 *towire_gossipd_dev_set_max_scids_encode_size(const tal_t *ctx, u32 max); +bool fromwire_gossipd_dev_set_max_scids_encode_size(const void *p, u32 *max); + +/* WIRE: GOSSIPD_GET_STRIPPED_CUPDATE */ +/* Given a short_channel_id */ +u8 *towire_gossipd_get_stripped_cupdate(const tal_t *ctx, const struct short_channel_id *channel_id); +bool fromwire_gossipd_get_stripped_cupdate(const void *p, struct short_channel_id *channel_id); + +/* WIRE: GOSSIPD_GET_STRIPPED_CUPDATE_REPLY */ +u8 *towire_gossipd_get_stripped_cupdate_reply(const tal_t *ctx, const u8 *stripped_update); +bool fromwire_gossipd_get_stripped_cupdate_reply(const tal_t *ctx, const void *p, u8 **stripped_update); + +/* WIRE: GOSSIPD_LOCAL_CHANNEL_CLOSE */ +/* gossipd->master: we're closing this channel. */ +u8 *towire_gossipd_local_channel_close(const tal_t *ctx, const struct short_channel_id *short_channel_id); +bool fromwire_gossipd_local_channel_close(const void *p, struct short_channel_id *short_channel_id); + +/* WIRE: GOSSIPD_GET_TXOUT */ +/* Gossipd->master get this tx output please. */ +u8 *towire_gossipd_get_txout(const tal_t *ctx, const struct short_channel_id *short_channel_id); +bool fromwire_gossipd_get_txout(const void *p, struct short_channel_id *short_channel_id); + +/* WIRE: GOSSIPD_GET_TXOUT_REPLY */ +/* master->gossipd here is the output */ +u8 *towire_gossipd_get_txout_reply(const tal_t *ctx, const struct short_channel_id *short_channel_id, struct amount_sat satoshis, const u8 *outscript); +bool fromwire_gossipd_get_txout_reply(const tal_t *ctx, const void *p, struct short_channel_id *short_channel_id, struct amount_sat *satoshis, u8 **outscript); + +/* WIRE: GOSSIPD_PAYMENT_FAILURE */ +/* master->gossipd an htlc failed with this onion error. */ +u8 *towire_gossipd_payment_failure(const tal_t *ctx, const u8 *error); +bool fromwire_gossipd_payment_failure(const tal_t *ctx, const void *p, u8 **error); + +/* WIRE: GOSSIPD_OUTPOINT_SPENT */ +/* master -> gossipd: a potential funding outpoint was spent */ +u8 *towire_gossipd_outpoint_spent(const tal_t *ctx, const struct short_channel_id *short_channel_id); +bool fromwire_gossipd_outpoint_spent(const void *p, struct short_channel_id *short_channel_id); + +/* WIRE: GOSSIPD_DEV_SUPPRESS */ +/* master -> gossipd: stop gossip timers. */ +u8 *towire_gossipd_dev_suppress(const tal_t *ctx); +bool fromwire_gossipd_dev_suppress(const void *p); + +/* WIRE: GOSSIPD_DEV_MEMLEAK */ +/* master -> gossipd: do you have a memleak? */ +u8 *towire_gossipd_dev_memleak(const tal_t *ctx); +bool fromwire_gossipd_dev_memleak(const void *p); + +/* WIRE: GOSSIPD_DEV_MEMLEAK_REPLY */ +u8 *towire_gossipd_dev_memleak_reply(const tal_t *ctx, bool leak); +bool fromwire_gossipd_dev_memleak_reply(const void *p, bool *leak); + +/* WIRE: GOSSIPD_DEV_COMPACT_STORE */ +/* master -> gossipd: please rewrite the gossip_store */ +u8 *towire_gossipd_dev_compact_store(const tal_t *ctx); +bool fromwire_gossipd_dev_compact_store(const void *p); + +/* WIRE: GOSSIPD_DEV_COMPACT_STORE_REPLY */ +/* gossipd -> master: ok */ +u8 *towire_gossipd_dev_compact_store_reply(const tal_t *ctx, bool success); +bool fromwire_gossipd_dev_compact_store_reply(const void *p, bool *success); + +/* WIRE: GOSSIPD_GET_INCOMING_CHANNELS */ +/* master -> gossipd: get route_info for our incoming channels */ +u8 *towire_gossipd_get_incoming_channels(const tal_t *ctx); +bool fromwire_gossipd_get_incoming_channels(const void *p); + +/* WIRE: GOSSIPD_GET_INCOMING_CHANNELS_REPLY */ +/* gossipd -> master: here they are. */ +u8 *towire_gossipd_get_incoming_channels_reply(const tal_t *ctx, const struct route_info *public_route_info, const bool *public_deadends, const struct route_info *private_route_info, const bool *private_deadends); +bool fromwire_gossipd_get_incoming_channels_reply(const tal_t *ctx, const void *p, struct route_info **public_route_info, bool **public_deadends, struct route_info **private_route_info, bool **private_deadends); + +/* WIRE: GOSSIPD_NEW_BLOCKHEIGHT */ +/* master -> gossipd: blockheight increased. */ +u8 *towire_gossipd_new_blockheight(const tal_t *ctx, u32 blockheight); +bool fromwire_gossipd_new_blockheight(const void *p, u32 *blockheight); + + +#endif /* LIGHTNING_GOSSIPD_GOSSIPD_WIREGEN_H */ + +// SHA256STAMP:exp-0-6790ea53b0abf99e5595d11fe496d3ac5fe5b159f15205eca4c34a96856626d8 diff --git a/hsmd/hsmd_wiregen.c b/hsmd/hsmd_wiregen.c new file mode 100644 index 000000000..e4e46b7d6 --- /dev/null +++ b/hsmd/hsmd_wiregen.c @@ -0,0 +1,1218 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Original template can be found at tools/gen/impl_template */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef SUPERVERBOSE +#define SUPERVERBOSE(...) +#endif + +/* Return signature for a funding tx. */ + +const char *hsmd_wire_name(int e) +{ + static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; + + switch ((enum hsmd_wire)e) { + case WIRE_HSMSTATUS_CLIENT_BAD_REQUEST: return "WIRE_HSMSTATUS_CLIENT_BAD_REQUEST"; + case WIRE_HSMD_INIT: return "WIRE_HSMD_INIT"; + case WIRE_HSMD_INIT_REPLY: return "WIRE_HSMD_INIT_REPLY"; + case WIRE_HSMD_CLIENT_HSMFD: return "WIRE_HSMD_CLIENT_HSMFD"; + case WIRE_HSMD_CLIENT_HSMFD_REPLY: return "WIRE_HSMD_CLIENT_HSMFD_REPLY"; + case WIRE_HSMD_GET_CHANNEL_BASEPOINTS: return "WIRE_HSMD_GET_CHANNEL_BASEPOINTS"; + case WIRE_HSMD_GET_CHANNEL_BASEPOINTS_REPLY: return "WIRE_HSMD_GET_CHANNEL_BASEPOINTS_REPLY"; + case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REQ: return "WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REQ"; + case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY: return "WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY"; + case WIRE_HSMD_SIGN_WITHDRAWAL: return "WIRE_HSMD_SIGN_WITHDRAWAL"; + case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY: return "WIRE_HSMD_SIGN_WITHDRAWAL_REPLY"; + case WIRE_HSMD_SIGN_INVOICE: return "WIRE_HSMD_SIGN_INVOICE"; + case WIRE_HSMD_SIGN_INVOICE_REPLY: return "WIRE_HSMD_SIGN_INVOICE_REPLY"; + case WIRE_HSMD_ECDH_REQ: return "WIRE_HSMD_ECDH_REQ"; + case WIRE_HSMD_ECDH_RESP: return "WIRE_HSMD_ECDH_RESP"; + case WIRE_HSMD_CANNOUNCEMENT_SIG_REQ: return "WIRE_HSMD_CANNOUNCEMENT_SIG_REQ"; + case WIRE_HSMD_CANNOUNCEMENT_SIG_REPLY: return "WIRE_HSMD_CANNOUNCEMENT_SIG_REPLY"; + case WIRE_HSMD_CUPDATE_SIG_REQ: return "WIRE_HSMD_CUPDATE_SIG_REQ"; + case WIRE_HSMD_CUPDATE_SIG_REPLY: return "WIRE_HSMD_CUPDATE_SIG_REPLY"; + case WIRE_HSMD_SIGN_COMMITMENT_TX: return "WIRE_HSMD_SIGN_COMMITMENT_TX"; + case WIRE_HSMD_SIGN_COMMITMENT_TX_REPLY: return "WIRE_HSMD_SIGN_COMMITMENT_TX_REPLY"; + case WIRE_HSMD_SIGN_DELAYED_PAYMENT_TO_US: return "WIRE_HSMD_SIGN_DELAYED_PAYMENT_TO_US"; + case WIRE_HSMD_SIGN_REMOTE_HTLC_TO_US: return "WIRE_HSMD_SIGN_REMOTE_HTLC_TO_US"; + case WIRE_HSMD_SIGN_PENALTY_TO_US: return "WIRE_HSMD_SIGN_PENALTY_TO_US"; + case WIRE_HSMD_SIGN_LOCAL_HTLC_TX: return "WIRE_HSMD_SIGN_LOCAL_HTLC_TX"; + case WIRE_HSMD_SIGN_REMOTE_COMMITMENT_TX: return "WIRE_HSMD_SIGN_REMOTE_COMMITMENT_TX"; + case WIRE_HSMD_SIGN_REMOTE_HTLC_TX: return "WIRE_HSMD_SIGN_REMOTE_HTLC_TX"; + case WIRE_HSMD_SIGN_MUTUAL_CLOSE_TX: return "WIRE_HSMD_SIGN_MUTUAL_CLOSE_TX"; + case WIRE_HSMD_SIGN_TX_REPLY: return "WIRE_HSMD_SIGN_TX_REPLY"; + case WIRE_HSMD_GET_PER_COMMITMENT_POINT: return "WIRE_HSMD_GET_PER_COMMITMENT_POINT"; + case WIRE_HSMD_GET_PER_COMMITMENT_POINT_REPLY: return "WIRE_HSMD_GET_PER_COMMITMENT_POINT_REPLY"; + case WIRE_HSMD_DEV_MEMLEAK: return "WIRE_HSMD_DEV_MEMLEAK"; + case WIRE_HSMD_DEV_MEMLEAK_REPLY: return "WIRE_HSMD_DEV_MEMLEAK_REPLY"; + case WIRE_HSMD_CHECK_FUTURE_SECRET: return "WIRE_HSMD_CHECK_FUTURE_SECRET"; + case WIRE_HSMD_CHECK_FUTURE_SECRET_REPLY: return "WIRE_HSMD_CHECK_FUTURE_SECRET_REPLY"; + case WIRE_HSMD_SIGN_MESSAGE: return "WIRE_HSMD_SIGN_MESSAGE"; + case WIRE_HSMD_SIGN_MESSAGE_REPLY: return "WIRE_HSMD_SIGN_MESSAGE_REPLY"; + case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY: return "WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY"; + case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY_REPLY: return "WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY_REPLY"; + } + + snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); + return invalidbuf; +} + +bool hsmd_wire_is_defined(u16 type) +{ + switch ((enum hsmd_wire)type) { + case WIRE_HSMSTATUS_CLIENT_BAD_REQUEST:; + case WIRE_HSMD_INIT:; + case WIRE_HSMD_INIT_REPLY:; + case WIRE_HSMD_CLIENT_HSMFD:; + case WIRE_HSMD_CLIENT_HSMFD_REPLY:; + case WIRE_HSMD_GET_CHANNEL_BASEPOINTS:; + case WIRE_HSMD_GET_CHANNEL_BASEPOINTS_REPLY:; + case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REQ:; + case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY:; + case WIRE_HSMD_SIGN_WITHDRAWAL:; + case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY:; + case WIRE_HSMD_SIGN_INVOICE:; + case WIRE_HSMD_SIGN_INVOICE_REPLY:; + case WIRE_HSMD_ECDH_REQ:; + case WIRE_HSMD_ECDH_RESP:; + case WIRE_HSMD_CANNOUNCEMENT_SIG_REQ:; + case WIRE_HSMD_CANNOUNCEMENT_SIG_REPLY:; + case WIRE_HSMD_CUPDATE_SIG_REQ:; + case WIRE_HSMD_CUPDATE_SIG_REPLY:; + case WIRE_HSMD_SIGN_COMMITMENT_TX:; + case WIRE_HSMD_SIGN_COMMITMENT_TX_REPLY:; + case WIRE_HSMD_SIGN_DELAYED_PAYMENT_TO_US:; + case WIRE_HSMD_SIGN_REMOTE_HTLC_TO_US:; + case WIRE_HSMD_SIGN_PENALTY_TO_US:; + case WIRE_HSMD_SIGN_LOCAL_HTLC_TX:; + case WIRE_HSMD_SIGN_REMOTE_COMMITMENT_TX:; + case WIRE_HSMD_SIGN_REMOTE_HTLC_TX:; + case WIRE_HSMD_SIGN_MUTUAL_CLOSE_TX:; + case WIRE_HSMD_SIGN_TX_REPLY:; + case WIRE_HSMD_GET_PER_COMMITMENT_POINT:; + case WIRE_HSMD_GET_PER_COMMITMENT_POINT_REPLY:; + case WIRE_HSMD_DEV_MEMLEAK:; + case WIRE_HSMD_DEV_MEMLEAK_REPLY:; + case WIRE_HSMD_CHECK_FUTURE_SECRET:; + case WIRE_HSMD_CHECK_FUTURE_SECRET_REPLY:; + case WIRE_HSMD_SIGN_MESSAGE:; + case WIRE_HSMD_SIGN_MESSAGE_REPLY:; + case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY:; + case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY_REPLY:; + return true; + } + return false; +} + + + + + +/* WIRE: HSMSTATUS_CLIENT_BAD_REQUEST */ +/* Clients should not give a bad request but not the HSM's decision to crash. */ +u8 *towire_hsmstatus_client_bad_request(const tal_t *ctx, const struct node_id *id, const wirestring *description, const u8 *msg) +{ + u16 len = tal_count(msg); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMSTATUS_CLIENT_BAD_REQUEST); + towire_node_id(&p, id); + towire_wirestring(&p, description); + towire_u16(&p, len); + towire_u8_array(&p, msg, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmstatus_client_bad_request(const tal_t *ctx, const void *p, struct node_id *id, wirestring **description, u8 **msg) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMSTATUS_CLIENT_BAD_REQUEST) + return false; + fromwire_node_id(&cursor, &plen, id); + *description = fromwire_wirestring(ctx, &cursor, &plen); + len = fromwire_u16(&cursor, &plen); + // 2nd case msg + *msg = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *msg, len); + return cursor != NULL; +} + +/* WIRE: HSMD_INIT */ +/* Start the HSM. */ +u8 *towire_hsmd_init(const tal_t *ctx, const struct bip32_key_version *bip32_key_version, const struct chainparams *chainparams, const struct secret *hsm_encryption_key, const struct privkey *dev_force_privkey, const struct secret *dev_force_bip32_seed, const struct secrets *dev_force_channel_secrets, const struct sha256 *dev_force_channel_secrets_shaseed) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_INIT); + towire_bip32_key_version(&p, bip32_key_version); + towire_chainparams(&p, chainparams); + if (!hsm_encryption_key) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_secret(&p, hsm_encryption_key); + } + if (!dev_force_privkey) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_privkey(&p, dev_force_privkey); + } + if (!dev_force_bip32_seed) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_secret(&p, dev_force_bip32_seed); + } + if (!dev_force_channel_secrets) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_secrets(&p, dev_force_channel_secrets); + } + if (!dev_force_channel_secrets_shaseed) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_sha256(&p, dev_force_channel_secrets_shaseed); + } + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_init(const tal_t *ctx, const void *p, struct bip32_key_version *bip32_key_version, const struct chainparams **chainparams, struct secret **hsm_encryption_key, struct privkey **dev_force_privkey, struct secret **dev_force_bip32_seed, struct secrets **dev_force_channel_secrets, struct sha256 **dev_force_channel_secrets_shaseed) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_INIT) + return false; + fromwire_bip32_key_version(&cursor, &plen, bip32_key_version); + fromwire_chainparams(&cursor, &plen, chainparams); + if (!fromwire_bool(&cursor, &plen)) + *hsm_encryption_key = NULL; + else { + *hsm_encryption_key = tal(ctx, struct secret); + fromwire_secret(&cursor, &plen, *hsm_encryption_key); + } + if (!fromwire_bool(&cursor, &plen)) + *dev_force_privkey = NULL; + else { + *dev_force_privkey = tal(ctx, struct privkey); + fromwire_privkey(&cursor, &plen, *dev_force_privkey); + } + if (!fromwire_bool(&cursor, &plen)) + *dev_force_bip32_seed = NULL; + else { + *dev_force_bip32_seed = tal(ctx, struct secret); + fromwire_secret(&cursor, &plen, *dev_force_bip32_seed); + } + if (!fromwire_bool(&cursor, &plen)) + *dev_force_channel_secrets = NULL; + else { + *dev_force_channel_secrets = tal(ctx, struct secrets); + fromwire_secrets(&cursor, &plen, *dev_force_channel_secrets); + } + if (!fromwire_bool(&cursor, &plen)) + *dev_force_channel_secrets_shaseed = NULL; + else { + *dev_force_channel_secrets_shaseed = tal(ctx, struct sha256); + fromwire_sha256(&cursor, &plen, *dev_force_channel_secrets_shaseed); + } + return cursor != NULL; +} + +/* WIRE: HSMD_INIT_REPLY */ +u8 *towire_hsmd_init_reply(const tal_t *ctx, const struct node_id *node_id, const struct ext_key *bip32) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_INIT_REPLY); + towire_node_id(&p, node_id); + towire_ext_key(&p, bip32); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_init_reply(const void *p, struct node_id *node_id, struct ext_key *bip32) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_INIT_REPLY) + return false; + fromwire_node_id(&cursor, &plen, node_id); + fromwire_ext_key(&cursor, &plen, bip32); + return cursor != NULL; +} + +/* WIRE: HSMD_CLIENT_HSMFD */ +/* Get a new HSM FD */ +u8 *towire_hsmd_client_hsmfd(const tal_t *ctx, const struct node_id *id, u64 dbid, u64 capabilities) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_CLIENT_HSMFD); + /* Which identity to use for requests */ + towire_node_id(&p, id); + /* Database id for this client */ + towire_u64(&p, dbid); + towire_u64(&p, capabilities); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_client_hsmfd(const void *p, struct node_id *id, u64 *dbid, u64 *capabilities) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_CLIENT_HSMFD) + return false; + /* Which identity to use for requests */ + fromwire_node_id(&cursor, &plen, id); + /* Database id for this client */ + *dbid = fromwire_u64(&cursor, &plen); + *capabilities = fromwire_u64(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: HSMD_CLIENT_HSMFD_REPLY */ +/* No content */ +u8 *towire_hsmd_client_hsmfd_reply(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_CLIENT_HSMFD_REPLY); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_client_hsmfd_reply(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_CLIENT_HSMFD_REPLY) + return false; + return cursor != NULL; +} + +/* WIRE: HSMD_GET_CHANNEL_BASEPOINTS */ +/* Get the basepoints and funding key for this specific channel. */ +u8 *towire_hsmd_get_channel_basepoints(const tal_t *ctx, const struct node_id *peerid, u64 dbid) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_GET_CHANNEL_BASEPOINTS); + towire_node_id(&p, peerid); + towire_u64(&p, dbid); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_get_channel_basepoints(const void *p, struct node_id *peerid, u64 *dbid) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_GET_CHANNEL_BASEPOINTS) + return false; + fromwire_node_id(&cursor, &plen, peerid); + *dbid = fromwire_u64(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: HSMD_GET_CHANNEL_BASEPOINTS_REPLY */ +u8 *towire_hsmd_get_channel_basepoints_reply(const tal_t *ctx, const struct basepoints *basepoints, const struct pubkey *funding_pubkey) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_GET_CHANNEL_BASEPOINTS_REPLY); + towire_basepoints(&p, basepoints); + towire_pubkey(&p, funding_pubkey); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_get_channel_basepoints_reply(const void *p, struct basepoints *basepoints, struct pubkey *funding_pubkey) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_GET_CHANNEL_BASEPOINTS_REPLY) + return false; + fromwire_basepoints(&cursor, &plen, basepoints); + fromwire_pubkey(&cursor, &plen, funding_pubkey); + return cursor != NULL; +} + +/* WIRE: HSMD_NODE_ANNOUNCEMENT_SIG_REQ */ +/* Master asks the HSM to sign a node_announcement */ +u8 *towire_hsmd_node_announcement_sig_req(const tal_t *ctx, const u8 *announcement) +{ + u16 annlen = tal_count(announcement); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REQ); + towire_u16(&p, annlen); + towire_u8_array(&p, announcement, annlen); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_node_announcement_sig_req(const tal_t *ctx, const void *p, u8 **announcement) +{ + u16 annlen; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REQ) + return false; + annlen = fromwire_u16(&cursor, &plen); + // 2nd case announcement + *announcement = annlen ? tal_arr(ctx, u8, annlen) : NULL; + fromwire_u8_array(&cursor, &plen, *announcement, annlen); + return cursor != NULL; +} + +/* WIRE: HSMD_NODE_ANNOUNCEMENT_SIG_REPLY */ +u8 *towire_hsmd_node_announcement_sig_reply(const tal_t *ctx, const secp256k1_ecdsa_signature *signature) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY); + towire_secp256k1_ecdsa_signature(&p, signature); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_node_announcement_sig_reply(const void *p, secp256k1_ecdsa_signature *signature) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY) + return false; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, signature); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_WITHDRAWAL */ +/* Sign a withdrawal request */ +u8 *towire_hsmd_sign_withdrawal(const tal_t *ctx, const struct utxo **inputs, const struct wally_psbt *psbt) +{ + u16 num_inputs = tal_count(inputs); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_WITHDRAWAL); + towire_u16(&p, num_inputs); + for (size_t i = 0; i < num_inputs; i++) + towire_utxo(&p, inputs[i]); + towire_wally_psbt(&p, psbt); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_withdrawal(const tal_t *ctx, const void *p, struct utxo ***inputs, struct wally_psbt **psbt) +{ + u16 num_inputs; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_WITHDRAWAL) + return false; + num_inputs = fromwire_u16(&cursor, &plen); + // 2nd case inputs + *inputs = num_inputs ? tal_arr(ctx, struct utxo *, num_inputs) : NULL; + for (size_t i = 0; i < num_inputs; i++) + (*inputs)[i] = fromwire_utxo(*inputs, &cursor, &plen); + *psbt = fromwire_wally_psbt(ctx, &cursor, &plen); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_WITHDRAWAL_REPLY */ +u8 *towire_hsmd_sign_withdrawal_reply(const tal_t *ctx, const struct wally_psbt *psbt) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_WITHDRAWAL_REPLY); + towire_wally_psbt(&p, psbt); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_withdrawal_reply(const tal_t *ctx, const void *p, struct wally_psbt **psbt) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_WITHDRAWAL_REPLY) + return false; + *psbt = fromwire_wally_psbt(ctx, &cursor, &plen); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_INVOICE */ +/* Sign an invoice */ +u8 *towire_hsmd_sign_invoice(const tal_t *ctx, const u8 *u5bytes, const u8 *hrp) +{ + u16 len = tal_count(u5bytes); + u16 hrplen = tal_count(hrp); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_INVOICE); + towire_u16(&p, len); + towire_u8_array(&p, u5bytes, len); + towire_u16(&p, hrplen); + towire_u8_array(&p, hrp, hrplen); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_invoice(const tal_t *ctx, const void *p, u8 **u5bytes, u8 **hrp) +{ + u16 len; + u16 hrplen; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_INVOICE) + return false; + len = fromwire_u16(&cursor, &plen); + // 2nd case u5bytes + *u5bytes = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *u5bytes, len); + hrplen = fromwire_u16(&cursor, &plen); + // 2nd case hrp + *hrp = hrplen ? tal_arr(ctx, u8, hrplen) : NULL; + fromwire_u8_array(&cursor, &plen, *hrp, hrplen); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_INVOICE_REPLY */ +u8 *towire_hsmd_sign_invoice_reply(const tal_t *ctx, const secp256k1_ecdsa_recoverable_signature *sig) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_INVOICE_REPLY); + towire_secp256k1_ecdsa_recoverable_signature(&p, sig); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_invoice_reply(const void *p, secp256k1_ecdsa_recoverable_signature *sig) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_INVOICE_REPLY) + return false; + fromwire_secp256k1_ecdsa_recoverable_signature(&cursor, &plen, sig); + return cursor != NULL; +} + +/* WIRE: HSMD_ECDH_REQ */ +/* Give me ECDH(node-id-secret */ +u8 *towire_hsmd_ecdh_req(const tal_t *ctx, const struct pubkey *point) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_ECDH_REQ); + towire_pubkey(&p, point); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_ecdh_req(const void *p, struct pubkey *point) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_ECDH_REQ) + return false; + fromwire_pubkey(&cursor, &plen, point); + return cursor != NULL; +} + +/* WIRE: HSMD_ECDH_RESP */ +u8 *towire_hsmd_ecdh_resp(const tal_t *ctx, const struct secret *ss) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_ECDH_RESP); + towire_secret(&p, ss); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_ecdh_resp(const void *p, struct secret *ss) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_ECDH_RESP) + return false; + fromwire_secret(&cursor, &plen, ss); + return cursor != NULL; +} + +/* WIRE: HSMD_CANNOUNCEMENT_SIG_REQ */ +u8 *towire_hsmd_cannouncement_sig_req(const tal_t *ctx, const u8 *ca) +{ + u16 calen = tal_count(ca); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_CANNOUNCEMENT_SIG_REQ); + towire_u16(&p, calen); + towire_u8_array(&p, ca, calen); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_cannouncement_sig_req(const tal_t *ctx, const void *p, u8 **ca) +{ + u16 calen; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_CANNOUNCEMENT_SIG_REQ) + return false; + calen = fromwire_u16(&cursor, &plen); + // 2nd case ca + *ca = calen ? tal_arr(ctx, u8, calen) : NULL; + fromwire_u8_array(&cursor, &plen, *ca, calen); + return cursor != NULL; +} + +/* WIRE: HSMD_CANNOUNCEMENT_SIG_REPLY */ +u8 *towire_hsmd_cannouncement_sig_reply(const tal_t *ctx, const secp256k1_ecdsa_signature *node_signature, const secp256k1_ecdsa_signature *bitcoin_signature) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_CANNOUNCEMENT_SIG_REPLY); + towire_secp256k1_ecdsa_signature(&p, node_signature); + towire_secp256k1_ecdsa_signature(&p, bitcoin_signature); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_cannouncement_sig_reply(const void *p, secp256k1_ecdsa_signature *node_signature, secp256k1_ecdsa_signature *bitcoin_signature) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_CANNOUNCEMENT_SIG_REPLY) + return false; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, node_signature); + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, bitcoin_signature); + return cursor != NULL; +} + +/* WIRE: HSMD_CUPDATE_SIG_REQ */ +u8 *towire_hsmd_cupdate_sig_req(const tal_t *ctx, const u8 *cu) +{ + u16 culen = tal_count(cu); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_CUPDATE_SIG_REQ); + towire_u16(&p, culen); + towire_u8_array(&p, cu, culen); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_cupdate_sig_req(const tal_t *ctx, const void *p, u8 **cu) +{ + u16 culen; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_CUPDATE_SIG_REQ) + return false; + culen = fromwire_u16(&cursor, &plen); + // 2nd case cu + *cu = culen ? tal_arr(ctx, u8, culen) : NULL; + fromwire_u8_array(&cursor, &plen, *cu, culen); + return cursor != NULL; +} + +/* WIRE: HSMD_CUPDATE_SIG_REPLY */ +u8 *towire_hsmd_cupdate_sig_reply(const tal_t *ctx, const u8 *cu) +{ + u16 culen = tal_count(cu); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_CUPDATE_SIG_REPLY); + towire_u16(&p, culen); + towire_u8_array(&p, cu, culen); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_cupdate_sig_reply(const tal_t *ctx, const void *p, u8 **cu) +{ + u16 culen; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_CUPDATE_SIG_REPLY) + return false; + culen = fromwire_u16(&cursor, &plen); + // 2nd case cu + *cu = culen ? tal_arr(ctx, u8, culen) : NULL; + fromwire_u8_array(&cursor, &plen, *cu, culen); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_COMMITMENT_TX */ +/* Master asks HSM to sign a commitment transaction. */ +u8 *towire_hsmd_sign_commitment_tx(const tal_t *ctx, const struct node_id *peer_id, u64 channel_dbid, const struct bitcoin_tx *tx, const struct pubkey *remote_funding_key) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_COMMITMENT_TX); + towire_node_id(&p, peer_id); + towire_u64(&p, channel_dbid); + towire_bitcoin_tx(&p, tx); + towire_pubkey(&p, remote_funding_key); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_commitment_tx(const tal_t *ctx, const void *p, struct node_id *peer_id, u64 *channel_dbid, struct bitcoin_tx **tx, struct pubkey *remote_funding_key) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_COMMITMENT_TX) + return false; + fromwire_node_id(&cursor, &plen, peer_id); + *channel_dbid = fromwire_u64(&cursor, &plen); + *tx = fromwire_bitcoin_tx(ctx, &cursor, &plen); + fromwire_pubkey(&cursor, &plen, remote_funding_key); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_COMMITMENT_TX_REPLY */ +u8 *towire_hsmd_sign_commitment_tx_reply(const tal_t *ctx, const struct bitcoin_signature *sig) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_COMMITMENT_TX_REPLY); + towire_bitcoin_signature(&p, sig); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_commitment_tx_reply(const void *p, struct bitcoin_signature *sig) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_COMMITMENT_TX_REPLY) + return false; + fromwire_bitcoin_signature(&cursor, &plen, sig); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_DELAYED_PAYMENT_TO_US */ +/* Onchaind asks HSM to sign a spend to-us. Four variants */ +/* of keys is derived differently... */ +/* FIXME: Have master tell hsmd the keyindex */ +u8 *towire_hsmd_sign_delayed_payment_to_us(const tal_t *ctx, u64 commit_num, const struct bitcoin_tx *tx, const u8 *wscript) +{ + u16 wscript_len = tal_count(wscript); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_DELAYED_PAYMENT_TO_US); + towire_u64(&p, commit_num); + towire_bitcoin_tx(&p, tx); + towire_u16(&p, wscript_len); + towire_u8_array(&p, wscript, wscript_len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_delayed_payment_to_us(const tal_t *ctx, const void *p, u64 *commit_num, struct bitcoin_tx **tx, u8 **wscript) +{ + u16 wscript_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_DELAYED_PAYMENT_TO_US) + return false; + *commit_num = fromwire_u64(&cursor, &plen); + *tx = fromwire_bitcoin_tx(ctx, &cursor, &plen); + wscript_len = fromwire_u16(&cursor, &plen); + // 2nd case wscript + *wscript = wscript_len ? tal_arr(ctx, u8, wscript_len) : NULL; + fromwire_u8_array(&cursor, &plen, *wscript, wscript_len); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_REMOTE_HTLC_TO_US */ +u8 *towire_hsmd_sign_remote_htlc_to_us(const tal_t *ctx, const struct pubkey *remote_per_commitment_point, const struct bitcoin_tx *tx, const u8 *wscript, bool option_anchor_outputs) +{ + u16 wscript_len = tal_count(wscript); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_REMOTE_HTLC_TO_US); + towire_pubkey(&p, remote_per_commitment_point); + towire_bitcoin_tx(&p, tx); + towire_u16(&p, wscript_len); + towire_u8_array(&p, wscript, wscript_len); + towire_bool(&p, option_anchor_outputs); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_remote_htlc_to_us(const tal_t *ctx, const void *p, struct pubkey *remote_per_commitment_point, struct bitcoin_tx **tx, u8 **wscript, bool *option_anchor_outputs) +{ + u16 wscript_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_REMOTE_HTLC_TO_US) + return false; + fromwire_pubkey(&cursor, &plen, remote_per_commitment_point); + *tx = fromwire_bitcoin_tx(ctx, &cursor, &plen); + wscript_len = fromwire_u16(&cursor, &plen); + // 2nd case wscript + *wscript = wscript_len ? tal_arr(ctx, u8, wscript_len) : NULL; + fromwire_u8_array(&cursor, &plen, *wscript, wscript_len); + *option_anchor_outputs = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_PENALTY_TO_US */ +u8 *towire_hsmd_sign_penalty_to_us(const tal_t *ctx, const struct secret *revocation_secret, const struct bitcoin_tx *tx, const u8 *wscript) +{ + u16 wscript_len = tal_count(wscript); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_PENALTY_TO_US); + towire_secret(&p, revocation_secret); + towire_bitcoin_tx(&p, tx); + towire_u16(&p, wscript_len); + towire_u8_array(&p, wscript, wscript_len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_penalty_to_us(const tal_t *ctx, const void *p, struct secret *revocation_secret, struct bitcoin_tx **tx, u8 **wscript) +{ + u16 wscript_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_PENALTY_TO_US) + return false; + fromwire_secret(&cursor, &plen, revocation_secret); + *tx = fromwire_bitcoin_tx(ctx, &cursor, &plen); + wscript_len = fromwire_u16(&cursor, &plen); + // 2nd case wscript + *wscript = wscript_len ? tal_arr(ctx, u8, wscript_len) : NULL; + fromwire_u8_array(&cursor, &plen, *wscript, wscript_len); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_LOCAL_HTLC_TX */ +/* Onchaind asks HSM to sign a local HTLC success or HTLC timeout tx. */ +u8 *towire_hsmd_sign_local_htlc_tx(const tal_t *ctx, u64 commit_num, const struct bitcoin_tx *tx, const u8 *wscript, bool option_anchor_outputs) +{ + u16 wscript_len = tal_count(wscript); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_LOCAL_HTLC_TX); + towire_u64(&p, commit_num); + towire_bitcoin_tx(&p, tx); + towire_u16(&p, wscript_len); + towire_u8_array(&p, wscript, wscript_len); + towire_bool(&p, option_anchor_outputs); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_local_htlc_tx(const tal_t *ctx, const void *p, u64 *commit_num, struct bitcoin_tx **tx, u8 **wscript, bool *option_anchor_outputs) +{ + u16 wscript_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_LOCAL_HTLC_TX) + return false; + *commit_num = fromwire_u64(&cursor, &plen); + *tx = fromwire_bitcoin_tx(ctx, &cursor, &plen); + wscript_len = fromwire_u16(&cursor, &plen); + // 2nd case wscript + *wscript = wscript_len ? tal_arr(ctx, u8, wscript_len) : NULL; + fromwire_u8_array(&cursor, &plen, *wscript, wscript_len); + *option_anchor_outputs = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_REMOTE_COMMITMENT_TX */ +/* Openingd/channeld asks HSM to sign the other sides' commitment tx. */ +u8 *towire_hsmd_sign_remote_commitment_tx(const tal_t *ctx, const struct bitcoin_tx *tx, const struct pubkey *remote_funding_key, const struct pubkey *remote_per_commit, bool option_static_remotekey) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_REMOTE_COMMITMENT_TX); + towire_bitcoin_tx(&p, tx); + towire_pubkey(&p, remote_funding_key); + towire_pubkey(&p, remote_per_commit); + towire_bool(&p, option_static_remotekey); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_remote_commitment_tx(const tal_t *ctx, const void *p, struct bitcoin_tx **tx, struct pubkey *remote_funding_key, struct pubkey *remote_per_commit, bool *option_static_remotekey) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_REMOTE_COMMITMENT_TX) + return false; + *tx = fromwire_bitcoin_tx(ctx, &cursor, &plen); + fromwire_pubkey(&cursor, &plen, remote_funding_key); + fromwire_pubkey(&cursor, &plen, remote_per_commit); + *option_static_remotekey = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_REMOTE_HTLC_TX */ +/* channeld asks HSM to sign remote HTLC tx. */ +u8 *towire_hsmd_sign_remote_htlc_tx(const tal_t *ctx, const struct bitcoin_tx *tx, const u8 *wscript, const struct pubkey *remote_per_commit_point, bool option_anchor_outputs) +{ + u16 len = tal_count(wscript); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_REMOTE_HTLC_TX); + towire_bitcoin_tx(&p, tx); + towire_u16(&p, len); + towire_u8_array(&p, wscript, len); + towire_pubkey(&p, remote_per_commit_point); + towire_bool(&p, option_anchor_outputs); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_remote_htlc_tx(const tal_t *ctx, const void *p, struct bitcoin_tx **tx, u8 **wscript, struct pubkey *remote_per_commit_point, bool *option_anchor_outputs) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_REMOTE_HTLC_TX) + return false; + *tx = fromwire_bitcoin_tx(ctx, &cursor, &plen); + len = fromwire_u16(&cursor, &plen); + // 2nd case wscript + *wscript = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *wscript, len); + fromwire_pubkey(&cursor, &plen, remote_per_commit_point); + *option_anchor_outputs = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_MUTUAL_CLOSE_TX */ +/* closingd asks HSM to sign mutual close tx. */ +u8 *towire_hsmd_sign_mutual_close_tx(const tal_t *ctx, const struct bitcoin_tx *tx, const struct pubkey *remote_funding_key) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_MUTUAL_CLOSE_TX); + towire_bitcoin_tx(&p, tx); + towire_pubkey(&p, remote_funding_key); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_mutual_close_tx(const tal_t *ctx, const void *p, struct bitcoin_tx **tx, struct pubkey *remote_funding_key) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_MUTUAL_CLOSE_TX) + return false; + *tx = fromwire_bitcoin_tx(ctx, &cursor, &plen); + fromwire_pubkey(&cursor, &plen, remote_funding_key); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_TX_REPLY */ +/* Reply for all the above requests. */ +u8 *towire_hsmd_sign_tx_reply(const tal_t *ctx, const struct bitcoin_signature *sig) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_TX_REPLY); + towire_bitcoin_signature(&p, sig); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_tx_reply(const void *p, struct bitcoin_signature *sig) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_TX_REPLY) + return false; + fromwire_bitcoin_signature(&cursor, &plen, sig); + return cursor != NULL; +} + +/* WIRE: HSMD_GET_PER_COMMITMENT_POINT */ +/* Openingd/channeld/onchaind asks for Nth per_commitment_point */ +u8 *towire_hsmd_get_per_commitment_point(const tal_t *ctx, u64 n) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_GET_PER_COMMITMENT_POINT); + towire_u64(&p, n); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_get_per_commitment_point(const void *p, u64 *n) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_GET_PER_COMMITMENT_POINT) + return false; + *n = fromwire_u64(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: HSMD_GET_PER_COMMITMENT_POINT_REPLY */ +u8 *towire_hsmd_get_per_commitment_point_reply(const tal_t *ctx, const struct pubkey *per_commitment_point, const struct secret *old_commitment_secret) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_GET_PER_COMMITMENT_POINT_REPLY); + towire_pubkey(&p, per_commitment_point); + if (!old_commitment_secret) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_secret(&p, old_commitment_secret); + } + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_get_per_commitment_point_reply(const tal_t *ctx, const void *p, struct pubkey *per_commitment_point, struct secret **old_commitment_secret) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_GET_PER_COMMITMENT_POINT_REPLY) + return false; + fromwire_pubkey(&cursor, &plen, per_commitment_point); + if (!fromwire_bool(&cursor, &plen)) + *old_commitment_secret = NULL; + else { + *old_commitment_secret = tal(ctx, struct secret); + fromwire_secret(&cursor, &plen, *old_commitment_secret); + } + return cursor != NULL; +} + +/* WIRE: HSMD_DEV_MEMLEAK */ +/* master -> hsmd: do you have a memleak? */ +u8 *towire_hsmd_dev_memleak(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_DEV_MEMLEAK); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_dev_memleak(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_DEV_MEMLEAK) + return false; + return cursor != NULL; +} + +/* WIRE: HSMD_DEV_MEMLEAK_REPLY */ +u8 *towire_hsmd_dev_memleak_reply(const tal_t *ctx, bool leak) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_DEV_MEMLEAK_REPLY); + towire_bool(&p, leak); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_dev_memleak_reply(const void *p, bool *leak) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_DEV_MEMLEAK_REPLY) + return false; + *leak = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: HSMD_CHECK_FUTURE_SECRET */ +/* channeld asks to check if claimed future commitment_secret is correct. */ +u8 *towire_hsmd_check_future_secret(const tal_t *ctx, u64 n, const struct secret *commitment_secret) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_CHECK_FUTURE_SECRET); + towire_u64(&p, n); + towire_secret(&p, commitment_secret); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_check_future_secret(const void *p, u64 *n, struct secret *commitment_secret) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_CHECK_FUTURE_SECRET) + return false; + *n = fromwire_u64(&cursor, &plen); + fromwire_secret(&cursor, &plen, commitment_secret); + return cursor != NULL; +} + +/* WIRE: HSMD_CHECK_FUTURE_SECRET_REPLY */ +u8 *towire_hsmd_check_future_secret_reply(const tal_t *ctx, bool correct) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_CHECK_FUTURE_SECRET_REPLY); + towire_bool(&p, correct); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_check_future_secret_reply(const void *p, bool *correct) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_CHECK_FUTURE_SECRET_REPLY) + return false; + *correct = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_MESSAGE */ +/* lightningd asks us to sign a string. */ +u8 *towire_hsmd_sign_message(const tal_t *ctx, const u8 *msg) +{ + u16 len = tal_count(msg); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_MESSAGE); + towire_u16(&p, len); + towire_u8_array(&p, msg, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_message(const tal_t *ctx, const void *p, u8 **msg) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_MESSAGE) + return false; + len = fromwire_u16(&cursor, &plen); + // 2nd case msg + *msg = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *msg, len); + return cursor != NULL; +} + +/* WIRE: HSMD_SIGN_MESSAGE_REPLY */ +u8 *towire_hsmd_sign_message_reply(const tal_t *ctx, const secp256k1_ecdsa_recoverable_signature *sig) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_SIGN_MESSAGE_REPLY); + towire_secp256k1_ecdsa_recoverable_signature(&p, sig); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_sign_message_reply(const void *p, secp256k1_ecdsa_recoverable_signature *sig) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_SIGN_MESSAGE_REPLY) + return false; + fromwire_secp256k1_ecdsa_recoverable_signature(&cursor, &plen, sig); + return cursor != NULL; +} + +/* WIRE: HSMD_GET_OUTPUT_SCRIPTPUBKEY */ +/* lightningd needs to get a scriptPubkey for a utxo with closeinfo */ +u8 *towire_hsmd_get_output_scriptpubkey(const tal_t *ctx, u64 channel_id, const struct node_id *peer_id, const struct pubkey *commitment_point) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY); + towire_u64(&p, channel_id); + towire_node_id(&p, peer_id); + if (!commitment_point) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_pubkey(&p, commitment_point); + } + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_get_output_scriptpubkey(const tal_t *ctx, const void *p, u64 *channel_id, struct node_id *peer_id, struct pubkey **commitment_point) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY) + return false; + *channel_id = fromwire_u64(&cursor, &plen); + fromwire_node_id(&cursor, &plen, peer_id); + if (!fromwire_bool(&cursor, &plen)) + *commitment_point = NULL; + else { + *commitment_point = tal(ctx, struct pubkey); + fromwire_pubkey(&cursor, &plen, *commitment_point); + } + return cursor != NULL; +} + +/* WIRE: HSMD_GET_OUTPUT_SCRIPTPUBKEY_REPLY */ +u8 *towire_hsmd_get_output_scriptpubkey_reply(const tal_t *ctx, const u8 *script) +{ + u16 script_len = tal_count(script); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY_REPLY); + towire_u16(&p, script_len); + towire_u8_array(&p, script, script_len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_hsmd_get_output_scriptpubkey_reply(const tal_t *ctx, const void *p, u8 **script) +{ + u16 script_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY_REPLY) + return false; + script_len = fromwire_u16(&cursor, &plen); + // 2nd case script + *script = script_len ? tal_arr(ctx, u8, script_len) : NULL; + fromwire_u8_array(&cursor, &plen, *script, script_len); + return cursor != NULL; +} + +// SHA256STAMP:exp-0-fd33f5b428d1806da30507ca94c8e34f3c7c0023ecf87c55aa2867a403d5a20c diff --git a/hsmd/hsmd_wiregen.h b/hsmd/hsmd_wiregen.h new file mode 100644 index 000000000..e73f113b5 --- /dev/null +++ b/hsmd/hsmd_wiregen.h @@ -0,0 +1,275 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the _csv file it was generated from. */ +/* Original template can be found at tools/gen/header_template */ + +#ifndef LIGHTNING_HSMD_HSMD_WIREGEN_H +#define LIGHTNING_HSMD_HSMD_WIREGEN_H +#include +#include +#include +#include +#include +#include +#include +#include + +enum hsmd_wire { + /* Clients should not give a bad request but not the HSM's decision to crash. */ + WIRE_HSMSTATUS_CLIENT_BAD_REQUEST = 1000, + /* Start the HSM. */ + WIRE_HSMD_INIT = 11, + WIRE_HSMD_INIT_REPLY = 111, + /* Get a new HSM FD */ + WIRE_HSMD_CLIENT_HSMFD = 9, + /* No content */ + WIRE_HSMD_CLIENT_HSMFD_REPLY = 109, + /* Get the basepoints and funding key for this specific channel. */ + WIRE_HSMD_GET_CHANNEL_BASEPOINTS = 10, + WIRE_HSMD_GET_CHANNEL_BASEPOINTS_REPLY = 110, + /* Master asks the HSM to sign a node_announcement */ + WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REQ = 6, + WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY = 106, + /* Sign a withdrawal request */ + WIRE_HSMD_SIGN_WITHDRAWAL = 7, + WIRE_HSMD_SIGN_WITHDRAWAL_REPLY = 107, + /* Sign an invoice */ + WIRE_HSMD_SIGN_INVOICE = 8, + WIRE_HSMD_SIGN_INVOICE_REPLY = 108, + /* Give me ECDH(node-id-secret */ + WIRE_HSMD_ECDH_REQ = 1, + WIRE_HSMD_ECDH_RESP = 100, + WIRE_HSMD_CANNOUNCEMENT_SIG_REQ = 2, + WIRE_HSMD_CANNOUNCEMENT_SIG_REPLY = 102, + WIRE_HSMD_CUPDATE_SIG_REQ = 3, + WIRE_HSMD_CUPDATE_SIG_REPLY = 103, + /* Master asks HSM to sign a commitment transaction. */ + WIRE_HSMD_SIGN_COMMITMENT_TX = 5, + WIRE_HSMD_SIGN_COMMITMENT_TX_REPLY = 105, + /* Onchaind asks HSM to sign a spend to-us. Four variants */ + /* of keys is derived differently... */ + /* FIXME: Have master tell hsmd the keyindex */ + WIRE_HSMD_SIGN_DELAYED_PAYMENT_TO_US = 12, + WIRE_HSMD_SIGN_REMOTE_HTLC_TO_US = 13, + WIRE_HSMD_SIGN_PENALTY_TO_US = 14, + /* Onchaind asks HSM to sign a local HTLC success or HTLC timeout tx. */ + WIRE_HSMD_SIGN_LOCAL_HTLC_TX = 16, + /* Openingd/channeld asks HSM to sign the other sides' commitment tx. */ + WIRE_HSMD_SIGN_REMOTE_COMMITMENT_TX = 19, + /* channeld asks HSM to sign remote HTLC tx. */ + WIRE_HSMD_SIGN_REMOTE_HTLC_TX = 20, + /* closingd asks HSM to sign mutual close tx. */ + WIRE_HSMD_SIGN_MUTUAL_CLOSE_TX = 21, + /* Reply for all the above requests. */ + WIRE_HSMD_SIGN_TX_REPLY = 112, + /* Openingd/channeld/onchaind asks for Nth per_commitment_point */ + WIRE_HSMD_GET_PER_COMMITMENT_POINT = 18, + WIRE_HSMD_GET_PER_COMMITMENT_POINT_REPLY = 118, + /* master -> hsmd: do you have a memleak? */ + WIRE_HSMD_DEV_MEMLEAK = 33, + WIRE_HSMD_DEV_MEMLEAK_REPLY = 133, + /* channeld asks to check if claimed future commitment_secret is correct. */ + WIRE_HSMD_CHECK_FUTURE_SECRET = 22, + WIRE_HSMD_CHECK_FUTURE_SECRET_REPLY = 122, + /* lightningd asks us to sign a string. */ + WIRE_HSMD_SIGN_MESSAGE = 23, + WIRE_HSMD_SIGN_MESSAGE_REPLY = 123, + /* lightningd needs to get a scriptPubkey for a utxo with closeinfo */ + WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY = 24, + WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY_REPLY = 124, +}; + +const char *hsmd_wire_name(int e); + +/** + * Determine whether a given message type is defined as a message. + * + * Returns true if the message type is part of the message definitions we have + * generated parsers for, false if it is a custom message that cannot be + * handled internally. + */ +bool hsmd_wire_is_defined(u16 type); + + +/* WIRE: HSMSTATUS_CLIENT_BAD_REQUEST */ +/* Clients should not give a bad request but not the HSM's decision to crash. */ +u8 *towire_hsmstatus_client_bad_request(const tal_t *ctx, const struct node_id *id, const wirestring *description, const u8 *msg); +bool fromwire_hsmstatus_client_bad_request(const tal_t *ctx, const void *p, struct node_id *id, wirestring **description, u8 **msg); + +/* WIRE: HSMD_INIT */ +/* Start the HSM. */ +u8 *towire_hsmd_init(const tal_t *ctx, const struct bip32_key_version *bip32_key_version, const struct chainparams *chainparams, const struct secret *hsm_encryption_key, const struct privkey *dev_force_privkey, const struct secret *dev_force_bip32_seed, const struct secrets *dev_force_channel_secrets, const struct sha256 *dev_force_channel_secrets_shaseed); +bool fromwire_hsmd_init(const tal_t *ctx, const void *p, struct bip32_key_version *bip32_key_version, const struct chainparams **chainparams, struct secret **hsm_encryption_key, struct privkey **dev_force_privkey, struct secret **dev_force_bip32_seed, struct secrets **dev_force_channel_secrets, struct sha256 **dev_force_channel_secrets_shaseed); + +/* WIRE: HSMD_INIT_REPLY */ +u8 *towire_hsmd_init_reply(const tal_t *ctx, const struct node_id *node_id, const struct ext_key *bip32); +bool fromwire_hsmd_init_reply(const void *p, struct node_id *node_id, struct ext_key *bip32); + +/* WIRE: HSMD_CLIENT_HSMFD */ +/* Get a new HSM FD */ +u8 *towire_hsmd_client_hsmfd(const tal_t *ctx, const struct node_id *id, u64 dbid, u64 capabilities); +bool fromwire_hsmd_client_hsmfd(const void *p, struct node_id *id, u64 *dbid, u64 *capabilities); + +/* WIRE: HSMD_CLIENT_HSMFD_REPLY */ +/* No content */ +u8 *towire_hsmd_client_hsmfd_reply(const tal_t *ctx); +bool fromwire_hsmd_client_hsmfd_reply(const void *p); + +/* WIRE: HSMD_GET_CHANNEL_BASEPOINTS */ +/* Get the basepoints and funding key for this specific channel. */ +u8 *towire_hsmd_get_channel_basepoints(const tal_t *ctx, const struct node_id *peerid, u64 dbid); +bool fromwire_hsmd_get_channel_basepoints(const void *p, struct node_id *peerid, u64 *dbid); + +/* WIRE: HSMD_GET_CHANNEL_BASEPOINTS_REPLY */ +u8 *towire_hsmd_get_channel_basepoints_reply(const tal_t *ctx, const struct basepoints *basepoints, const struct pubkey *funding_pubkey); +bool fromwire_hsmd_get_channel_basepoints_reply(const void *p, struct basepoints *basepoints, struct pubkey *funding_pubkey); + +/* WIRE: HSMD_NODE_ANNOUNCEMENT_SIG_REQ */ +/* Master asks the HSM to sign a node_announcement */ +u8 *towire_hsmd_node_announcement_sig_req(const tal_t *ctx, const u8 *announcement); +bool fromwire_hsmd_node_announcement_sig_req(const tal_t *ctx, const void *p, u8 **announcement); + +/* WIRE: HSMD_NODE_ANNOUNCEMENT_SIG_REPLY */ +u8 *towire_hsmd_node_announcement_sig_reply(const tal_t *ctx, const secp256k1_ecdsa_signature *signature); +bool fromwire_hsmd_node_announcement_sig_reply(const void *p, secp256k1_ecdsa_signature *signature); + +/* WIRE: HSMD_SIGN_WITHDRAWAL */ +/* Sign a withdrawal request */ +u8 *towire_hsmd_sign_withdrawal(const tal_t *ctx, const struct utxo **inputs, const struct wally_psbt *psbt); +bool fromwire_hsmd_sign_withdrawal(const tal_t *ctx, const void *p, struct utxo ***inputs, struct wally_psbt **psbt); + +/* WIRE: HSMD_SIGN_WITHDRAWAL_REPLY */ +u8 *towire_hsmd_sign_withdrawal_reply(const tal_t *ctx, const struct wally_psbt *psbt); +bool fromwire_hsmd_sign_withdrawal_reply(const tal_t *ctx, const void *p, struct wally_psbt **psbt); + +/* WIRE: HSMD_SIGN_INVOICE */ +/* Sign an invoice */ +u8 *towire_hsmd_sign_invoice(const tal_t *ctx, const u8 *u5bytes, const u8 *hrp); +bool fromwire_hsmd_sign_invoice(const tal_t *ctx, const void *p, u8 **u5bytes, u8 **hrp); + +/* WIRE: HSMD_SIGN_INVOICE_REPLY */ +u8 *towire_hsmd_sign_invoice_reply(const tal_t *ctx, const secp256k1_ecdsa_recoverable_signature *sig); +bool fromwire_hsmd_sign_invoice_reply(const void *p, secp256k1_ecdsa_recoverable_signature *sig); + +/* WIRE: HSMD_ECDH_REQ */ +/* Give me ECDH(node-id-secret */ +u8 *towire_hsmd_ecdh_req(const tal_t *ctx, const struct pubkey *point); +bool fromwire_hsmd_ecdh_req(const void *p, struct pubkey *point); + +/* WIRE: HSMD_ECDH_RESP */ +u8 *towire_hsmd_ecdh_resp(const tal_t *ctx, const struct secret *ss); +bool fromwire_hsmd_ecdh_resp(const void *p, struct secret *ss); + +/* WIRE: HSMD_CANNOUNCEMENT_SIG_REQ */ +u8 *towire_hsmd_cannouncement_sig_req(const tal_t *ctx, const u8 *ca); +bool fromwire_hsmd_cannouncement_sig_req(const tal_t *ctx, const void *p, u8 **ca); + +/* WIRE: HSMD_CANNOUNCEMENT_SIG_REPLY */ +u8 *towire_hsmd_cannouncement_sig_reply(const tal_t *ctx, const secp256k1_ecdsa_signature *node_signature, const secp256k1_ecdsa_signature *bitcoin_signature); +bool fromwire_hsmd_cannouncement_sig_reply(const void *p, secp256k1_ecdsa_signature *node_signature, secp256k1_ecdsa_signature *bitcoin_signature); + +/* WIRE: HSMD_CUPDATE_SIG_REQ */ +u8 *towire_hsmd_cupdate_sig_req(const tal_t *ctx, const u8 *cu); +bool fromwire_hsmd_cupdate_sig_req(const tal_t *ctx, const void *p, u8 **cu); + +/* WIRE: HSMD_CUPDATE_SIG_REPLY */ +u8 *towire_hsmd_cupdate_sig_reply(const tal_t *ctx, const u8 *cu); +bool fromwire_hsmd_cupdate_sig_reply(const tal_t *ctx, const void *p, u8 **cu); + +/* WIRE: HSMD_SIGN_COMMITMENT_TX */ +/* Master asks HSM to sign a commitment transaction. */ +u8 *towire_hsmd_sign_commitment_tx(const tal_t *ctx, const struct node_id *peer_id, u64 channel_dbid, const struct bitcoin_tx *tx, const struct pubkey *remote_funding_key); +bool fromwire_hsmd_sign_commitment_tx(const tal_t *ctx, const void *p, struct node_id *peer_id, u64 *channel_dbid, struct bitcoin_tx **tx, struct pubkey *remote_funding_key); + +/* WIRE: HSMD_SIGN_COMMITMENT_TX_REPLY */ +u8 *towire_hsmd_sign_commitment_tx_reply(const tal_t *ctx, const struct bitcoin_signature *sig); +bool fromwire_hsmd_sign_commitment_tx_reply(const void *p, struct bitcoin_signature *sig); + +/* WIRE: HSMD_SIGN_DELAYED_PAYMENT_TO_US */ +/* Onchaind asks HSM to sign a spend to-us. Four variants */ +/* of keys is derived differently... */ +/* FIXME: Have master tell hsmd the keyindex */ +u8 *towire_hsmd_sign_delayed_payment_to_us(const tal_t *ctx, u64 commit_num, const struct bitcoin_tx *tx, const u8 *wscript); +bool fromwire_hsmd_sign_delayed_payment_to_us(const tal_t *ctx, const void *p, u64 *commit_num, struct bitcoin_tx **tx, u8 **wscript); + +/* WIRE: HSMD_SIGN_REMOTE_HTLC_TO_US */ +u8 *towire_hsmd_sign_remote_htlc_to_us(const tal_t *ctx, const struct pubkey *remote_per_commitment_point, const struct bitcoin_tx *tx, const u8 *wscript, bool option_anchor_outputs); +bool fromwire_hsmd_sign_remote_htlc_to_us(const tal_t *ctx, const void *p, struct pubkey *remote_per_commitment_point, struct bitcoin_tx **tx, u8 **wscript, bool *option_anchor_outputs); + +/* WIRE: HSMD_SIGN_PENALTY_TO_US */ +u8 *towire_hsmd_sign_penalty_to_us(const tal_t *ctx, const struct secret *revocation_secret, const struct bitcoin_tx *tx, const u8 *wscript); +bool fromwire_hsmd_sign_penalty_to_us(const tal_t *ctx, const void *p, struct secret *revocation_secret, struct bitcoin_tx **tx, u8 **wscript); + +/* WIRE: HSMD_SIGN_LOCAL_HTLC_TX */ +/* Onchaind asks HSM to sign a local HTLC success or HTLC timeout tx. */ +u8 *towire_hsmd_sign_local_htlc_tx(const tal_t *ctx, u64 commit_num, const struct bitcoin_tx *tx, const u8 *wscript, bool option_anchor_outputs); +bool fromwire_hsmd_sign_local_htlc_tx(const tal_t *ctx, const void *p, u64 *commit_num, struct bitcoin_tx **tx, u8 **wscript, bool *option_anchor_outputs); + +/* WIRE: HSMD_SIGN_REMOTE_COMMITMENT_TX */ +/* Openingd/channeld asks HSM to sign the other sides' commitment tx. */ +u8 *towire_hsmd_sign_remote_commitment_tx(const tal_t *ctx, const struct bitcoin_tx *tx, const struct pubkey *remote_funding_key, const struct pubkey *remote_per_commit, bool option_static_remotekey); +bool fromwire_hsmd_sign_remote_commitment_tx(const tal_t *ctx, const void *p, struct bitcoin_tx **tx, struct pubkey *remote_funding_key, struct pubkey *remote_per_commit, bool *option_static_remotekey); + +/* WIRE: HSMD_SIGN_REMOTE_HTLC_TX */ +/* channeld asks HSM to sign remote HTLC tx. */ +u8 *towire_hsmd_sign_remote_htlc_tx(const tal_t *ctx, const struct bitcoin_tx *tx, const u8 *wscript, const struct pubkey *remote_per_commit_point, bool option_anchor_outputs); +bool fromwire_hsmd_sign_remote_htlc_tx(const tal_t *ctx, const void *p, struct bitcoin_tx **tx, u8 **wscript, struct pubkey *remote_per_commit_point, bool *option_anchor_outputs); + +/* WIRE: HSMD_SIGN_MUTUAL_CLOSE_TX */ +/* closingd asks HSM to sign mutual close tx. */ +u8 *towire_hsmd_sign_mutual_close_tx(const tal_t *ctx, const struct bitcoin_tx *tx, const struct pubkey *remote_funding_key); +bool fromwire_hsmd_sign_mutual_close_tx(const tal_t *ctx, const void *p, struct bitcoin_tx **tx, struct pubkey *remote_funding_key); + +/* WIRE: HSMD_SIGN_TX_REPLY */ +/* Reply for all the above requests. */ +u8 *towire_hsmd_sign_tx_reply(const tal_t *ctx, const struct bitcoin_signature *sig); +bool fromwire_hsmd_sign_tx_reply(const void *p, struct bitcoin_signature *sig); + +/* WIRE: HSMD_GET_PER_COMMITMENT_POINT */ +/* Openingd/channeld/onchaind asks for Nth per_commitment_point */ +u8 *towire_hsmd_get_per_commitment_point(const tal_t *ctx, u64 n); +bool fromwire_hsmd_get_per_commitment_point(const void *p, u64 *n); + +/* WIRE: HSMD_GET_PER_COMMITMENT_POINT_REPLY */ +u8 *towire_hsmd_get_per_commitment_point_reply(const tal_t *ctx, const struct pubkey *per_commitment_point, const struct secret *old_commitment_secret); +bool fromwire_hsmd_get_per_commitment_point_reply(const tal_t *ctx, const void *p, struct pubkey *per_commitment_point, struct secret **old_commitment_secret); + +/* WIRE: HSMD_DEV_MEMLEAK */ +/* master -> hsmd: do you have a memleak? */ +u8 *towire_hsmd_dev_memleak(const tal_t *ctx); +bool fromwire_hsmd_dev_memleak(const void *p); + +/* WIRE: HSMD_DEV_MEMLEAK_REPLY */ +u8 *towire_hsmd_dev_memleak_reply(const tal_t *ctx, bool leak); +bool fromwire_hsmd_dev_memleak_reply(const void *p, bool *leak); + +/* WIRE: HSMD_CHECK_FUTURE_SECRET */ +/* channeld asks to check if claimed future commitment_secret is correct. */ +u8 *towire_hsmd_check_future_secret(const tal_t *ctx, u64 n, const struct secret *commitment_secret); +bool fromwire_hsmd_check_future_secret(const void *p, u64 *n, struct secret *commitment_secret); + +/* WIRE: HSMD_CHECK_FUTURE_SECRET_REPLY */ +u8 *towire_hsmd_check_future_secret_reply(const tal_t *ctx, bool correct); +bool fromwire_hsmd_check_future_secret_reply(const void *p, bool *correct); + +/* WIRE: HSMD_SIGN_MESSAGE */ +/* lightningd asks us to sign a string. */ +u8 *towire_hsmd_sign_message(const tal_t *ctx, const u8 *msg); +bool fromwire_hsmd_sign_message(const tal_t *ctx, const void *p, u8 **msg); + +/* WIRE: HSMD_SIGN_MESSAGE_REPLY */ +u8 *towire_hsmd_sign_message_reply(const tal_t *ctx, const secp256k1_ecdsa_recoverable_signature *sig); +bool fromwire_hsmd_sign_message_reply(const void *p, secp256k1_ecdsa_recoverable_signature *sig); + +/* WIRE: HSMD_GET_OUTPUT_SCRIPTPUBKEY */ +/* lightningd needs to get a scriptPubkey for a utxo with closeinfo */ +u8 *towire_hsmd_get_output_scriptpubkey(const tal_t *ctx, u64 channel_id, const struct node_id *peer_id, const struct pubkey *commitment_point); +bool fromwire_hsmd_get_output_scriptpubkey(const tal_t *ctx, const void *p, u64 *channel_id, struct node_id *peer_id, struct pubkey **commitment_point); + +/* WIRE: HSMD_GET_OUTPUT_SCRIPTPUBKEY_REPLY */ +u8 *towire_hsmd_get_output_scriptpubkey_reply(const tal_t *ctx, const u8 *script); +bool fromwire_hsmd_get_output_scriptpubkey_reply(const tal_t *ctx, const void *p, u8 **script); + + +#endif /* LIGHTNING_HSMD_HSMD_WIREGEN_H */ + +// SHA256STAMP:exp-0-fd33f5b428d1806da30507ca94c8e34f3c7c0023ecf87c55aa2867a403d5a20c diff --git a/onchaind/onchaind_wiregen.c b/onchaind/onchaind_wiregen.c new file mode 100644 index 000000000..b1ca7d81f --- /dev/null +++ b/onchaind/onchaind_wiregen.c @@ -0,0 +1,630 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Original template can be found at tools/gen/impl_template */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef SUPERVERBOSE +#define SUPERVERBOSE(...) +#endif + + +const char *onchaind_wire_name(int e) +{ + static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; + + switch ((enum onchaind_wire)e) { + case WIRE_ONCHAIND_INIT: return "WIRE_ONCHAIND_INIT"; + case WIRE_ONCHAIND_HTLC: return "WIRE_ONCHAIND_HTLC"; + case WIRE_ONCHAIND_INIT_REPLY: return "WIRE_ONCHAIND_INIT_REPLY"; + case WIRE_ONCHAIND_BROADCAST_TX: return "WIRE_ONCHAIND_BROADCAST_TX"; + case WIRE_ONCHAIND_SPENT: return "WIRE_ONCHAIND_SPENT"; + case WIRE_ONCHAIND_DEPTH: return "WIRE_ONCHAIND_DEPTH"; + case WIRE_ONCHAIND_UNWATCH_TX: return "WIRE_ONCHAIND_UNWATCH_TX"; + case WIRE_ONCHAIND_KNOWN_PREIMAGE: return "WIRE_ONCHAIND_KNOWN_PREIMAGE"; + case WIRE_ONCHAIND_EXTRACTED_PREIMAGE: return "WIRE_ONCHAIND_EXTRACTED_PREIMAGE"; + case WIRE_ONCHAIND_MISSING_HTLC_OUTPUT: return "WIRE_ONCHAIND_MISSING_HTLC_OUTPUT"; + case WIRE_ONCHAIND_HTLC_TIMEOUT: return "WIRE_ONCHAIND_HTLC_TIMEOUT"; + case WIRE_ONCHAIND_ALL_IRREVOCABLY_RESOLVED: return "WIRE_ONCHAIND_ALL_IRREVOCABLY_RESOLVED"; + case WIRE_ONCHAIND_ADD_UTXO: return "WIRE_ONCHAIND_ADD_UTXO"; + case WIRE_ONCHAIND_DEV_MEMLEAK: return "WIRE_ONCHAIND_DEV_MEMLEAK"; + case WIRE_ONCHAIND_DEV_MEMLEAK_REPLY: return "WIRE_ONCHAIND_DEV_MEMLEAK_REPLY"; + case WIRE_ONCHAIND_ANNOTATE_TXOUT: return "WIRE_ONCHAIND_ANNOTATE_TXOUT"; + case WIRE_ONCHAIND_ANNOTATE_TXIN: return "WIRE_ONCHAIND_ANNOTATE_TXIN"; + case WIRE_ONCHAIND_NOTIFY_COIN_MVT: return "WIRE_ONCHAIND_NOTIFY_COIN_MVT"; + } + + snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); + return invalidbuf; +} + +bool onchaind_wire_is_defined(u16 type) +{ + switch ((enum onchaind_wire)type) { + case WIRE_ONCHAIND_INIT:; + case WIRE_ONCHAIND_HTLC:; + case WIRE_ONCHAIND_INIT_REPLY:; + case WIRE_ONCHAIND_BROADCAST_TX:; + case WIRE_ONCHAIND_SPENT:; + case WIRE_ONCHAIND_DEPTH:; + case WIRE_ONCHAIND_UNWATCH_TX:; + case WIRE_ONCHAIND_KNOWN_PREIMAGE:; + case WIRE_ONCHAIND_EXTRACTED_PREIMAGE:; + case WIRE_ONCHAIND_MISSING_HTLC_OUTPUT:; + case WIRE_ONCHAIND_HTLC_TIMEOUT:; + case WIRE_ONCHAIND_ALL_IRREVOCABLY_RESOLVED:; + case WIRE_ONCHAIND_ADD_UTXO:; + case WIRE_ONCHAIND_DEV_MEMLEAK:; + case WIRE_ONCHAIND_DEV_MEMLEAK_REPLY:; + case WIRE_ONCHAIND_ANNOTATE_TXOUT:; + case WIRE_ONCHAIND_ANNOTATE_TXIN:; + case WIRE_ONCHAIND_NOTIFY_COIN_MVT:; + return true; + } + return false; +} + + + + + +/* WIRE: ONCHAIND_INIT */ +/* Begin! Here's the onchain tx which spends funding tx */ +u8 *towire_onchaind_init(const tal_t *ctx, const struct shachain *shachain, const struct chainparams *chainparams, struct amount_sat funding_amount_satoshi, struct amount_msat our_msat, const struct pubkey *old_remote_per_commitment_point, const struct pubkey *remote_per_commitment_point, u32 local_to_self_delay, u32 remote_to_self_delay, u32 delayed_to_us_feerate, u32 htlc_feerate, u32 penalty_feerate, struct amount_sat local_dust_limit_satoshi, const struct bitcoin_txid *our_broadcast_txid, const u8 *local_scriptpubkey, const u8 *remote_scriptpubkey, const struct pubkey *ourwallet_pubkey, enum side opener, const struct basepoints *local_basepoints, const struct basepoints *remote_basepoints, const struct tx_parts *tx_parts, u32 locktime, u32 tx_blockheight, u32 reasonable_depth, const struct bitcoin_signature *htlc_signature, u64 num_htlcs, u32 min_possible_feerate, u32 max_possible_feerate, const struct pubkey *possible_remote_per_commit_point, const struct pubkey *local_funding_pubkey, const struct pubkey *remote_funding_pubkey, bool option_static_remotekey, bool option_anchor_outputs, bool is_replay) +{ + u16 local_scriptpubkey_len = tal_count(local_scriptpubkey); + u16 remote_scriptpubkey_len = tal_count(remote_scriptpubkey); + u16 num_htlc_sigs = tal_count(htlc_signature); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_INIT); + towire_shachain(&p, shachain); + /* This needs to be set explicitly since the same message also contains a */ + /* transaction that we need to parse correctly. */ + towire_chainparams(&p, chainparams); + towire_amount_sat(&p, funding_amount_satoshi); + /* Our current balance (of funding amount */ + towire_amount_msat(&p, our_msat); + /* Remote per commit point for committed tx. */ + towire_pubkey(&p, old_remote_per_commitment_point); + /* Remote per commit point for current tx (needed if we haven't got revoke_and_ack yet). */ + towire_pubkey(&p, remote_per_commitment_point); + towire_u32(&p, local_to_self_delay); + towire_u32(&p, remote_to_self_delay); + towire_u32(&p, delayed_to_us_feerate); + towire_u32(&p, htlc_feerate); + towire_u32(&p, penalty_feerate); + towire_amount_sat(&p, local_dust_limit_satoshi); + /* Gives an easy way to tell if it's our unilateral close or theirs... */ + towire_bitcoin_txid(&p, our_broadcast_txid); + towire_u16(&p, local_scriptpubkey_len); + towire_u8_array(&p, local_scriptpubkey, local_scriptpubkey_len); + towire_u16(&p, remote_scriptpubkey_len); + towire_u8_array(&p, remote_scriptpubkey, remote_scriptpubkey_len); + towire_pubkey(&p, ourwallet_pubkey); + /* We need these two for commit number obscurer */ + towire_side(&p, opener); + towire_basepoints(&p, local_basepoints); + towire_basepoints(&p, remote_basepoints); + towire_tx_parts(&p, tx_parts); + towire_u32(&p, locktime); + towire_u32(&p, tx_blockheight); + towire_u32(&p, reasonable_depth); + towire_u16(&p, num_htlc_sigs); + for (size_t i = 0; i < num_htlc_sigs; i++) + towire_bitcoin_signature(&p, htlc_signature + i); + towire_u64(&p, num_htlcs); + towire_u32(&p, min_possible_feerate); + towire_u32(&p, max_possible_feerate); + if (!possible_remote_per_commit_point) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_pubkey(&p, possible_remote_per_commit_point); + } + towire_pubkey(&p, local_funding_pubkey); + towire_pubkey(&p, remote_funding_pubkey); + towire_bool(&p, option_static_remotekey); + towire_bool(&p, option_anchor_outputs); + towire_bool(&p, is_replay); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_init(const tal_t *ctx, const void *p, struct shachain *shachain, const struct chainparams **chainparams, struct amount_sat *funding_amount_satoshi, struct amount_msat *our_msat, struct pubkey *old_remote_per_commitment_point, struct pubkey *remote_per_commitment_point, u32 *local_to_self_delay, u32 *remote_to_self_delay, u32 *delayed_to_us_feerate, u32 *htlc_feerate, u32 *penalty_feerate, struct amount_sat *local_dust_limit_satoshi, struct bitcoin_txid *our_broadcast_txid, u8 **local_scriptpubkey, u8 **remote_scriptpubkey, struct pubkey *ourwallet_pubkey, enum side *opener, struct basepoints *local_basepoints, struct basepoints *remote_basepoints, struct tx_parts **tx_parts, u32 *locktime, u32 *tx_blockheight, u32 *reasonable_depth, struct bitcoin_signature **htlc_signature, u64 *num_htlcs, u32 *min_possible_feerate, u32 *max_possible_feerate, struct pubkey **possible_remote_per_commit_point, struct pubkey *local_funding_pubkey, struct pubkey *remote_funding_pubkey, bool *option_static_remotekey, bool *option_anchor_outputs, bool *is_replay) +{ + u16 local_scriptpubkey_len; + u16 remote_scriptpubkey_len; + u16 num_htlc_sigs; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_INIT) + return false; + fromwire_shachain(&cursor, &plen, shachain); + /* This needs to be set explicitly since the same message also contains a */ + /* transaction that we need to parse correctly. */ + fromwire_chainparams(&cursor, &plen, chainparams); + *funding_amount_satoshi = fromwire_amount_sat(&cursor, &plen); + /* Our current balance (of funding amount */ + *our_msat = fromwire_amount_msat(&cursor, &plen); + /* Remote per commit point for committed tx. */ + fromwire_pubkey(&cursor, &plen, old_remote_per_commitment_point); + /* Remote per commit point for current tx (needed if we haven't got revoke_and_ack yet). */ + fromwire_pubkey(&cursor, &plen, remote_per_commitment_point); + *local_to_self_delay = fromwire_u32(&cursor, &plen); + *remote_to_self_delay = fromwire_u32(&cursor, &plen); + *delayed_to_us_feerate = fromwire_u32(&cursor, &plen); + *htlc_feerate = fromwire_u32(&cursor, &plen); + *penalty_feerate = fromwire_u32(&cursor, &plen); + *local_dust_limit_satoshi = fromwire_amount_sat(&cursor, &plen); + /* Gives an easy way to tell if it's our unilateral close or theirs... */ + fromwire_bitcoin_txid(&cursor, &plen, our_broadcast_txid); + local_scriptpubkey_len = fromwire_u16(&cursor, &plen); + // 2nd case local_scriptpubkey + *local_scriptpubkey = local_scriptpubkey_len ? tal_arr(ctx, u8, local_scriptpubkey_len) : NULL; + fromwire_u8_array(&cursor, &plen, *local_scriptpubkey, local_scriptpubkey_len); + remote_scriptpubkey_len = fromwire_u16(&cursor, &plen); + // 2nd case remote_scriptpubkey + *remote_scriptpubkey = remote_scriptpubkey_len ? tal_arr(ctx, u8, remote_scriptpubkey_len) : NULL; + fromwire_u8_array(&cursor, &plen, *remote_scriptpubkey, remote_scriptpubkey_len); + fromwire_pubkey(&cursor, &plen, ourwallet_pubkey); + /* We need these two for commit number obscurer */ + *opener = fromwire_side(&cursor, &plen); + fromwire_basepoints(&cursor, &plen, local_basepoints); + fromwire_basepoints(&cursor, &plen, remote_basepoints); + *tx_parts = fromwire_tx_parts(ctx, &cursor, &plen); + *locktime = fromwire_u32(&cursor, &plen); + *tx_blockheight = fromwire_u32(&cursor, &plen); + *reasonable_depth = fromwire_u32(&cursor, &plen); + num_htlc_sigs = fromwire_u16(&cursor, &plen); + // 2nd case htlc_signature + *htlc_signature = num_htlc_sigs ? tal_arr(ctx, struct bitcoin_signature, num_htlc_sigs) : NULL; + for (size_t i = 0; i < num_htlc_sigs; i++) + fromwire_bitcoin_signature(&cursor, &plen, *htlc_signature + i); + *num_htlcs = fromwire_u64(&cursor, &plen); + *min_possible_feerate = fromwire_u32(&cursor, &plen); + *max_possible_feerate = fromwire_u32(&cursor, &plen); + if (!fromwire_bool(&cursor, &plen)) + *possible_remote_per_commit_point = NULL; + else { + *possible_remote_per_commit_point = tal(ctx, struct pubkey); + fromwire_pubkey(&cursor, &plen, *possible_remote_per_commit_point); + } + fromwire_pubkey(&cursor, &plen, local_funding_pubkey); + fromwire_pubkey(&cursor, &plen, remote_funding_pubkey); + *option_static_remotekey = fromwire_bool(&cursor, &plen); + *option_anchor_outputs = fromwire_bool(&cursor, &plen); + *is_replay = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: ONCHAIND_HTLC */ +/* This is all the HTLCs: one per message */ +u8 *towire_onchaind_htlc(const tal_t *ctx, const struct htlc_stub *htlc, bool tell_if_missing, bool tell_immediately) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_HTLC); + towire_htlc_stub(&p, htlc); + /* If it's not in the commitment tx */ + towire_bool(&p, tell_if_missing); + towire_bool(&p, tell_immediately); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_htlc(const void *p, struct htlc_stub *htlc, bool *tell_if_missing, bool *tell_immediately) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_HTLC) + return false; + fromwire_htlc_stub(&cursor, &plen, htlc); + /* If it's not in the commitment tx */ + *tell_if_missing = fromwire_bool(&cursor, &plen); + *tell_immediately = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: ONCHAIND_INIT_REPLY */ +/* This says we're ready; give us preimages. */ +u8 *towire_onchaind_init_reply(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_INIT_REPLY); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_init_reply(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_INIT_REPLY) + return false; + return cursor != NULL; +} + +/* WIRE: ONCHAIND_BROADCAST_TX */ +/* onchaind->master: Send out a tx. */ +u8 *towire_onchaind_broadcast_tx(const tal_t *ctx, const struct bitcoin_tx *tx, enum wallet_tx_type type) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_BROADCAST_TX); + towire_bitcoin_tx(&p, tx); + towire_wallet_tx_type(&p, type); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_broadcast_tx(const tal_t *ctx, const void *p, struct bitcoin_tx **tx, enum wallet_tx_type *type) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_BROADCAST_TX) + return false; + *tx = fromwire_bitcoin_tx(ctx, &cursor, &plen); + *type = fromwire_wallet_tx_type(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: ONCHAIND_SPENT */ +/* master->onchaind: Notifier that an output has been spent by input_num of tx. */ +u8 *towire_onchaind_spent(const tal_t *ctx, const struct tx_parts *tx, u32 input_num, u32 blockheight, bool is_replay) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_SPENT); + towire_tx_parts(&p, tx); + towire_u32(&p, input_num); + towire_u32(&p, blockheight); + towire_bool(&p, is_replay); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_spent(const tal_t *ctx, const void *p, struct tx_parts **tx, u32 *input_num, u32 *blockheight, bool *is_replay) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_SPENT) + return false; + *tx = fromwire_tx_parts(ctx, &cursor, &plen); + *input_num = fromwire_u32(&cursor, &plen); + *blockheight = fromwire_u32(&cursor, &plen); + *is_replay = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: ONCHAIND_DEPTH */ +/* master->onchaind: We will receive more than one of these */ +u8 *towire_onchaind_depth(const tal_t *ctx, const struct bitcoin_txid *txid, u32 depth, bool is_replay) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_DEPTH); + towire_bitcoin_txid(&p, txid); + towire_u32(&p, depth); + towire_bool(&p, is_replay); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_depth(const void *p, struct bitcoin_txid *txid, u32 *depth, bool *is_replay) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_DEPTH) + return false; + fromwire_bitcoin_txid(&cursor, &plen, txid); + *depth = fromwire_u32(&cursor, &plen); + *is_replay = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: ONCHAIND_UNWATCH_TX */ +/* onchaind->master: We don't want to watch this tx */ +u8 *towire_onchaind_unwatch_tx(const tal_t *ctx, const struct bitcoin_txid *txid) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_UNWATCH_TX); + towire_bitcoin_txid(&p, txid); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_unwatch_tx(const void *p, struct bitcoin_txid *txid) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_UNWATCH_TX) + return false; + fromwire_bitcoin_txid(&cursor, &plen, txid); + return cursor != NULL; +} + +/* WIRE: ONCHAIND_KNOWN_PREIMAGE */ +/* master->onchaind: We know HTLC preimage */ +u8 *towire_onchaind_known_preimage(const tal_t *ctx, const struct preimage *preimage, bool is_replay) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_KNOWN_PREIMAGE); + towire_preimage(&p, preimage); + towire_bool(&p, is_replay); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_known_preimage(const void *p, struct preimage *preimage, bool *is_replay) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_KNOWN_PREIMAGE) + return false; + fromwire_preimage(&cursor, &plen, preimage); + *is_replay = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: ONCHAIND_EXTRACTED_PREIMAGE */ +/* onchaind->master: We discovered HTLC preimage */ +u8 *towire_onchaind_extracted_preimage(const tal_t *ctx, const struct preimage *preimage) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_EXTRACTED_PREIMAGE); + towire_preimage(&p, preimage); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_extracted_preimage(const void *p, struct preimage *preimage) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_EXTRACTED_PREIMAGE) + return false; + fromwire_preimage(&cursor, &plen, preimage); + return cursor != NULL; +} + +/* WIRE: ONCHAIND_MISSING_HTLC_OUTPUT */ +/* onchaind->master: this HTLC was missing from commit tx. */ +u8 *towire_onchaind_missing_htlc_output(const tal_t *ctx, const struct htlc_stub *htlc) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_MISSING_HTLC_OUTPUT); + towire_htlc_stub(&p, htlc); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_missing_htlc_output(const void *p, struct htlc_stub *htlc) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_MISSING_HTLC_OUTPUT) + return false; + fromwire_htlc_stub(&cursor, &plen, htlc); + return cursor != NULL; +} + +/* WIRE: ONCHAIND_HTLC_TIMEOUT */ +/* onchaind->master: this HTLC has timed out (after reasonable_depth) */ +u8 *towire_onchaind_htlc_timeout(const tal_t *ctx, const struct htlc_stub *htlc) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_HTLC_TIMEOUT); + towire_htlc_stub(&p, htlc); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_htlc_timeout(const void *p, struct htlc_stub *htlc) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_HTLC_TIMEOUT) + return false; + fromwire_htlc_stub(&cursor, &plen, htlc); + return cursor != NULL; +} + +/* WIRE: ONCHAIND_ALL_IRREVOCABLY_RESOLVED */ +/* onchaind->master: this peer can be forgotten */ +u8 *towire_onchaind_all_irrevocably_resolved(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_ALL_IRREVOCABLY_RESOLVED); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_all_irrevocably_resolved(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_ALL_IRREVOCABLY_RESOLVED) + return false; + return cursor != NULL; +} + +/* WIRE: ONCHAIND_ADD_UTXO */ +/* onchaind->master: hey */ +u8 *towire_onchaind_add_utxo(const tal_t *ctx, const struct bitcoin_txid *prev_out_tx, u32 prev_out_index, const struct pubkey *per_commit_point, struct amount_sat value, u32 blockheight, const u8 *scriptpubkey) +{ + u16 len = tal_count(scriptpubkey); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_ADD_UTXO); + towire_bitcoin_txid(&p, prev_out_tx); + towire_u32(&p, prev_out_index); + if (!per_commit_point) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_pubkey(&p, per_commit_point); + } + towire_amount_sat(&p, value); + towire_u32(&p, blockheight); + towire_u16(&p, len); + towire_u8_array(&p, scriptpubkey, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_add_utxo(const tal_t *ctx, const void *p, struct bitcoin_txid *prev_out_tx, u32 *prev_out_index, struct pubkey **per_commit_point, struct amount_sat *value, u32 *blockheight, u8 **scriptpubkey) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_ADD_UTXO) + return false; + fromwire_bitcoin_txid(&cursor, &plen, prev_out_tx); + *prev_out_index = fromwire_u32(&cursor, &plen); + if (!fromwire_bool(&cursor, &plen)) + *per_commit_point = NULL; + else { + *per_commit_point = tal(ctx, struct pubkey); + fromwire_pubkey(&cursor, &plen, *per_commit_point); + } + *value = fromwire_amount_sat(&cursor, &plen); + *blockheight = fromwire_u32(&cursor, &plen); + len = fromwire_u16(&cursor, &plen); + // 2nd case scriptpubkey + *scriptpubkey = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *scriptpubkey, len); + return cursor != NULL; +} + +/* WIRE: ONCHAIND_DEV_MEMLEAK */ +/* master -> onchaind: do you have a memleak? */ +u8 *towire_onchaind_dev_memleak(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_DEV_MEMLEAK); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_dev_memleak(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_DEV_MEMLEAK) + return false; + return cursor != NULL; +} + +/* WIRE: ONCHAIND_DEV_MEMLEAK_REPLY */ +u8 *towire_onchaind_dev_memleak_reply(const tal_t *ctx, bool leak) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_DEV_MEMLEAK_REPLY); + towire_bool(&p, leak); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_dev_memleak_reply(const void *p, bool *leak) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_DEV_MEMLEAK_REPLY) + return false; + *leak = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: ONCHAIND_ANNOTATE_TXOUT */ +/* Tell the main daemon what we've been watching */ +/* that we tracked automatically but only onchaind knows how to classify their */ +/* transactions. */ +u8 *towire_onchaind_annotate_txout(const tal_t *ctx, const struct bitcoin_txid *txid, u32 outnum, enum wallet_tx_type type) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_ANNOTATE_TXOUT); + towire_bitcoin_txid(&p, txid); + towire_u32(&p, outnum); + towire_wallet_tx_type(&p, type); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_annotate_txout(const void *p, struct bitcoin_txid *txid, u32 *outnum, enum wallet_tx_type *type) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_ANNOTATE_TXOUT) + return false; + fromwire_bitcoin_txid(&cursor, &plen, txid); + *outnum = fromwire_u32(&cursor, &plen); + *type = fromwire_wallet_tx_type(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: ONCHAIND_ANNOTATE_TXIN */ +u8 *towire_onchaind_annotate_txin(const tal_t *ctx, const struct bitcoin_txid *txid, u32 innum, enum wallet_tx_type type) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_ANNOTATE_TXIN); + towire_bitcoin_txid(&p, txid); + towire_u32(&p, innum); + towire_wallet_tx_type(&p, type); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_annotate_txin(const void *p, struct bitcoin_txid *txid, u32 *innum, enum wallet_tx_type *type) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_ANNOTATE_TXIN) + return false; + fromwire_bitcoin_txid(&cursor, &plen, txid); + *innum = fromwire_u32(&cursor, &plen); + *type = fromwire_wallet_tx_type(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: ONCHAIND_NOTIFY_COIN_MVT */ +u8 *towire_onchaind_notify_coin_mvt(const tal_t *ctx, const struct chain_coin_mvt *mvt) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONCHAIND_NOTIFY_COIN_MVT); + towire_chain_coin_mvt(&p, mvt); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onchaind_notify_coin_mvt(const void *p, struct chain_coin_mvt *mvt) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONCHAIND_NOTIFY_COIN_MVT) + return false; + fromwire_chain_coin_mvt(&cursor, &plen, mvt); + return cursor != NULL; +} + +// SHA256STAMP:exp-0-f2014a3431bb14b19ff6c2e2a273cfe07c58238052a6a18a62e413fc59d9cbf2 diff --git a/onchaind/onchaind_wiregen.h b/onchaind/onchaind_wiregen.h new file mode 100644 index 000000000..a4bde38d9 --- /dev/null +++ b/onchaind/onchaind_wiregen.h @@ -0,0 +1,159 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the _csv file it was generated from. */ +/* Original template can be found at tools/gen/header_template */ + +#ifndef LIGHTNING_ONCHAIND_ONCHAIND_WIREGEN_H +#define LIGHTNING_ONCHAIND_ONCHAIND_WIREGEN_H +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum onchaind_wire { + /* Begin! Here's the onchain tx which spends funding tx */ + WIRE_ONCHAIND_INIT = 5001, + /* This is all the HTLCs: one per message */ + WIRE_ONCHAIND_HTLC = 5002, + /* This says we're ready; give us preimages. */ + WIRE_ONCHAIND_INIT_REPLY = 5101, + /* onchaind->master: Send out a tx. */ + WIRE_ONCHAIND_BROADCAST_TX = 5003, + /* master->onchaind: Notifier that an output has been spent by input_num of tx. */ + WIRE_ONCHAIND_SPENT = 5004, + /* master->onchaind: We will receive more than one of these */ + WIRE_ONCHAIND_DEPTH = 5005, + /* onchaind->master: We don't want to watch this tx */ + WIRE_ONCHAIND_UNWATCH_TX = 5006, + /* master->onchaind: We know HTLC preimage */ + WIRE_ONCHAIND_KNOWN_PREIMAGE = 5007, + /* onchaind->master: We discovered HTLC preimage */ + WIRE_ONCHAIND_EXTRACTED_PREIMAGE = 5008, + /* onchaind->master: this HTLC was missing from commit tx. */ + WIRE_ONCHAIND_MISSING_HTLC_OUTPUT = 5009, + /* onchaind->master: this HTLC has timed out (after reasonable_depth) */ + WIRE_ONCHAIND_HTLC_TIMEOUT = 5010, + /* onchaind->master: this peer can be forgotten */ + WIRE_ONCHAIND_ALL_IRREVOCABLY_RESOLVED = 5011, + /* onchaind->master: hey */ + WIRE_ONCHAIND_ADD_UTXO = 5012, + /* master -> onchaind: do you have a memleak? */ + WIRE_ONCHAIND_DEV_MEMLEAK = 5033, + WIRE_ONCHAIND_DEV_MEMLEAK_REPLY = 5133, + /* Tell the main daemon what we've been watching */ + /* that we tracked automatically but only onchaind knows how to classify their */ + /* transactions. */ + WIRE_ONCHAIND_ANNOTATE_TXOUT = 5035, + WIRE_ONCHAIND_ANNOTATE_TXIN = 5036, + WIRE_ONCHAIND_NOTIFY_COIN_MVT = 5037, +}; + +const char *onchaind_wire_name(int e); + +/** + * Determine whether a given message type is defined as a message. + * + * Returns true if the message type is part of the message definitions we have + * generated parsers for, false if it is a custom message that cannot be + * handled internally. + */ +bool onchaind_wire_is_defined(u16 type); + + +/* WIRE: ONCHAIND_INIT */ +/* Begin! Here's the onchain tx which spends funding tx */ +u8 *towire_onchaind_init(const tal_t *ctx, const struct shachain *shachain, const struct chainparams *chainparams, struct amount_sat funding_amount_satoshi, struct amount_msat our_msat, const struct pubkey *old_remote_per_commitment_point, const struct pubkey *remote_per_commitment_point, u32 local_to_self_delay, u32 remote_to_self_delay, u32 delayed_to_us_feerate, u32 htlc_feerate, u32 penalty_feerate, struct amount_sat local_dust_limit_satoshi, const struct bitcoin_txid *our_broadcast_txid, const u8 *local_scriptpubkey, const u8 *remote_scriptpubkey, const struct pubkey *ourwallet_pubkey, enum side opener, const struct basepoints *local_basepoints, const struct basepoints *remote_basepoints, const struct tx_parts *tx_parts, u32 locktime, u32 tx_blockheight, u32 reasonable_depth, const struct bitcoin_signature *htlc_signature, u64 num_htlcs, u32 min_possible_feerate, u32 max_possible_feerate, const struct pubkey *possible_remote_per_commit_point, const struct pubkey *local_funding_pubkey, const struct pubkey *remote_funding_pubkey, bool option_static_remotekey, bool option_anchor_outputs, bool is_replay); +bool fromwire_onchaind_init(const tal_t *ctx, const void *p, struct shachain *shachain, const struct chainparams **chainparams, struct amount_sat *funding_amount_satoshi, struct amount_msat *our_msat, struct pubkey *old_remote_per_commitment_point, struct pubkey *remote_per_commitment_point, u32 *local_to_self_delay, u32 *remote_to_self_delay, u32 *delayed_to_us_feerate, u32 *htlc_feerate, u32 *penalty_feerate, struct amount_sat *local_dust_limit_satoshi, struct bitcoin_txid *our_broadcast_txid, u8 **local_scriptpubkey, u8 **remote_scriptpubkey, struct pubkey *ourwallet_pubkey, enum side *opener, struct basepoints *local_basepoints, struct basepoints *remote_basepoints, struct tx_parts **tx_parts, u32 *locktime, u32 *tx_blockheight, u32 *reasonable_depth, struct bitcoin_signature **htlc_signature, u64 *num_htlcs, u32 *min_possible_feerate, u32 *max_possible_feerate, struct pubkey **possible_remote_per_commit_point, struct pubkey *local_funding_pubkey, struct pubkey *remote_funding_pubkey, bool *option_static_remotekey, bool *option_anchor_outputs, bool *is_replay); + +/* WIRE: ONCHAIND_HTLC */ +/* This is all the HTLCs: one per message */ +u8 *towire_onchaind_htlc(const tal_t *ctx, const struct htlc_stub *htlc, bool tell_if_missing, bool tell_immediately); +bool fromwire_onchaind_htlc(const void *p, struct htlc_stub *htlc, bool *tell_if_missing, bool *tell_immediately); + +/* WIRE: ONCHAIND_INIT_REPLY */ +/* This says we're ready; give us preimages. */ +u8 *towire_onchaind_init_reply(const tal_t *ctx); +bool fromwire_onchaind_init_reply(const void *p); + +/* WIRE: ONCHAIND_BROADCAST_TX */ +/* onchaind->master: Send out a tx. */ +u8 *towire_onchaind_broadcast_tx(const tal_t *ctx, const struct bitcoin_tx *tx, enum wallet_tx_type type); +bool fromwire_onchaind_broadcast_tx(const tal_t *ctx, const void *p, struct bitcoin_tx **tx, enum wallet_tx_type *type); + +/* WIRE: ONCHAIND_SPENT */ +/* master->onchaind: Notifier that an output has been spent by input_num of tx. */ +u8 *towire_onchaind_spent(const tal_t *ctx, const struct tx_parts *tx, u32 input_num, u32 blockheight, bool is_replay); +bool fromwire_onchaind_spent(const tal_t *ctx, const void *p, struct tx_parts **tx, u32 *input_num, u32 *blockheight, bool *is_replay); + +/* WIRE: ONCHAIND_DEPTH */ +/* master->onchaind: We will receive more than one of these */ +u8 *towire_onchaind_depth(const tal_t *ctx, const struct bitcoin_txid *txid, u32 depth, bool is_replay); +bool fromwire_onchaind_depth(const void *p, struct bitcoin_txid *txid, u32 *depth, bool *is_replay); + +/* WIRE: ONCHAIND_UNWATCH_TX */ +/* onchaind->master: We don't want to watch this tx */ +u8 *towire_onchaind_unwatch_tx(const tal_t *ctx, const struct bitcoin_txid *txid); +bool fromwire_onchaind_unwatch_tx(const void *p, struct bitcoin_txid *txid); + +/* WIRE: ONCHAIND_KNOWN_PREIMAGE */ +/* master->onchaind: We know HTLC preimage */ +u8 *towire_onchaind_known_preimage(const tal_t *ctx, const struct preimage *preimage, bool is_replay); +bool fromwire_onchaind_known_preimage(const void *p, struct preimage *preimage, bool *is_replay); + +/* WIRE: ONCHAIND_EXTRACTED_PREIMAGE */ +/* onchaind->master: We discovered HTLC preimage */ +u8 *towire_onchaind_extracted_preimage(const tal_t *ctx, const struct preimage *preimage); +bool fromwire_onchaind_extracted_preimage(const void *p, struct preimage *preimage); + +/* WIRE: ONCHAIND_MISSING_HTLC_OUTPUT */ +/* onchaind->master: this HTLC was missing from commit tx. */ +u8 *towire_onchaind_missing_htlc_output(const tal_t *ctx, const struct htlc_stub *htlc); +bool fromwire_onchaind_missing_htlc_output(const void *p, struct htlc_stub *htlc); + +/* WIRE: ONCHAIND_HTLC_TIMEOUT */ +/* onchaind->master: this HTLC has timed out (after reasonable_depth) */ +u8 *towire_onchaind_htlc_timeout(const tal_t *ctx, const struct htlc_stub *htlc); +bool fromwire_onchaind_htlc_timeout(const void *p, struct htlc_stub *htlc); + +/* WIRE: ONCHAIND_ALL_IRREVOCABLY_RESOLVED */ +/* onchaind->master: this peer can be forgotten */ +u8 *towire_onchaind_all_irrevocably_resolved(const tal_t *ctx); +bool fromwire_onchaind_all_irrevocably_resolved(const void *p); + +/* WIRE: ONCHAIND_ADD_UTXO */ +/* onchaind->master: hey */ +u8 *towire_onchaind_add_utxo(const tal_t *ctx, const struct bitcoin_txid *prev_out_tx, u32 prev_out_index, const struct pubkey *per_commit_point, struct amount_sat value, u32 blockheight, const u8 *scriptpubkey); +bool fromwire_onchaind_add_utxo(const tal_t *ctx, const void *p, struct bitcoin_txid *prev_out_tx, u32 *prev_out_index, struct pubkey **per_commit_point, struct amount_sat *value, u32 *blockheight, u8 **scriptpubkey); + +/* WIRE: ONCHAIND_DEV_MEMLEAK */ +/* master -> onchaind: do you have a memleak? */ +u8 *towire_onchaind_dev_memleak(const tal_t *ctx); +bool fromwire_onchaind_dev_memleak(const void *p); + +/* WIRE: ONCHAIND_DEV_MEMLEAK_REPLY */ +u8 *towire_onchaind_dev_memleak_reply(const tal_t *ctx, bool leak); +bool fromwire_onchaind_dev_memleak_reply(const void *p, bool *leak); + +/* WIRE: ONCHAIND_ANNOTATE_TXOUT */ +/* Tell the main daemon what we've been watching */ +/* that we tracked automatically but only onchaind knows how to classify their */ +/* transactions. */ +u8 *towire_onchaind_annotate_txout(const tal_t *ctx, const struct bitcoin_txid *txid, u32 outnum, enum wallet_tx_type type); +bool fromwire_onchaind_annotate_txout(const void *p, struct bitcoin_txid *txid, u32 *outnum, enum wallet_tx_type *type); + +/* WIRE: ONCHAIND_ANNOTATE_TXIN */ +u8 *towire_onchaind_annotate_txin(const tal_t *ctx, const struct bitcoin_txid *txid, u32 innum, enum wallet_tx_type type); +bool fromwire_onchaind_annotate_txin(const void *p, struct bitcoin_txid *txid, u32 *innum, enum wallet_tx_type *type); + +/* WIRE: ONCHAIND_NOTIFY_COIN_MVT */ +u8 *towire_onchaind_notify_coin_mvt(const tal_t *ctx, const struct chain_coin_mvt *mvt); +bool fromwire_onchaind_notify_coin_mvt(const void *p, struct chain_coin_mvt *mvt); + + +#endif /* LIGHTNING_ONCHAIND_ONCHAIND_WIREGEN_H */ + +// SHA256STAMP:exp-0-f2014a3431bb14b19ff6c2e2a273cfe07c58238052a6a18a62e413fc59d9cbf2 diff --git a/openingd/openingd_wiregen.c b/openingd/openingd_wiregen.c new file mode 100644 index 000000000..8e91b2e88 --- /dev/null +++ b/openingd/openingd_wiregen.c @@ -0,0 +1,583 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Original template can be found at tools/gen/impl_template */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef SUPERVERBOSE +#define SUPERVERBOSE(...) +#endif + + +const char *openingd_wire_name(int e) +{ + static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; + + switch ((enum openingd_wire)e) { + case WIRE_OPENINGD_INIT: return "WIRE_OPENINGD_INIT"; + case WIRE_OPENINGD_GOT_OFFER: return "WIRE_OPENINGD_GOT_OFFER"; + case WIRE_OPENINGD_GOT_OFFER_REPLY: return "WIRE_OPENINGD_GOT_OFFER_REPLY"; + case WIRE_OPENINGD_FUNDER_REPLY: return "WIRE_OPENINGD_FUNDER_REPLY"; + case WIRE_OPENINGD_FUNDER_START: return "WIRE_OPENINGD_FUNDER_START"; + case WIRE_OPENINGD_FUNDER_START_REPLY: return "WIRE_OPENINGD_FUNDER_START_REPLY"; + case WIRE_OPENINGD_FUNDER_COMPLETE: return "WIRE_OPENINGD_FUNDER_COMPLETE"; + case WIRE_OPENINGD_FUNDER_CANCEL: return "WIRE_OPENINGD_FUNDER_CANCEL"; + case WIRE_OPENINGD_FUNDER_FAILED: return "WIRE_OPENINGD_FUNDER_FAILED"; + case WIRE_OPENINGD_FUNDEE: return "WIRE_OPENINGD_FUNDEE"; + case WIRE_OPENINGD_DEV_MEMLEAK: return "WIRE_OPENINGD_DEV_MEMLEAK"; + case WIRE_OPENINGD_DEV_MEMLEAK_REPLY: return "WIRE_OPENINGD_DEV_MEMLEAK_REPLY"; + } + + snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); + return invalidbuf; +} + +bool openingd_wire_is_defined(u16 type) +{ + switch ((enum openingd_wire)type) { + case WIRE_OPENINGD_INIT:; + case WIRE_OPENINGD_GOT_OFFER:; + case WIRE_OPENINGD_GOT_OFFER_REPLY:; + case WIRE_OPENINGD_FUNDER_REPLY:; + case WIRE_OPENINGD_FUNDER_START:; + case WIRE_OPENINGD_FUNDER_START_REPLY:; + case WIRE_OPENINGD_FUNDER_COMPLETE:; + case WIRE_OPENINGD_FUNDER_CANCEL:; + case WIRE_OPENINGD_FUNDER_FAILED:; + case WIRE_OPENINGD_FUNDEE:; + case WIRE_OPENINGD_DEV_MEMLEAK:; + case WIRE_OPENINGD_DEV_MEMLEAK_REPLY:; + return true; + } + return false; +} + + + + + +/* WIRE: OPENINGD_INIT */ +u8 *towire_openingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct channel_config *our_config, u32 max_to_self_delay, struct amount_msat min_effective_htlc_capacity_msat, const struct per_peer_state *pps, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, u32 minimum_depth, u32 min_feerate, u32 max_feerate, const u8 *lfeatures, bool option_static_remotekey, bool option_anchor_outputs, const u8 *msg, const struct channel_id *dev_temporary_channel_id, bool dev_fast_gossip) +{ + u16 lfeatures_len = tal_count(lfeatures); + u16 len = tal_count(msg); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_OPENINGD_INIT); + /* Which network are we configured for? */ + towire_chainparams(&p, chainparams); + towire_feature_set(&p, our_features); + /* Base configuration we'll offer (channel reserve will vary with amount) */ + towire_channel_config(&p, our_config); + /* Minimum/maximum configuration values we'll accept */ + towire_u32(&p, max_to_self_delay); + towire_amount_msat(&p, min_effective_htlc_capacity_msat); + towire_per_peer_state(&p, pps); + towire_basepoints(&p, our_basepoints); + towire_pubkey(&p, our_funding_pubkey); + /* Constraints in case the other end tries to open a channel. */ + towire_u32(&p, minimum_depth); + towire_u32(&p, min_feerate); + towire_u32(&p, max_feerate); + towire_u16(&p, lfeatures_len); + towire_u8_array(&p, lfeatures, lfeatures_len); + towire_bool(&p, option_static_remotekey); + towire_bool(&p, option_anchor_outputs); + /* Optional msg to send. */ + towire_u16(&p, len); + towire_u8_array(&p, msg, len); + if (!dev_temporary_channel_id) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_channel_id(&p, dev_temporary_channel_id); + } + towire_bool(&p, dev_fast_gossip); + + return memcheck(p, tal_count(p)); +} +bool fromwire_openingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct channel_config *our_config, u32 *max_to_self_delay, struct amount_msat *min_effective_htlc_capacity_msat, struct per_peer_state **pps, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, u32 *minimum_depth, u32 *min_feerate, u32 *max_feerate, u8 **lfeatures, bool *option_static_remotekey, bool *option_anchor_outputs, u8 **msg, struct channel_id **dev_temporary_channel_id, bool *dev_fast_gossip) +{ + u16 lfeatures_len; + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_OPENINGD_INIT) + return false; + /* Which network are we configured for? */ + fromwire_chainparams(&cursor, &plen, chainparams); + *our_features = fromwire_feature_set(ctx, &cursor, &plen); + /* Base configuration we'll offer (channel reserve will vary with amount) */ + fromwire_channel_config(&cursor, &plen, our_config); + /* Minimum/maximum configuration values we'll accept */ + *max_to_self_delay = fromwire_u32(&cursor, &plen); + *min_effective_htlc_capacity_msat = fromwire_amount_msat(&cursor, &plen); + *pps = fromwire_per_peer_state(ctx, &cursor, &plen); + fromwire_basepoints(&cursor, &plen, our_basepoints); + fromwire_pubkey(&cursor, &plen, our_funding_pubkey); + /* Constraints in case the other end tries to open a channel. */ + *minimum_depth = fromwire_u32(&cursor, &plen); + *min_feerate = fromwire_u32(&cursor, &plen); + *max_feerate = fromwire_u32(&cursor, &plen); + lfeatures_len = fromwire_u16(&cursor, &plen); + // 2nd case lfeatures + *lfeatures = lfeatures_len ? tal_arr(ctx, u8, lfeatures_len) : NULL; + fromwire_u8_array(&cursor, &plen, *lfeatures, lfeatures_len); + *option_static_remotekey = fromwire_bool(&cursor, &plen); + *option_anchor_outputs = fromwire_bool(&cursor, &plen); + /* Optional msg to send. */ + len = fromwire_u16(&cursor, &plen); + // 2nd case msg + *msg = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *msg, len); + if (!fromwire_bool(&cursor, &plen)) + *dev_temporary_channel_id = NULL; + else { + *dev_temporary_channel_id = tal(ctx, struct channel_id); + fromwire_channel_id(&cursor, &plen, *dev_temporary_channel_id); + } + *dev_fast_gossip = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: OPENINGD_GOT_OFFER */ +/* Openingd->master: they offered channel */ +u8 *towire_openingd_got_offer(const tal_t *ctx, struct amount_sat funding_satoshis, struct amount_msat push_msat, struct amount_sat dust_limit_satoshis, struct amount_msat max_htlc_value_in_flight_msat, struct amount_sat channel_reserve_satoshis, struct amount_msat htlc_minimum_msat, u32 feerate_per_kw, u16 to_self_delay, u16 max_accepted_htlcs, u8 channel_flags, const u8 *shutdown_scriptpubkey) +{ + u16 shutdown_len = tal_count(shutdown_scriptpubkey); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_OPENINGD_GOT_OFFER); + towire_amount_sat(&p, funding_satoshis); + towire_amount_msat(&p, push_msat); + towire_amount_sat(&p, dust_limit_satoshis); + towire_amount_msat(&p, max_htlc_value_in_flight_msat); + towire_amount_sat(&p, channel_reserve_satoshis); + towire_amount_msat(&p, htlc_minimum_msat); + towire_u32(&p, feerate_per_kw); + towire_u16(&p, to_self_delay); + towire_u16(&p, max_accepted_htlcs); + towire_u8(&p, channel_flags); + towire_u16(&p, shutdown_len); + towire_u8_array(&p, shutdown_scriptpubkey, shutdown_len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_openingd_got_offer(const tal_t *ctx, const void *p, struct amount_sat *funding_satoshis, struct amount_msat *push_msat, struct amount_sat *dust_limit_satoshis, struct amount_msat *max_htlc_value_in_flight_msat, struct amount_sat *channel_reserve_satoshis, struct amount_msat *htlc_minimum_msat, u32 *feerate_per_kw, u16 *to_self_delay, u16 *max_accepted_htlcs, u8 *channel_flags, u8 **shutdown_scriptpubkey) +{ + u16 shutdown_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_OPENINGD_GOT_OFFER) + return false; + *funding_satoshis = fromwire_amount_sat(&cursor, &plen); + *push_msat = fromwire_amount_msat(&cursor, &plen); + *dust_limit_satoshis = fromwire_amount_sat(&cursor, &plen); + *max_htlc_value_in_flight_msat = fromwire_amount_msat(&cursor, &plen); + *channel_reserve_satoshis = fromwire_amount_sat(&cursor, &plen); + *htlc_minimum_msat = fromwire_amount_msat(&cursor, &plen); + *feerate_per_kw = fromwire_u32(&cursor, &plen); + *to_self_delay = fromwire_u16(&cursor, &plen); + *max_accepted_htlcs = fromwire_u16(&cursor, &plen); + *channel_flags = fromwire_u8(&cursor, &plen); + shutdown_len = fromwire_u16(&cursor, &plen); + // 2nd case shutdown_scriptpubkey + *shutdown_scriptpubkey = shutdown_len ? tal_arr(ctx, u8, shutdown_len) : NULL; + fromwire_u8_array(&cursor, &plen, *shutdown_scriptpubkey, shutdown_len); + return cursor != NULL; +} + +/* WIRE: OPENINGD_GOT_OFFER_REPLY */ +/* master->openingd: optional rejection message */ +u8 *towire_openingd_got_offer_reply(const tal_t *ctx, const wirestring *rejection, const u8 *our_shutdown_scriptpubkey) +{ + u16 shutdown_len = tal_count(our_shutdown_scriptpubkey); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_OPENINGD_GOT_OFFER_REPLY); + if (!rejection) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_wirestring(&p, rejection); + } + towire_u16(&p, shutdown_len); + towire_u8_array(&p, our_shutdown_scriptpubkey, shutdown_len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_openingd_got_offer_reply(const tal_t *ctx, const void *p, wirestring **rejection, u8 **our_shutdown_scriptpubkey) +{ + u16 shutdown_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_OPENINGD_GOT_OFFER_REPLY) + return false; + if (!fromwire_bool(&cursor, &plen)) + *rejection = NULL; + else { + *rejection = fromwire_wirestring(ctx, &cursor, &plen); + } + shutdown_len = fromwire_u16(&cursor, &plen); + // 2nd case our_shutdown_scriptpubkey + *our_shutdown_scriptpubkey = shutdown_len ? tal_arr(ctx, u8, shutdown_len) : NULL; + fromwire_u8_array(&cursor, &plen, *our_shutdown_scriptpubkey, shutdown_len); + return cursor != NULL; +} + +/* WIRE: OPENINGD_FUNDER_REPLY */ +/* Openingd->master: we've successfully offered channel. */ +/* This gives their sig */ +u8 *towire_openingd_funder_reply(const tal_t *ctx, const struct channel_config *their_config, const struct bitcoin_tx *first_commit, const struct penalty_base *pbase, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *pps, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *their_per_commit_point, u32 minimum_depth, const struct pubkey *remote_fundingkey, const struct bitcoin_txid *funding_txid, u16 funding_txout, u32 feerate_per_kw, struct amount_sat our_channel_reserve_satoshis, const u8 *shutdown_scriptpubkey) +{ + u16 shutdown_len = tal_count(shutdown_scriptpubkey); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_OPENINGD_FUNDER_REPLY); + towire_channel_config(&p, their_config); + towire_bitcoin_tx(&p, first_commit); + if (!pbase) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_penalty_base(&p, pbase); + } + towire_bitcoin_signature(&p, first_commit_sig); + towire_per_peer_state(&p, pps); + towire_pubkey(&p, revocation_basepoint); + towire_pubkey(&p, payment_basepoint); + towire_pubkey(&p, htlc_basepoint); + towire_pubkey(&p, delayed_payment_basepoint); + towire_pubkey(&p, their_per_commit_point); + towire_u32(&p, minimum_depth); + towire_pubkey(&p, remote_fundingkey); + towire_bitcoin_txid(&p, funding_txid); + towire_u16(&p, funding_txout); + towire_u32(&p, feerate_per_kw); + towire_amount_sat(&p, our_channel_reserve_satoshis); + towire_u16(&p, shutdown_len); + towire_u8_array(&p, shutdown_scriptpubkey, shutdown_len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_openingd_funder_reply(const tal_t *ctx, const void *p, struct channel_config *their_config, struct bitcoin_tx **first_commit, struct penalty_base **pbase, struct bitcoin_signature *first_commit_sig, struct per_peer_state **pps, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *their_per_commit_point, u32 *minimum_depth, struct pubkey *remote_fundingkey, struct bitcoin_txid *funding_txid, u16 *funding_txout, u32 *feerate_per_kw, struct amount_sat *our_channel_reserve_satoshis, u8 **shutdown_scriptpubkey) +{ + u16 shutdown_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_OPENINGD_FUNDER_REPLY) + return false; + fromwire_channel_config(&cursor, &plen, their_config); + *first_commit = fromwire_bitcoin_tx(ctx, &cursor, &plen); + if (!fromwire_bool(&cursor, &plen)) + *pbase = NULL; + else { + *pbase = tal(ctx, struct penalty_base); + fromwire_penalty_base(&cursor, &plen, *pbase); + } + fromwire_bitcoin_signature(&cursor, &plen, first_commit_sig); + *pps = fromwire_per_peer_state(ctx, &cursor, &plen); + fromwire_pubkey(&cursor, &plen, revocation_basepoint); + fromwire_pubkey(&cursor, &plen, payment_basepoint); + fromwire_pubkey(&cursor, &plen, htlc_basepoint); + fromwire_pubkey(&cursor, &plen, delayed_payment_basepoint); + fromwire_pubkey(&cursor, &plen, their_per_commit_point); + *minimum_depth = fromwire_u32(&cursor, &plen); + fromwire_pubkey(&cursor, &plen, remote_fundingkey); + fromwire_bitcoin_txid(&cursor, &plen, funding_txid); + *funding_txout = fromwire_u16(&cursor, &plen); + *feerate_per_kw = fromwire_u32(&cursor, &plen); + *our_channel_reserve_satoshis = fromwire_amount_sat(&cursor, &plen); + shutdown_len = fromwire_u16(&cursor, &plen); + // 2nd case shutdown_scriptpubkey + *shutdown_scriptpubkey = shutdown_len ? tal_arr(ctx, u8, shutdown_len) : NULL; + fromwire_u8_array(&cursor, &plen, *shutdown_scriptpubkey, shutdown_len); + return cursor != NULL; +} + +/* WIRE: OPENINGD_FUNDER_START */ +/* master->openingd: start channel establishment for a funding tx */ +u8 *towire_openingd_funder_start(const tal_t *ctx, struct amount_sat funding_satoshis, struct amount_msat push_msat, const u8 *upfront_shutdown_script, u32 feerate_per_kw, u8 channel_flags) +{ + u16 len_upfront = tal_count(upfront_shutdown_script); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_OPENINGD_FUNDER_START); + towire_amount_sat(&p, funding_satoshis); + towire_amount_msat(&p, push_msat); + towire_u16(&p, len_upfront); + towire_u8_array(&p, upfront_shutdown_script, len_upfront); + towire_u32(&p, feerate_per_kw); + towire_u8(&p, channel_flags); + + return memcheck(p, tal_count(p)); +} +bool fromwire_openingd_funder_start(const tal_t *ctx, const void *p, struct amount_sat *funding_satoshis, struct amount_msat *push_msat, u8 **upfront_shutdown_script, u32 *feerate_per_kw, u8 *channel_flags) +{ + u16 len_upfront; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_OPENINGD_FUNDER_START) + return false; + *funding_satoshis = fromwire_amount_sat(&cursor, &plen); + *push_msat = fromwire_amount_msat(&cursor, &plen); + len_upfront = fromwire_u16(&cursor, &plen); + // 2nd case upfront_shutdown_script + *upfront_shutdown_script = len_upfront ? tal_arr(ctx, u8, len_upfront) : NULL; + fromwire_u8_array(&cursor, &plen, *upfront_shutdown_script, len_upfront); + *feerate_per_kw = fromwire_u32(&cursor, &plen); + *channel_flags = fromwire_u8(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: OPENINGD_FUNDER_START_REPLY */ +/* openingd->master: send back output script for 2-of-2 funding output */ +u8 *towire_openingd_funder_start_reply(const tal_t *ctx, const u8 *scriptpubkey, bool upfront_shutdown_negotiated) +{ + u8 script_len = tal_count(scriptpubkey); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_OPENINGD_FUNDER_START_REPLY); + towire_u8(&p, script_len); + towire_u8_array(&p, scriptpubkey, script_len); + towire_bool(&p, upfront_shutdown_negotiated); + + return memcheck(p, tal_count(p)); +} +bool fromwire_openingd_funder_start_reply(const tal_t *ctx, const void *p, u8 **scriptpubkey, bool *upfront_shutdown_negotiated) +{ + u8 script_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_OPENINGD_FUNDER_START_REPLY) + return false; + script_len = fromwire_u8(&cursor, &plen); + // 2nd case scriptpubkey + *scriptpubkey = script_len ? tal_arr(ctx, u8, script_len) : NULL; + fromwire_u8_array(&cursor, &plen, *scriptpubkey, script_len); + *upfront_shutdown_negotiated = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: OPENINGD_FUNDER_COMPLETE */ +/* master->openingd: complete channel establishment for a funding */ +/* tx that will be paid for by an external wallet */ +/* response to this is a normal `openingd_funder_reply` ?? */ +u8 *towire_openingd_funder_complete(const tal_t *ctx, const struct bitcoin_txid *funding_txid, u16 funding_txout) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_OPENINGD_FUNDER_COMPLETE); + towire_bitcoin_txid(&p, funding_txid); + towire_u16(&p, funding_txout); + + return memcheck(p, tal_count(p)); +} +bool fromwire_openingd_funder_complete(const void *p, struct bitcoin_txid *funding_txid, u16 *funding_txout) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_OPENINGD_FUNDER_COMPLETE) + return false; + fromwire_bitcoin_txid(&cursor, &plen, funding_txid); + *funding_txout = fromwire_u16(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: OPENINGD_FUNDER_CANCEL */ +/*master->openingd: cancel channel establishment for a funding */ +u8 *towire_openingd_funder_cancel(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_OPENINGD_FUNDER_CANCEL); + + return memcheck(p, tal_count(p)); +} +bool fromwire_openingd_funder_cancel(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_OPENINGD_FUNDER_CANCEL) + return false; + return cursor != NULL; +} + +/* WIRE: OPENINGD_FUNDER_FAILED */ +/* Openingd->master: we failed to negotiation channel */ +u8 *towire_openingd_funder_failed(const tal_t *ctx, const wirestring *reason) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_OPENINGD_FUNDER_FAILED); + towire_wirestring(&p, reason); + + return memcheck(p, tal_count(p)); +} +bool fromwire_openingd_funder_failed(const tal_t *ctx, const void *p, wirestring **reason) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_OPENINGD_FUNDER_FAILED) + return false; + *reason = fromwire_wirestring(ctx, &cursor, &plen); + return cursor != NULL; +} + +/* WIRE: OPENINGD_FUNDEE */ +/* Openingd->master: they offered channel. */ +/* This gives their txid and info */ +u8 *towire_openingd_fundee(const tal_t *ctx, const struct channel_config *their_config, const struct bitcoin_tx *first_commit, const struct penalty_base *pbase, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *pps, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *their_per_commit_point, const struct pubkey *remote_fundingkey, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshis, struct amount_msat push_msat, u8 channel_flags, u32 feerate_per_kw, const u8 *funding_signed_msg, struct amount_sat our_channel_reserve_satoshis, const u8 *local_shutdown_scriptpubkey, const u8 *remote_shutdown_scriptpubkey) +{ + u16 msglen = tal_count(funding_signed_msg); + u16 local_shutdown_len = tal_count(local_shutdown_scriptpubkey); + u16 remote_shutdown_len = tal_count(remote_shutdown_scriptpubkey); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_OPENINGD_FUNDEE); + towire_channel_config(&p, their_config); + towire_bitcoin_tx(&p, first_commit); + if (!pbase) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_penalty_base(&p, pbase); + } + towire_bitcoin_signature(&p, first_commit_sig); + towire_per_peer_state(&p, pps); + towire_pubkey(&p, revocation_basepoint); + towire_pubkey(&p, payment_basepoint); + towire_pubkey(&p, htlc_basepoint); + towire_pubkey(&p, delayed_payment_basepoint); + towire_pubkey(&p, their_per_commit_point); + towire_pubkey(&p, remote_fundingkey); + towire_bitcoin_txid(&p, funding_txid); + towire_u16(&p, funding_txout); + towire_amount_sat(&p, funding_satoshis); + towire_amount_msat(&p, push_msat); + towire_u8(&p, channel_flags); + towire_u32(&p, feerate_per_kw); + /* The funding signed message: send this and we're committed. */ + towire_u16(&p, msglen); + towire_u8_array(&p, funding_signed_msg, msglen); + towire_amount_sat(&p, our_channel_reserve_satoshis); + towire_u16(&p, local_shutdown_len); + towire_u8_array(&p, local_shutdown_scriptpubkey, local_shutdown_len); + towire_u16(&p, remote_shutdown_len); + towire_u8_array(&p, remote_shutdown_scriptpubkey, remote_shutdown_len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_openingd_fundee(const tal_t *ctx, const void *p, struct channel_config *their_config, struct bitcoin_tx **first_commit, struct penalty_base **pbase, struct bitcoin_signature *first_commit_sig, struct per_peer_state **pps, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *their_per_commit_point, struct pubkey *remote_fundingkey, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshis, struct amount_msat *push_msat, u8 *channel_flags, u32 *feerate_per_kw, u8 **funding_signed_msg, struct amount_sat *our_channel_reserve_satoshis, u8 **local_shutdown_scriptpubkey, u8 **remote_shutdown_scriptpubkey) +{ + u16 msglen; + u16 local_shutdown_len; + u16 remote_shutdown_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_OPENINGD_FUNDEE) + return false; + fromwire_channel_config(&cursor, &plen, their_config); + *first_commit = fromwire_bitcoin_tx(ctx, &cursor, &plen); + if (!fromwire_bool(&cursor, &plen)) + *pbase = NULL; + else { + *pbase = tal(ctx, struct penalty_base); + fromwire_penalty_base(&cursor, &plen, *pbase); + } + fromwire_bitcoin_signature(&cursor, &plen, first_commit_sig); + *pps = fromwire_per_peer_state(ctx, &cursor, &plen); + fromwire_pubkey(&cursor, &plen, revocation_basepoint); + fromwire_pubkey(&cursor, &plen, payment_basepoint); + fromwire_pubkey(&cursor, &plen, htlc_basepoint); + fromwire_pubkey(&cursor, &plen, delayed_payment_basepoint); + fromwire_pubkey(&cursor, &plen, their_per_commit_point); + fromwire_pubkey(&cursor, &plen, remote_fundingkey); + fromwire_bitcoin_txid(&cursor, &plen, funding_txid); + *funding_txout = fromwire_u16(&cursor, &plen); + *funding_satoshis = fromwire_amount_sat(&cursor, &plen); + *push_msat = fromwire_amount_msat(&cursor, &plen); + *channel_flags = fromwire_u8(&cursor, &plen); + *feerate_per_kw = fromwire_u32(&cursor, &plen); + /* The funding signed message: send this and we're committed. */ + msglen = fromwire_u16(&cursor, &plen); + // 2nd case funding_signed_msg + *funding_signed_msg = msglen ? tal_arr(ctx, u8, msglen) : NULL; + fromwire_u8_array(&cursor, &plen, *funding_signed_msg, msglen); + *our_channel_reserve_satoshis = fromwire_amount_sat(&cursor, &plen); + local_shutdown_len = fromwire_u16(&cursor, &plen); + // 2nd case local_shutdown_scriptpubkey + *local_shutdown_scriptpubkey = local_shutdown_len ? tal_arr(ctx, u8, local_shutdown_len) : NULL; + fromwire_u8_array(&cursor, &plen, *local_shutdown_scriptpubkey, local_shutdown_len); + remote_shutdown_len = fromwire_u16(&cursor, &plen); + // 2nd case remote_shutdown_scriptpubkey + *remote_shutdown_scriptpubkey = remote_shutdown_len ? tal_arr(ctx, u8, remote_shutdown_len) : NULL; + fromwire_u8_array(&cursor, &plen, *remote_shutdown_scriptpubkey, remote_shutdown_len); + return cursor != NULL; +} + +/* WIRE: OPENINGD_DEV_MEMLEAK */ +/* master -> openingd: do you have a memleak? */ +u8 *towire_openingd_dev_memleak(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_OPENINGD_DEV_MEMLEAK); + + return memcheck(p, tal_count(p)); +} +bool fromwire_openingd_dev_memleak(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_OPENINGD_DEV_MEMLEAK) + return false; + return cursor != NULL; +} + +/* WIRE: OPENINGD_DEV_MEMLEAK_REPLY */ +u8 *towire_openingd_dev_memleak_reply(const tal_t *ctx, bool leak) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_OPENINGD_DEV_MEMLEAK_REPLY); + towire_bool(&p, leak); + + return memcheck(p, tal_count(p)); +} +bool fromwire_openingd_dev_memleak_reply(const void *p, bool *leak) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_OPENINGD_DEV_MEMLEAK_REPLY) + return false; + *leak = fromwire_bool(&cursor, &plen); + return cursor != NULL; +} + +// SHA256STAMP:exp-0-a51533cda64c44739e86c8c93cc8f70d5f24b6c7ddb1f5b06684c4b35f58f501 diff --git a/openingd/openingd_wiregen.h b/openingd/openingd_wiregen.h new file mode 100644 index 000000000..13a9f0b6b --- /dev/null +++ b/openingd/openingd_wiregen.h @@ -0,0 +1,125 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the _csv file it was generated from. */ +/* Original template can be found at tools/gen/header_template */ + +#ifndef LIGHTNING_OPENINGD_OPENINGD_WIREGEN_H +#define LIGHTNING_OPENINGD_OPENINGD_WIREGEN_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum openingd_wire { + WIRE_OPENINGD_INIT = 6000, + /* Openingd->master: they offered channel */ + WIRE_OPENINGD_GOT_OFFER = 6005, + /* master->openingd: optional rejection message */ + WIRE_OPENINGD_GOT_OFFER_REPLY = 6105, + /* Openingd->master: we've successfully offered channel. */ + /* This gives their sig */ + WIRE_OPENINGD_FUNDER_REPLY = 6101, + /* master->openingd: start channel establishment for a funding tx */ + WIRE_OPENINGD_FUNDER_START = 6002, + /* openingd->master: send back output script for 2-of-2 funding output */ + WIRE_OPENINGD_FUNDER_START_REPLY = 6102, + /* master->openingd: complete channel establishment for a funding */ + /* tx that will be paid for by an external wallet */ + /* response to this is a normal `openingd_funder_reply` ?? */ + WIRE_OPENINGD_FUNDER_COMPLETE = 6012, + /* master->openingd: cancel channel establishment for a funding */ + WIRE_OPENINGD_FUNDER_CANCEL = 6013, + /* Openingd->master: we failed to negotiation channel */ + WIRE_OPENINGD_FUNDER_FAILED = 6004, + /* Openingd->master: they offered channel. */ + /* This gives their txid and info */ + WIRE_OPENINGD_FUNDEE = 6003, + /* master -> openingd: do you have a memleak? */ + WIRE_OPENINGD_DEV_MEMLEAK = 6033, + WIRE_OPENINGD_DEV_MEMLEAK_REPLY = 6133, +}; + +const char *openingd_wire_name(int e); + +/** + * Determine whether a given message type is defined as a message. + * + * Returns true if the message type is part of the message definitions we have + * generated parsers for, false if it is a custom message that cannot be + * handled internally. + */ +bool openingd_wire_is_defined(u16 type); + + +/* WIRE: OPENINGD_INIT */ +u8 *towire_openingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct channel_config *our_config, u32 max_to_self_delay, struct amount_msat min_effective_htlc_capacity_msat, const struct per_peer_state *pps, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, u32 minimum_depth, u32 min_feerate, u32 max_feerate, const u8 *lfeatures, bool option_static_remotekey, bool option_anchor_outputs, const u8 *msg, const struct channel_id *dev_temporary_channel_id, bool dev_fast_gossip); +bool fromwire_openingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct channel_config *our_config, u32 *max_to_self_delay, struct amount_msat *min_effective_htlc_capacity_msat, struct per_peer_state **pps, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, u32 *minimum_depth, u32 *min_feerate, u32 *max_feerate, u8 **lfeatures, bool *option_static_remotekey, bool *option_anchor_outputs, u8 **msg, struct channel_id **dev_temporary_channel_id, bool *dev_fast_gossip); + +/* WIRE: OPENINGD_GOT_OFFER */ +/* Openingd->master: they offered channel */ +u8 *towire_openingd_got_offer(const tal_t *ctx, struct amount_sat funding_satoshis, struct amount_msat push_msat, struct amount_sat dust_limit_satoshis, struct amount_msat max_htlc_value_in_flight_msat, struct amount_sat channel_reserve_satoshis, struct amount_msat htlc_minimum_msat, u32 feerate_per_kw, u16 to_self_delay, u16 max_accepted_htlcs, u8 channel_flags, const u8 *shutdown_scriptpubkey); +bool fromwire_openingd_got_offer(const tal_t *ctx, const void *p, struct amount_sat *funding_satoshis, struct amount_msat *push_msat, struct amount_sat *dust_limit_satoshis, struct amount_msat *max_htlc_value_in_flight_msat, struct amount_sat *channel_reserve_satoshis, struct amount_msat *htlc_minimum_msat, u32 *feerate_per_kw, u16 *to_self_delay, u16 *max_accepted_htlcs, u8 *channel_flags, u8 **shutdown_scriptpubkey); + +/* WIRE: OPENINGD_GOT_OFFER_REPLY */ +/* master->openingd: optional rejection message */ +u8 *towire_openingd_got_offer_reply(const tal_t *ctx, const wirestring *rejection, const u8 *our_shutdown_scriptpubkey); +bool fromwire_openingd_got_offer_reply(const tal_t *ctx, const void *p, wirestring **rejection, u8 **our_shutdown_scriptpubkey); + +/* WIRE: OPENINGD_FUNDER_REPLY */ +/* Openingd->master: we've successfully offered channel. */ +/* This gives their sig */ +u8 *towire_openingd_funder_reply(const tal_t *ctx, const struct channel_config *their_config, const struct bitcoin_tx *first_commit, const struct penalty_base *pbase, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *pps, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *their_per_commit_point, u32 minimum_depth, const struct pubkey *remote_fundingkey, const struct bitcoin_txid *funding_txid, u16 funding_txout, u32 feerate_per_kw, struct amount_sat our_channel_reserve_satoshis, const u8 *shutdown_scriptpubkey); +bool fromwire_openingd_funder_reply(const tal_t *ctx, const void *p, struct channel_config *their_config, struct bitcoin_tx **first_commit, struct penalty_base **pbase, struct bitcoin_signature *first_commit_sig, struct per_peer_state **pps, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *their_per_commit_point, u32 *minimum_depth, struct pubkey *remote_fundingkey, struct bitcoin_txid *funding_txid, u16 *funding_txout, u32 *feerate_per_kw, struct amount_sat *our_channel_reserve_satoshis, u8 **shutdown_scriptpubkey); + +/* WIRE: OPENINGD_FUNDER_START */ +/* master->openingd: start channel establishment for a funding tx */ +u8 *towire_openingd_funder_start(const tal_t *ctx, struct amount_sat funding_satoshis, struct amount_msat push_msat, const u8 *upfront_shutdown_script, u32 feerate_per_kw, u8 channel_flags); +bool fromwire_openingd_funder_start(const tal_t *ctx, const void *p, struct amount_sat *funding_satoshis, struct amount_msat *push_msat, u8 **upfront_shutdown_script, u32 *feerate_per_kw, u8 *channel_flags); + +/* WIRE: OPENINGD_FUNDER_START_REPLY */ +/* openingd->master: send back output script for 2-of-2 funding output */ +u8 *towire_openingd_funder_start_reply(const tal_t *ctx, const u8 *scriptpubkey, bool upfront_shutdown_negotiated); +bool fromwire_openingd_funder_start_reply(const tal_t *ctx, const void *p, u8 **scriptpubkey, bool *upfront_shutdown_negotiated); + +/* WIRE: OPENINGD_FUNDER_COMPLETE */ +/* master->openingd: complete channel establishment for a funding */ +/* tx that will be paid for by an external wallet */ +/* response to this is a normal `openingd_funder_reply` ?? */ +u8 *towire_openingd_funder_complete(const tal_t *ctx, const struct bitcoin_txid *funding_txid, u16 funding_txout); +bool fromwire_openingd_funder_complete(const void *p, struct bitcoin_txid *funding_txid, u16 *funding_txout); + +/* WIRE: OPENINGD_FUNDER_CANCEL */ +/* master->openingd: cancel channel establishment for a funding */ +u8 *towire_openingd_funder_cancel(const tal_t *ctx); +bool fromwire_openingd_funder_cancel(const void *p); + +/* WIRE: OPENINGD_FUNDER_FAILED */ +/* Openingd->master: we failed to negotiation channel */ +u8 *towire_openingd_funder_failed(const tal_t *ctx, const wirestring *reason); +bool fromwire_openingd_funder_failed(const tal_t *ctx, const void *p, wirestring **reason); + +/* WIRE: OPENINGD_FUNDEE */ +/* Openingd->master: they offered channel. */ +/* This gives their txid and info */ +u8 *towire_openingd_fundee(const tal_t *ctx, const struct channel_config *their_config, const struct bitcoin_tx *first_commit, const struct penalty_base *pbase, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *pps, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *their_per_commit_point, const struct pubkey *remote_fundingkey, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshis, struct amount_msat push_msat, u8 channel_flags, u32 feerate_per_kw, const u8 *funding_signed_msg, struct amount_sat our_channel_reserve_satoshis, const u8 *local_shutdown_scriptpubkey, const u8 *remote_shutdown_scriptpubkey); +bool fromwire_openingd_fundee(const tal_t *ctx, const void *p, struct channel_config *their_config, struct bitcoin_tx **first_commit, struct penalty_base **pbase, struct bitcoin_signature *first_commit_sig, struct per_peer_state **pps, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *their_per_commit_point, struct pubkey *remote_fundingkey, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshis, struct amount_msat *push_msat, u8 *channel_flags, u32 *feerate_per_kw, u8 **funding_signed_msg, struct amount_sat *our_channel_reserve_satoshis, u8 **local_shutdown_scriptpubkey, u8 **remote_shutdown_scriptpubkey); + +/* WIRE: OPENINGD_DEV_MEMLEAK */ +/* master -> openingd: do you have a memleak? */ +u8 *towire_openingd_dev_memleak(const tal_t *ctx); +bool fromwire_openingd_dev_memleak(const void *p); + +/* WIRE: OPENINGD_DEV_MEMLEAK_REPLY */ +u8 *towire_openingd_dev_memleak_reply(const tal_t *ctx, bool leak); +bool fromwire_openingd_dev_memleak_reply(const void *p, bool *leak); + + +#endif /* LIGHTNING_OPENINGD_OPENINGD_WIREGEN_H */ + +// SHA256STAMP:exp-0-a51533cda64c44739e86c8c93cc8f70d5f24b6c7ddb1f5b06684c4b35f58f501 diff --git a/wallet/db_postgres_sqlgen.c b/wallet/db_postgres_sqlgen.c new file mode 100644 index 000000000..98dbce313 --- /dev/null +++ b/wallet/db_postgres_sqlgen.c @@ -0,0 +1,1645 @@ +#ifndef LIGHTNINGD_WALLET_GEN_DB_POSTGRES +#define LIGHTNINGD_WALLET_GEN_DB_POSTGRES + +#include +#include + +#if HAVE_POSTGRES + +struct db_query db_postgres_queries[] = { + + { + .name = "CREATE TABLE version (version INTEGER)", + .query = "CREATE TABLE version (version INTEGER)", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO version VALUES (1)", + .query = "INSERT INTO version VALUES (1)", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE outputs ( prev_out_tx BLOB, prev_out_index INTEGER, value BIGINT, type INTEGER, status INTEGER, keyindex INTEGER, PRIMARY KEY (prev_out_tx, prev_out_index));", + .query = "CREATE TABLE outputs ( prev_out_tx BYTEA, prev_out_index INTEGER, value BIGINT, type INTEGER, status INTEGER, keyindex INTEGER, PRIMARY KEY (prev_out_tx, prev_out_index));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE vars ( name VARCHAR(32), val VARCHAR(255), PRIMARY KEY (name));", + .query = "CREATE TABLE vars ( name VARCHAR(32), val VARCHAR(255), PRIMARY KEY (name));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE shachains ( id BIGSERIAL, min_index BIGINT, num_valid BIGINT, PRIMARY KEY (id));", + .query = "CREATE TABLE shachains ( id BIGSERIAL, min_index BIGINT, num_valid BIGINT, PRIMARY KEY (id));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE shachain_known ( shachain_id BIGINT REFERENCES shachains(id) ON DELETE CASCADE, pos INTEGER, idx BIGINT, hash BLOB, PRIMARY KEY (shachain_id, pos));", + .query = "CREATE TABLE shachain_known ( shachain_id BIGINT REFERENCES shachains(id) ON DELETE CASCADE, pos INTEGER, idx BIGINT, hash BYTEA, PRIMARY KEY (shachain_id, pos));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE peers ( id BIGSERIAL, node_id BLOB UNIQUE, address TEXT, PRIMARY KEY (id));", + .query = "CREATE TABLE peers ( id BIGSERIAL, node_id BYTEA UNIQUE, address TEXT, PRIMARY KEY (id));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE channels ( id BIGSERIAL, peer_id BIGINT REFERENCES peers(id) ON DELETE CASCADE, short_channel_id TEXT, channel_config_local BIGINT, channel_config_remote BIGINT, state INTEGER, funder INTEGER, channel_flags INTEGER, minimum_depth INTEGER, next_index_local BIGINT, next_index_remote BIGINT, next_htlc_id BIGINT, funding_tx_id BLOB, funding_tx_outnum INTEGER, funding_satoshi BIGINT, funding_locked_remote INTEGER, push_msatoshi BIGINT, msatoshi_local BIGINT, fundingkey_remote BLOB, revocation_basepoint_remote BLOB, payment_basepoint_remote BLOB, htlc_basepoint_remote BLOB, delayed_payment_basepoint_remote BLOB, per_commit_remote BLOB, old_per_commit_remote BLOB, local_feerate_per_kw INTEGER, remote_feerate_per_kw INTEGER, shachain_remote_id BIGINT, shutdown_scriptpubkey_remote BLOB, shutdown_keyidx_local BIGINT, last_sent_commit_state BIGINT, last_sent_commit_id INTEGER, last_tx BLOB, last_sig BLOB, closing_fee_received INTEGER, closing_sig_received BLOB, PRIMARY KEY (id));", + .query = "CREATE TABLE channels ( id BIGSERIAL, peer_id BIGINT REFERENCES peers(id) ON DELETE CASCADE, short_channel_id TEXT, channel_config_local BIGINT, channel_config_remote BIGINT, state INTEGER, funder INTEGER, channel_flags INTEGER, minimum_depth INTEGER, next_index_local BIGINT, next_index_remote BIGINT, next_htlc_id BIGINT, funding_tx_id BYTEA, funding_tx_outnum INTEGER, funding_satoshi BIGINT, funding_locked_remote INTEGER, push_msatoshi BIGINT, msatoshi_local BIGINT, fundingkey_remote BYTEA, revocation_basepoint_remote BYTEA, payment_basepoint_remote BYTEA, htlc_basepoint_remote BYTEA, delayed_payment_basepoint_remote BYTEA, per_commit_remote BYTEA, old_per_commit_remote BYTEA, local_feerate_per_kw INTEGER, remote_feerate_per_kw INTEGER, shachain_remote_id BIGINT, shutdown_scriptpubkey_remote BYTEA, shutdown_keyidx_local BIGINT, last_sent_commit_state BIGINT, last_sent_commit_id INTEGER, last_tx BYTEA, last_sig BYTEA, closing_fee_received INTEGER, closing_sig_received BYTEA, PRIMARY KEY (id));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE channel_configs ( id BIGSERIAL, dust_limit_satoshis BIGINT, max_htlc_value_in_flight_msat BIGINT, channel_reserve_satoshis BIGINT, htlc_minimum_msat BIGINT, to_self_delay INTEGER, max_accepted_htlcs INTEGER, PRIMARY KEY (id));", + .query = "CREATE TABLE channel_configs ( id BIGSERIAL, dust_limit_satoshis BIGINT, max_htlc_value_in_flight_msat BIGINT, channel_reserve_satoshis BIGINT, htlc_minimum_msat BIGINT, to_self_delay INTEGER, max_accepted_htlcs INTEGER, PRIMARY KEY (id));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE channel_htlcs ( id BIGSERIAL, channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, channel_htlc_id BIGINT, direction INTEGER, origin_htlc BIGINT, msatoshi BIGINT, cltv_expiry INTEGER, payment_hash BLOB, payment_key BLOB, routing_onion BLOB, failuremsg BLOB, malformed_onion INTEGER, hstate INTEGER, shared_secret BLOB, PRIMARY KEY (id), UNIQUE (channel_id, channel_htlc_id, direction));", + .query = "CREATE TABLE channel_htlcs ( id BIGSERIAL, channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, channel_htlc_id BIGINT, direction INTEGER, origin_htlc BIGINT, msatoshi BIGINT, cltv_expiry INTEGER, payment_hash BYTEA, payment_key BYTEA, routing_onion BYTEA, failuremsg BYTEA, malformed_onion INTEGER, hstate INTEGER, shared_secret BYTEA, PRIMARY KEY (id), UNIQUE (channel_id, channel_htlc_id, direction));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE invoices ( id BIGSERIAL, state INTEGER, msatoshi BIGINT, payment_hash BLOB, payment_key BLOB, label TEXT, PRIMARY KEY (id), UNIQUE (label), UNIQUE (payment_hash));", + .query = "CREATE TABLE invoices ( id BIGSERIAL, state INTEGER, msatoshi BIGINT, payment_hash BYTEA, payment_key BYTEA, label TEXT, PRIMARY KEY (id), UNIQUE (label), UNIQUE (payment_hash));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE payments ( id BIGSERIAL, timestamp INTEGER, status INTEGER, payment_hash BLOB, direction INTEGER, destination BLOB, msatoshi BIGINT, PRIMARY KEY (id), UNIQUE (payment_hash));", + .query = "CREATE TABLE payments ( id BIGSERIAL, timestamp INTEGER, status INTEGER, payment_hash BYTEA, direction INTEGER, destination BYTEA, msatoshi BIGINT, PRIMARY KEY (id), UNIQUE (payment_hash));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE invoices ADD expiry_time BIGINT;", + .query = "ALTER TABLE invoices ADD expiry_time BIGINT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE invoices SET expiry_time=9223372036854775807;", + .query = "UPDATE invoices SET expiry_time=9223372036854775807;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE invoices ADD pay_index BIGINT;", + .query = "ALTER TABLE invoices ADD pay_index BIGINT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE UNIQUE INDEX invoices_pay_index ON invoices(pay_index);", + .query = "CREATE UNIQUE INDEX invoices_pay_index ON invoices(pay_index);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE invoices SET pay_index=id WHERE state=1;", + .query = "UPDATE invoices SET pay_index=id WHERE state=1;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO vars(name, val) VALUES('next_pay_index', COALESCE((SELECT MAX(pay_index) FROM invoices WHERE state=1), 0) + 1 );", + .query = "INSERT INTO vars(name, val) VALUES('next_pay_index', COALESCE((SELECT MAX(pay_index) FROM invoices WHERE state=1), 0) + 1 );", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD first_blocknum BIGINT;", + .query = "ALTER TABLE channels ADD first_blocknum BIGINT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channels SET first_blocknum=1 WHERE short_channel_id IS NOT NULL;", + .query = "UPDATE channels SET first_blocknum=1 WHERE short_channel_id IS NOT NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD COLUMN channel_id BIGINT;", + .query = "ALTER TABLE outputs ADD COLUMN channel_id BIGINT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD COLUMN peer_id BLOB;", + .query = "ALTER TABLE outputs ADD COLUMN peer_id BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD COLUMN commitment_point BLOB;", + .query = "ALTER TABLE outputs ADD COLUMN commitment_point BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE invoices ADD COLUMN msatoshi_received BIGINT;", + .query = "ALTER TABLE invoices ADD COLUMN msatoshi_received BIGINT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE invoices SET msatoshi_received=0 WHERE state=1;", + .query = "UPDATE invoices SET msatoshi_received=0 WHERE state=1;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD COLUMN last_was_revoke INTEGER;", + .query = "ALTER TABLE channels ADD COLUMN last_was_revoke INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments RENAME TO temp_payments;", + .query = "ALTER TABLE payments RENAME TO temp_payments;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE payments ( id BIGSERIAL, timestamp INTEGER, status INTEGER, payment_hash BLOB, destination BLOB, msatoshi BIGINT, PRIMARY KEY (id), UNIQUE (payment_hash));", + .query = "CREATE TABLE payments ( id BIGSERIAL, timestamp INTEGER, status INTEGER, payment_hash BYTEA, destination BYTEA, msatoshi BIGINT, PRIMARY KEY (id), UNIQUE (payment_hash));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO payments SELECT id, timestamp, status, payment_hash, destination, msatoshi FROM temp_payments WHERE direction=1;", + .query = "INSERT INTO payments SELECT id, timestamp, status, payment_hash, destination, msatoshi FROM temp_payments WHERE direction=1;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "DROP TABLE temp_payments;", + .query = "DROP TABLE temp_payments;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD COLUMN payment_preimage BLOB;", + .query = "ALTER TABLE payments ADD COLUMN payment_preimage BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD COLUMN path_secrets BLOB;", + .query = "ALTER TABLE payments ADD COLUMN path_secrets BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE invoices ADD paid_timestamp BIGINT;", + .query = "ALTER TABLE invoices ADD paid_timestamp BIGINT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE invoices SET paid_timestamp = CURRENT_TIMESTAMP() WHERE state = 1;", + .query = "UPDATE invoices SET paid_timestamp = EXTRACT(epoch FROM now()) WHERE state = 1;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD COLUMN route_nodes BLOB;", + .query = "ALTER TABLE payments ADD COLUMN route_nodes BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD COLUMN route_channels BLOB;", + .query = "ALTER TABLE payments ADD COLUMN route_channels BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE htlc_sigs (channelid INTEGER REFERENCES channels(id) ON DELETE CASCADE, signature BLOB);", + .query = "CREATE TABLE htlc_sigs (channelid INTEGER REFERENCES channels(id) ON DELETE CASCADE, signature BYTEA);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE INDEX channel_idx ON htlc_sigs (channelid)", + .query = "CREATE INDEX channel_idx ON htlc_sigs (channelid)", + .placeholders = 0, + .readonly = false, + }, + { + .name = "DELETE FROM channels WHERE state=1", + .query = "DELETE FROM channels WHERE state=1", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE db_upgrades (upgrade_from INTEGER, lightning_version TEXT);", + .query = "CREATE TABLE db_upgrades (upgrade_from INTEGER, lightning_version TEXT);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "DELETE FROM peers WHERE id NOT IN (SELECT peer_id FROM channels);", + .query = "DELETE FROM peers WHERE id NOT IN (SELECT peer_id FROM channels);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channels SET STATE = 8 WHERE state > 8;", + .query = "UPDATE channels SET STATE = 8 WHERE state > 8;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE invoices ADD bolt11 TEXT;", + .query = "ALTER TABLE invoices ADD bolt11 TEXT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE blocks (height INT, hash BLOB, prev_hash BLOB, UNIQUE(height));", + .query = "CREATE TABLE blocks (height INT, hash BYTEA, prev_hash BYTEA, UNIQUE(height));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD COLUMN confirmation_height INTEGER REFERENCES blocks(height) ON DELETE SET NULL;", + .query = "ALTER TABLE outputs ADD COLUMN confirmation_height INTEGER REFERENCES blocks(height) ON DELETE SET NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD COLUMN spend_height INTEGER REFERENCES blocks(height) ON DELETE SET NULL;", + .query = "ALTER TABLE outputs ADD COLUMN spend_height INTEGER REFERENCES blocks(height) ON DELETE SET NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE INDEX output_height_idx ON outputs (confirmation_height, spend_height);", + .query = "CREATE INDEX output_height_idx ON outputs (confirmation_height, spend_height);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE utxoset ( txid BLOB, outnum INT, blockheight INT REFERENCES blocks(height) ON DELETE CASCADE, spendheight INT REFERENCES blocks(height) ON DELETE SET NULL, txindex INT, scriptpubkey BLOB, satoshis BIGINT, PRIMARY KEY(txid, outnum));", + .query = "CREATE TABLE utxoset ( txid BYTEA, outnum INT, blockheight INT REFERENCES blocks(height) ON DELETE CASCADE, spendheight INT REFERENCES blocks(height) ON DELETE SET NULL, txindex INT, scriptpubkey BYTEA, satoshis BIGINT, PRIMARY KEY(txid, outnum));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE INDEX short_channel_id ON utxoset (blockheight, txindex, outnum)", + .query = "CREATE INDEX short_channel_id ON utxoset (blockheight, txindex, outnum)", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE INDEX utxoset_spend ON utxoset (spendheight)", + .query = "CREATE INDEX utxoset_spend ON utxoset (spendheight)", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channels SET shutdown_keyidx_local=0 WHERE shutdown_keyidx_local = -1;", + .query = "UPDATE channels SET shutdown_keyidx_local=0 WHERE shutdown_keyidx_local = -1;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD failonionreply BLOB;", + .query = "ALTER TABLE payments ADD failonionreply BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD faildestperm INTEGER;", + .query = "ALTER TABLE payments ADD faildestperm INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD failindex INTEGER;", + .query = "ALTER TABLE payments ADD failindex INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD failcode INTEGER;", + .query = "ALTER TABLE payments ADD failcode INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD failnode BLOB;", + .query = "ALTER TABLE payments ADD failnode BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD failchannel TEXT;", + .query = "ALTER TABLE payments ADD failchannel TEXT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD failupdate BLOB;", + .query = "ALTER TABLE payments ADD failupdate BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE payments SET path_secrets = NULL , route_nodes = NULL , route_channels = NULL WHERE status <> 0;", + .query = "UPDATE payments SET path_secrets = NULL , route_nodes = NULL , route_channels = NULL WHERE status <> 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD in_payments_offered INTEGER DEFAULT 0;", + .query = "ALTER TABLE channels ADD in_payments_offered INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD in_payments_fulfilled INTEGER DEFAULT 0;", + .query = "ALTER TABLE channels ADD in_payments_fulfilled INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD in_msatoshi_offered BIGINT DEFAULT 0;", + .query = "ALTER TABLE channels ADD in_msatoshi_offered BIGINT DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD in_msatoshi_fulfilled BIGINT DEFAULT 0;", + .query = "ALTER TABLE channels ADD in_msatoshi_fulfilled BIGINT DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD out_payments_offered INTEGER DEFAULT 0;", + .query = "ALTER TABLE channels ADD out_payments_offered INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD out_payments_fulfilled INTEGER DEFAULT 0;", + .query = "ALTER TABLE channels ADD out_payments_fulfilled INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD out_msatoshi_offered BIGINT DEFAULT 0;", + .query = "ALTER TABLE channels ADD out_msatoshi_offered BIGINT DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD out_msatoshi_fulfilled BIGINT DEFAULT 0;", + .query = "ALTER TABLE channels ADD out_msatoshi_fulfilled BIGINT DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channels SET in_payments_offered = 0, in_payments_fulfilled = 0 , in_msatoshi_offered = 0, in_msatoshi_fulfilled = 0 , out_payments_offered = 0, out_payments_fulfilled = 0 , out_msatoshi_offered = 0, out_msatoshi_fulfilled = 0 ;", + .query = "UPDATE channels SET in_payments_offered = 0, in_payments_fulfilled = 0 , in_msatoshi_offered = 0, in_msatoshi_fulfilled = 0 , out_payments_offered = 0, out_payments_fulfilled = 0 , out_msatoshi_offered = 0, out_msatoshi_fulfilled = 0 ;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD msatoshi_sent BIGINT;", + .query = "ALTER TABLE payments ADD msatoshi_sent BIGINT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE payments SET msatoshi_sent = msatoshi;", + .query = "UPDATE payments SET msatoshi_sent = msatoshi;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "DELETE FROM utxoset WHERE blockheight IN ( SELECT DISTINCT(blockheight) FROM utxoset LEFT OUTER JOIN blocks on (blockheight = blocks.height) WHERE blocks.hash IS NULL);", + .query = "DELETE FROM utxoset WHERE blockheight IN ( SELECT DISTINCT(blockheight) FROM utxoset LEFT OUTER JOIN blocks on (blockheight = blocks.height) WHERE blocks.hash IS NULL);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD min_possible_feerate INTEGER;", + .query = "ALTER TABLE channels ADD min_possible_feerate INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD max_possible_feerate INTEGER;", + .query = "ALTER TABLE channels ADD max_possible_feerate INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channels SET min_possible_feerate=0, max_possible_feerate=250000;", + .query = "UPDATE channels SET min_possible_feerate=0, max_possible_feerate=250000;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD msatoshi_to_us_min BIGINT;", + .query = "ALTER TABLE channels ADD msatoshi_to_us_min BIGINT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD msatoshi_to_us_max BIGINT;", + .query = "ALTER TABLE channels ADD msatoshi_to_us_max BIGINT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channels SET msatoshi_to_us_min = msatoshi_local , msatoshi_to_us_max = msatoshi_local ;", + .query = "UPDATE channels SET msatoshi_to_us_min = msatoshi_local , msatoshi_to_us_max = msatoshi_local ;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE transactions ( id BLOB, blockheight INTEGER REFERENCES blocks(height) ON DELETE SET NULL, txindex INTEGER, rawtx BLOB, PRIMARY KEY (id));", + .query = "CREATE TABLE transactions ( id BYTEA, blockheight INTEGER REFERENCES blocks(height) ON DELETE SET NULL, txindex INTEGER, rawtx BYTEA, PRIMARY KEY (id));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD faildetail TEXT;", + .query = "ALTER TABLE payments ADD faildetail TEXT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE payments SET faildetail = 'unspecified payment failure reason' WHERE status = 2;", + .query = "UPDATE payments SET faildetail = 'unspecified payment failure reason' WHERE status = 2;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE channeltxs ( id BIGSERIAL, channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, type INTEGER, transaction_id BLOB REFERENCES transactions(id) ON DELETE CASCADE, input_num INTEGER, blockheight INTEGER REFERENCES blocks(height) ON DELETE CASCADE, PRIMARY KEY(id));", + .query = "CREATE TABLE channeltxs ( id BIGSERIAL, channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, type INTEGER, transaction_id BYTEA REFERENCES transactions(id) ON DELETE CASCADE, input_num INTEGER, blockheight INTEGER REFERENCES blocks(height) ON DELETE CASCADE, PRIMARY KEY(id));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "DELETE FROM blocks WHERE height > (SELECT MIN(first_blocknum) FROM channels);", + .query = "DELETE FROM blocks WHERE height > (SELECT MIN(first_blocknum) FROM channels);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO blocks (height) VALUES ((SELECT MIN(first_blocknum) FROM channels)) ON CONFLICT(height) DO NOTHING;", + .query = "INSERT INTO blocks (height) VALUES ((SELECT MIN(first_blocknum) FROM channels)) ON CONFLICT(height) DO NOTHING;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "DELETE FROM blocks WHERE height IS NULL;", + .query = "DELETE FROM blocks WHERE height IS NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE invoices ADD description TEXT;", + .query = "ALTER TABLE invoices ADD description TEXT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD description TEXT;", + .query = "ALTER TABLE payments ADD description TEXT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD future_per_commitment_point BLOB;", + .query = "ALTER TABLE channels ADD future_per_commitment_point BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD last_sent_commit BLOB;", + .query = "ALTER TABLE channels ADD last_sent_commit BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE forwarded_payments ( in_htlc_id BIGINT REFERENCES channel_htlcs(id) ON DELETE SET NULL, out_htlc_id BIGINT REFERENCES channel_htlcs(id) ON DELETE SET NULL, in_channel_scid BIGINT, out_channel_scid BIGINT, in_msatoshi BIGINT, out_msatoshi BIGINT, state INTEGER, UNIQUE(in_htlc_id, out_htlc_id));", + .query = "CREATE TABLE forwarded_payments ( in_htlc_id BIGINT REFERENCES channel_htlcs(id) ON DELETE SET NULL, out_htlc_id BIGINT REFERENCES channel_htlcs(id) ON DELETE SET NULL, in_channel_scid BIGINT, out_channel_scid BIGINT, in_msatoshi BIGINT, out_msatoshi BIGINT, state INTEGER, UNIQUE(in_htlc_id, out_htlc_id));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD faildirection INTEGER;", + .query = "ALTER TABLE payments ADD faildirection INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD scriptpubkey BLOB;", + .query = "ALTER TABLE outputs ADD scriptpubkey BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD bolt11 TEXT;", + .query = "ALTER TABLE payments ADD bolt11 TEXT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD feerate_base INTEGER;", + .query = "ALTER TABLE channels ADD feerate_base INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD feerate_ppm INTEGER;", + .query = "ALTER TABLE channels ADD feerate_ppm INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channel_htlcs ADD received_time BIGINT", + .query = "ALTER TABLE channel_htlcs ADD received_time BIGINT", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE forwarded_payments ADD received_time BIGINT", + .query = "ALTER TABLE forwarded_payments ADD received_time BIGINT", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE forwarded_payments ADD resolved_time BIGINT", + .query = "ALTER TABLE forwarded_payments ADD resolved_time BIGINT", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD remote_upfront_shutdown_script BLOB;", + .query = "ALTER TABLE channels ADD remote_upfront_shutdown_script BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE forwarded_payments ADD failcode INTEGER;", + .query = "ALTER TABLE forwarded_payments ADD failcode INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD remote_ann_node_sig BLOB;", + .query = "ALTER TABLE channels ADD remote_ann_node_sig BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD remote_ann_bitcoin_sig BLOB;", + .query = "ALTER TABLE channels ADD remote_ann_bitcoin_sig BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE transactions ADD type BIGINT;", + .query = "ALTER TABLE transactions ADD type BIGINT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE transactions ADD channel_id BIGINT;", + .query = "ALTER TABLE transactions ADD channel_id BIGINT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channels SET short_channel_id = REPLACE(short_channel_id, ':', 'x') WHERE short_channel_id IS NOT NULL;", + .query = "UPDATE channels SET short_channel_id = REPLACE(short_channel_id, ':', 'x') WHERE short_channel_id IS NOT NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE payments SET failchannel = REPLACE(failchannel, ':', 'x') WHERE failchannel IS NOT NULL;", + .query = "UPDATE payments SET failchannel = REPLACE(failchannel, ':', 'x') WHERE failchannel IS NOT NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD COLUMN option_static_remotekey INTEGER DEFAULT 0;", + .query = "ALTER TABLE channels ADD COLUMN option_static_remotekey INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE vars ADD COLUMN intval INTEGER", + .query = "ALTER TABLE vars ADD COLUMN intval INTEGER", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE vars ADD COLUMN blobval BLOB", + .query = "ALTER TABLE vars ADD COLUMN blobval BYTEA", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE vars SET intval = CAST(val AS INTEGER) WHERE name IN ('bip32_max_index', 'last_processed_block', 'next_pay_index')", + .query = "UPDATE vars SET intval = CAST(val AS INTEGER) WHERE name IN ('bip32_max_index', 'last_processed_block', 'next_pay_index')", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE vars SET blobval = CAST(val AS BLOB) WHERE name = 'genesis_hash'", + .query = "UPDATE vars SET blobval = CAST(val AS BYTEA) WHERE name = 'genesis_hash'", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE transaction_annotations ( txid BLOB, idx INTEGER, location INTEGER, type INTEGER, channel BIGINT REFERENCES channels(id), UNIQUE(txid, idx));", + .query = "CREATE TABLE transaction_annotations ( txid BYTEA, idx INTEGER, location INTEGER, type INTEGER, channel BIGINT REFERENCES channels(id), UNIQUE(txid, idx));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD shutdown_scriptpubkey_local BLOB;", + .query = "ALTER TABLE channels ADD shutdown_scriptpubkey_local BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE forwarded_payments SET received_time=0 WHERE received_time IS NULL;", + .query = "UPDATE forwarded_payments SET received_time=0 WHERE received_time IS NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE invoices ADD COLUMN features BLOB DEFAULT '';", + .query = "ALTER TABLE invoices ADD COLUMN features BYTEA DEFAULT '';", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE payments ( id BIGSERIAL, timestamp INTEGER, status INTEGER, payment_hash BLOB, destination BLOB, msatoshi BIGINT, payment_preimage BLOB, path_secrets BLOB, route_nodes BLOB, route_channels BLOB, failonionreply BLOB, faildestperm INTEGER, failindex INTEGER, failcode INTEGER, failnode BLOB, failchannel TEXT, failupdate BLOB, msatoshi_sent BIGINT, faildetail TEXT, description TEXT, faildirection INTEGER, bolt11 TEXT, total_msat BIGINT, partid BIGINT, PRIMARY KEY (id), UNIQUE (payment_hash, partid))", + .query = "CREATE TABLE payments ( id BIGSERIAL, timestamp INTEGER, status INTEGER, payment_hash BYTEA, destination BYTEA, msatoshi BIGINT, payment_preimage BYTEA, path_secrets BYTEA, route_nodes BYTEA, route_channels BYTEA, failonionreply BYTEA, faildestperm INTEGER, failindex INTEGER, failcode INTEGER, failnode BYTEA, failchannel TEXT, failupdate BYTEA, msatoshi_sent BIGINT, faildetail TEXT, description TEXT, faildirection INTEGER, bolt11 TEXT, total_msat BIGINT, partid BIGINT, PRIMARY KEY (id), UNIQUE (payment_hash, partid))", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO payments (id, timestamp, status, payment_hash, destination, msatoshi, payment_preimage, path_secrets, route_nodes, route_channels, failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, msatoshi_sent, faildetail, description, faildirection, bolt11)SELECT id, timestamp, status, payment_hash, destination, msatoshi, payment_preimage, path_secrets, route_nodes, route_channels, failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, msatoshi_sent, faildetail, description, faildirection, bolt11 FROM temp_payments;", + .query = "INSERT INTO payments (id, timestamp, status, payment_hash, destination, msatoshi, payment_preimage, path_secrets, route_nodes, route_channels, failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, msatoshi_sent, faildetail, description, faildirection, bolt11)SELECT id, timestamp, status, payment_hash, destination, msatoshi, payment_preimage, path_secrets, route_nodes, route_channels, failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, msatoshi_sent, faildetail, description, faildirection, bolt11 FROM temp_payments;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE payments SET total_msat = msatoshi;", + .query = "UPDATE payments SET total_msat = msatoshi;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE payments SET partid = 0;", + .query = "UPDATE payments SET partid = 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channel_htlcs ADD partid BIGINT;", + .query = "ALTER TABLE channel_htlcs ADD partid BIGINT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channel_htlcs SET partid = 0;", + .query = "UPDATE channel_htlcs SET partid = 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE channel_feerates ( channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, hstate INTEGER, feerate_per_kw INTEGER, UNIQUE (channel_id, hstate));", + .query = "CREATE TABLE channel_feerates ( channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, hstate INTEGER, feerate_per_kw INTEGER, UNIQUE (channel_id, hstate));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 4, local_feerate_per_kw FROM channels WHERE funder = 0;", + .query = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 4, local_feerate_per_kw FROM channels WHERE funder = 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 1, remote_feerate_per_kw FROM channels WHERE funder = 0 and local_feerate_per_kw != remote_feerate_per_kw;", + .query = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 1, remote_feerate_per_kw FROM channels WHERE funder = 0 and local_feerate_per_kw != remote_feerate_per_kw;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 14, remote_feerate_per_kw FROM channels WHERE funder = 1;", + .query = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 14, remote_feerate_per_kw FROM channels WHERE funder = 1;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 11, local_feerate_per_kw FROM channels WHERE funder = 1 and local_feerate_per_kw != remote_feerate_per_kw;", + .query = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 11, local_feerate_per_kw FROM channels WHERE funder = 1 and local_feerate_per_kw != remote_feerate_per_kw;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO vars (name, intval) VALUES ('data_version', 0);", + .query = "INSERT INTO vars (name, intval) VALUES ('data_version', 0);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channel_htlcs ADD localfailmsg BLOB;", + .query = "ALTER TABLE channel_htlcs ADD localfailmsg BYTEA;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channel_htlcs SET localfailmsg=decode('2002', 'hex') WHERE malformed_onion != 0 AND direction = 1;", + .query = "UPDATE channel_htlcs SET localfailmsg=decode('2002', 'hex') WHERE malformed_onion != 0 AND direction = 1;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD our_funding_satoshi BIGINT DEFAULT 0;", + .query = "ALTER TABLE channels ADD our_funding_satoshi BIGINT DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE penalty_bases ( channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, commitnum BIGINT, txid BLOB, outnum INTEGER, amount BIGINT, PRIMARY KEY (channel_id, commitnum));", + .query = "CREATE TABLE penalty_bases ( channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, commitnum BIGINT, txid BYTEA, outnum INTEGER, amount BIGINT, PRIMARY KEY (channel_id, commitnum));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channel_htlcs ADD we_filled INTEGER;", + .query = "ALTER TABLE channel_htlcs ADD we_filled INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO vars (name, intval) VALUES ('coin_moves_count', 0);", + .query = "INSERT INTO vars (name, intval) VALUES ('coin_moves_count', 0);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD reserved_til INTEGER DEFAULT NULL;", + .query = "ALTER TABLE outputs ADD reserved_til INTEGER DEFAULT NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD COLUMN option_anchor_outputs INTEGER DEFAULT 0;", + .query = "ALTER TABLE channels ADD COLUMN option_anchor_outputs INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD option_anchor_outputs INTEGER DEFAULT 0;", + .query = "ALTER TABLE outputs ADD option_anchor_outputs INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?", + .query = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = $1", + .placeholders = 1, + .readonly = false, + }, + { + .name = "SELECT version FROM version LIMIT 1", + .query = "SELECT version FROM version LIMIT 1", + .placeholders = 0, + .readonly = true, + }, + { + .name = "UPDATE version SET version=?;", + .query = "UPDATE version SET version=$1;", + .placeholders = 1, + .readonly = false, + }, + { + .name = "INSERT INTO db_upgrades VALUES (?, ?);", + .query = "INSERT INTO db_upgrades VALUES ($1, $2);", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT intval FROM vars WHERE name = 'data_version'", + .query = "SELECT intval FROM vars WHERE name = 'data_version'", + .placeholders = 0, + .readonly = true, + }, + { + .name = "SELECT intval FROM vars WHERE name= ? LIMIT 1", + .query = "SELECT intval FROM vars WHERE name= $1 LIMIT 1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "UPDATE vars SET intval=? WHERE name=?;", + .query = "UPDATE vars SET intval=$1 WHERE name=$2;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "INSERT INTO vars (name, intval) VALUES (?, ?);", + .query = "INSERT INTO vars (name, intval) VALUES ($1, $2);", + .placeholders = 2, + .readonly = false, + }, + { + .name = "UPDATE channels SET feerate_base = ?, feerate_ppm = ?;", + .query = "UPDATE channels SET feerate_base = $1, feerate_ppm = $2;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "UPDATE channels SET our_funding_satoshi = funding_satoshi WHERE funder = 0;", + .query = "UPDATE channels SET our_funding_satoshi = funding_satoshi WHERE funder = 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "SELECT type, keyindex, prev_out_tx, prev_out_index, channel_id, peer_id, commitment_point FROM outputs WHERE scriptpubkey IS NULL;", + .query = "SELECT type, keyindex, prev_out_tx, prev_out_index, channel_id, peer_id, commitment_point FROM outputs WHERE scriptpubkey IS NULL;", + .placeholders = 0, + .readonly = true, + }, + { + .name = "UPDATE outputs SET scriptpubkey = ? WHERE prev_out_tx = ? AND prev_out_index = ?", + .query = "UPDATE outputs SET scriptpubkey = $1 WHERE prev_out_tx = $2 AND prev_out_index = $3", + .placeholders = 3, + .readonly = false, + }, + { + .name = "SELECT c.id, p.node_id, c.last_tx, c.funding_satoshi, c.fundingkey_remote, c.last_sig FROM channels c LEFT OUTER JOIN peers p ON p.id = c.peer_id;", + .query = "SELECT c.id, p.node_id, c.last_tx, c.funding_satoshi, c.fundingkey_remote, c.last_sig FROM channels c LEFT OUTER JOIN peers p ON p.id = c.peer_id;", + .placeholders = 0, + .readonly = true, + }, + { + .name = "UPDATE channels SET last_tx = ? WHERE id = ?;", + .query = "UPDATE channels SET last_tx = $1 WHERE id = $2;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "UPDATE invoices SET state = ? WHERE state = ? AND expiry_time <= ?;", + .query = "UPDATE invoices SET state = $1 WHERE state = $2 AND expiry_time <= $3;", + .placeholders = 3, + .readonly = false, + }, + { + .name = "SELECT id FROM invoices WHERE state = ? AND expiry_time <= ?", + .query = "SELECT id FROM invoices WHERE state = $1 AND expiry_time <= $2", + .placeholders = 2, + .readonly = true, + }, + { + .name = "SELECT MIN(expiry_time) FROM invoices WHERE state = ?;", + .query = "SELECT MIN(expiry_time) FROM invoices WHERE state = $1;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "INSERT INTO invoices ( payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features) VALUES ( ?, ?, ? , ?, ?, ? , NULL, NULL , NULL, ?, ?, ?);", + .query = "INSERT INTO invoices ( payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features) VALUES ( $1, $2, $3 , $4, $5, $6 , NULL, NULL , NULL, $7, $8, $9);", + .placeholders = 9, + .readonly = false, + }, + { + .name = "SELECT id FROM invoices WHERE label = ?;", + .query = "SELECT id FROM invoices WHERE label = $1;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT id FROM invoices WHERE payment_hash = ?;", + .query = "SELECT id FROM invoices WHERE payment_hash = $1;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT id FROM invoices WHERE payment_hash = ? AND state = ?;", + .query = "SELECT id FROM invoices WHERE payment_hash = $1 AND state = $2;", + .placeholders = 2, + .readonly = true, + }, + { + .name = "DELETE FROM invoices WHERE id=?;", + .query = "DELETE FROM invoices WHERE id=$1;", + .placeholders = 1, + .readonly = false, + }, + { + .name = "DELETE FROM invoices WHERE state = ? AND expiry_time <= ?;", + .query = "DELETE FROM invoices WHERE state = $1 AND expiry_time <= $2;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices ORDER BY id;", + .query = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices ORDER BY id;", + .placeholders = 0, + .readonly = true, + }, + { + .name = "SELECT state FROM invoices WHERE id = ?;", + .query = "SELECT state FROM invoices WHERE id = $1;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "UPDATE invoices SET state=? , pay_index=? , msatoshi_received=? , paid_timestamp=? WHERE id=?;", + .query = "UPDATE invoices SET state=$1 , pay_index=$2 , msatoshi_received=$3 , paid_timestamp=$4 WHERE id=$5;", + .placeholders = 5, + .readonly = false, + }, + { + .name = "SELECT id FROM invoices WHERE pay_index IS NOT NULL AND pay_index > ? ORDER BY pay_index ASC LIMIT 1;", + .query = "SELECT id FROM invoices WHERE pay_index IS NOT NULL AND pay_index > $1 ORDER BY pay_index ASC LIMIT 1;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices WHERE id = ?;", + .query = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices WHERE id = $1;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT txid, outnum FROM utxoset WHERE spendheight is NULL", + .query = "SELECT txid, outnum FROM utxoset WHERE spendheight is NULL", + .placeholders = 0, + .readonly = true, + }, + { + .name = "SELECT * from outputs WHERE prev_out_tx=? AND prev_out_index=?", + .query = "SELECT * from outputs WHERE prev_out_tx=$1 AND prev_out_index=$2", + .placeholders = 2, + .readonly = true, + }, + { + .name = "INSERT INTO outputs ( prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + .query = "INSERT INTO outputs ( prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);", + .placeholders = 13, + .readonly = false, + }, + { + .name = "UPDATE outputs SET status=? WHERE status=? AND prev_out_tx=? AND prev_out_index=?", + .query = "UPDATE outputs SET status=$1 WHERE status=$2 AND prev_out_tx=$3 AND prev_out_index=$4", + .placeholders = 4, + .readonly = false, + }, + { + .name = "UPDATE outputs SET status=? WHERE prev_out_tx=? AND prev_out_index=?", + .query = "UPDATE outputs SET status=$1 WHERE prev_out_tx=$2 AND prev_out_index=$3", + .placeholders = 3, + .readonly = false, + }, + { + .name = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs", + .query = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs", + .placeholders = 0, + .readonly = true, + }, + { + .name = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs WHERE status= ? ", + .query = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs WHERE status= $1 ", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey, reserved_til FROM outputs WHERE channel_id IS NOT NULL AND confirmation_height IS NULL", + .query = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey, reserved_til FROM outputs WHERE channel_id IS NOT NULL AND confirmation_height IS NULL", + .placeholders = 0, + .readonly = true, + }, + { + .name = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey, reserved_til FROM outputs WHERE prev_out_tx = ? AND prev_out_index = ?", + .query = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey, reserved_til FROM outputs WHERE prev_out_tx = $1 AND prev_out_index = $2", + .placeholders = 2, + .readonly = true, + }, + { + .name = "UPDATE outputs SET status=?, reserved_til=?WHERE prev_out_tx=? AND prev_out_index=?", + .query = "UPDATE outputs SET status=$1, reserved_til=$2WHERE prev_out_tx=$3 AND prev_out_index=$4", + .placeholders = 4, + .readonly = false, + }, + { + .name = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs WHERE status = ? OR (status = ? AND reserved_til <= ?)ORDER BY RANDOM();", + .query = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs WHERE status = $1 OR (status = $2 AND reserved_til <= $3)ORDER BY RANDOM();", + .placeholders = 3, + .readonly = true, + }, + { + .name = "INSERT INTO shachains (min_index, num_valid) VALUES (?, 0);", + .query = "INSERT INTO shachains (min_index, num_valid) VALUES ($1, 0);", + .placeholders = 1, + .readonly = false, + }, + { + .name = "UPDATE shachains SET num_valid=?, min_index=? WHERE id=?", + .query = "UPDATE shachains SET num_valid=$1, min_index=$2 WHERE id=$3", + .placeholders = 3, + .readonly = false, + }, + { + .name = "UPDATE shachain_known SET idx=?, hash=? WHERE shachain_id=? AND pos=?", + .query = "UPDATE shachain_known SET idx=$1, hash=$2 WHERE shachain_id=$3 AND pos=$4", + .placeholders = 4, + .readonly = false, + }, + { + .name = "INSERT INTO shachain_known (shachain_id, pos, idx, hash) VALUES (?, ?, ?, ?);", + .query = "INSERT INTO shachain_known (shachain_id, pos, idx, hash) VALUES ($1, $2, $3, $4);", + .placeholders = 4, + .readonly = false, + }, + { + .name = "SELECT min_index, num_valid FROM shachains WHERE id=?", + .query = "SELECT min_index, num_valid FROM shachains WHERE id=$1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT idx, hash, pos FROM shachain_known WHERE shachain_id=?", + .query = "SELECT idx, hash, pos FROM shachain_known WHERE shachain_id=$1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT id, node_id, address FROM peers WHERE id=?;", + .query = "SELECT id, node_id, address FROM peers WHERE id=$1;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT signature FROM htlc_sigs WHERE channelid = ?", + .query = "SELECT signature FROM htlc_sigs WHERE channelid = $1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT remote_ann_node_sig, remote_ann_bitcoin_sig FROM channels WHERE id = ?", + .query = "SELECT remote_ann_node_sig, remote_ann_bitcoin_sig FROM channels WHERE id = $1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT hstate, feerate_per_kw FROM channel_feerates WHERE channel_id = ?", + .query = "SELECT hstate, feerate_per_kw FROM channel_feerates WHERE channel_id = $1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT id FROM channels ORDER BY id DESC LIMIT 1;", + .query = "SELECT id FROM channels ORDER BY id DESC LIMIT 1;", + .placeholders = 0, + .readonly = true, + }, + { + .name = "SELECT id, peer_id, short_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, option_static_remotekey, option_anchor_outputs, shutdown_scriptpubkey_local FROM channels WHERE state < ?;", + .query = "SELECT id, peer_id, short_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, option_static_remotekey, option_anchor_outputs, shutdown_scriptpubkey_local FROM channels WHERE state < $1;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "UPDATE channels SET in_payments_offered = COALESCE(in_payments_offered, 0) + 1 , in_msatoshi_offered = COALESCE(in_msatoshi_offered, 0) + ? WHERE id = ?;", + .query = "UPDATE channels SET in_payments_offered = COALESCE(in_payments_offered, 0) + 1 , in_msatoshi_offered = COALESCE(in_msatoshi_offered, 0) + $1 WHERE id = $2;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "UPDATE channels SET in_payments_fulfilled = COALESCE(in_payments_fulfilled, 0) + 1 , in_msatoshi_fulfilled = COALESCE(in_msatoshi_fulfilled, 0) + ? WHERE id = ?;", + .query = "UPDATE channels SET in_payments_fulfilled = COALESCE(in_payments_fulfilled, 0) + 1 , in_msatoshi_fulfilled = COALESCE(in_msatoshi_fulfilled, 0) + $1 WHERE id = $2;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "UPDATE channels SET out_payments_offered = COALESCE(out_payments_offered, 0) + 1 , out_msatoshi_offered = COALESCE(out_msatoshi_offered, 0) + ? WHERE id = ?;", + .query = "UPDATE channels SET out_payments_offered = COALESCE(out_payments_offered, 0) + 1 , out_msatoshi_offered = COALESCE(out_msatoshi_offered, 0) + $1 WHERE id = $2;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "UPDATE channels SET out_payments_fulfilled = COALESCE(out_payments_fulfilled, 0) + 1 , out_msatoshi_fulfilled = COALESCE(out_msatoshi_fulfilled, 0) + ? WHERE id = ?;", + .query = "UPDATE channels SET out_payments_fulfilled = COALESCE(out_payments_fulfilled, 0) + 1 , out_msatoshi_fulfilled = COALESCE(out_msatoshi_fulfilled, 0) + $1 WHERE id = $2;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT in_payments_offered, in_payments_fulfilled, in_msatoshi_offered, in_msatoshi_fulfilled, out_payments_offered, out_payments_fulfilled, out_msatoshi_offered, out_msatoshi_fulfilled FROM channels WHERE id = ?", + .query = "SELECT in_payments_offered, in_payments_fulfilled, in_msatoshi_offered, in_msatoshi_fulfilled, out_payments_offered, out_payments_fulfilled, out_msatoshi_offered, out_msatoshi_fulfilled FROM channels WHERE id = $1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT MIN(height), MAX(height) FROM blocks;", + .query = "SELECT MIN(height), MAX(height) FROM blocks;", + .placeholders = 0, + .readonly = true, + }, + { + .name = "INSERT INTO channel_configs DEFAULT VALUES;", + .query = "INSERT INTO channel_configs DEFAULT VALUES;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channel_configs SET dust_limit_satoshis=?, max_htlc_value_in_flight_msat=?, channel_reserve_satoshis=?, htlc_minimum_msat=?, to_self_delay=?, max_accepted_htlcs=? WHERE id=?;", + .query = "UPDATE channel_configs SET dust_limit_satoshis=$1, max_htlc_value_in_flight_msat=$2, channel_reserve_satoshis=$3, htlc_minimum_msat=$4, to_self_delay=$5, max_accepted_htlcs=$6 WHERE id=$7;", + .placeholders = 7, + .readonly = false, + }, + { + .name = "SELECT id, dust_limit_satoshis, max_htlc_value_in_flight_msat, channel_reserve_satoshis, htlc_minimum_msat, to_self_delay, max_accepted_htlcs FROM channel_configs WHERE id= ? ;", + .query = "SELECT id, dust_limit_satoshis, max_htlc_value_in_flight_msat, channel_reserve_satoshis, htlc_minimum_msat, to_self_delay, max_accepted_htlcs FROM channel_configs WHERE id= $1 ;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "UPDATE channels SET remote_ann_node_sig=?, remote_ann_bitcoin_sig=? WHERE id=?", + .query = "UPDATE channels SET remote_ann_node_sig=$1, remote_ann_bitcoin_sig=$2 WHERE id=$3", + .placeholders = 3, + .readonly = false, + }, + { + .name = "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=? WHERE id=?", + .query = "UPDATE channels SET shachain_remote_id=$1, short_channel_id=$2, state=$3, funder=$4, channel_flags=$5, minimum_depth=$6, next_index_local=$7, next_index_remote=$8, next_htlc_id=$9, funding_tx_id=$10, funding_tx_outnum=$11, funding_satoshi=$12, our_funding_satoshi=$13, funding_locked_remote=$14, push_msatoshi=$15, msatoshi_local=$16, shutdown_scriptpubkey_remote=$17, shutdown_keyidx_local=$18, channel_config_local=$19, last_tx=$20, last_sig=$21, last_was_revoke=$22, min_possible_feerate=$23, max_possible_feerate=$24, msatoshi_to_us_min=$25, msatoshi_to_us_max=$26, feerate_base=$27, feerate_ppm=$28, remote_upfront_shutdown_script=$29, option_static_remotekey=$30, option_anchor_outputs=$31, shutdown_scriptpubkey_local=$32 WHERE id=$33", + .placeholders = 33, + .readonly = false, + }, + { + .name = "UPDATE channels SET fundingkey_remote=?, revocation_basepoint_remote=?, payment_basepoint_remote=?, htlc_basepoint_remote=?, delayed_payment_basepoint_remote=?, per_commit_remote=?, old_per_commit_remote=?, channel_config_remote=?, future_per_commitment_point=? WHERE id=?", + .query = "UPDATE channels SET fundingkey_remote=$1, revocation_basepoint_remote=$2, payment_basepoint_remote=$3, htlc_basepoint_remote=$4, delayed_payment_basepoint_remote=$5, per_commit_remote=$6, old_per_commit_remote=$7, channel_config_remote=$8, future_per_commitment_point=$9 WHERE id=$10", + .placeholders = 10, + .readonly = false, + }, + { + .name = "DELETE FROM channel_feerates WHERE channel_id=?", + .query = "DELETE FROM channel_feerates WHERE channel_id=$1", + .placeholders = 1, + .readonly = false, + }, + { + .name = "INSERT INTO channel_feerates VALUES(?, ?, ?)", + .query = "INSERT INTO channel_feerates VALUES($1, $2, $3)", + .placeholders = 3, + .readonly = false, + }, + { + .name = "UPDATE channels SET last_sent_commit=? WHERE id=?", + .query = "UPDATE channels SET last_sent_commit=$1 WHERE id=$2", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT id FROM peers WHERE node_id = ?", + .query = "SELECT id FROM peers WHERE node_id = $1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "UPDATE peers SET address = ? WHERE id = ?", + .query = "UPDATE peers SET address = $1 WHERE id = $2", + .placeholders = 2, + .readonly = false, + }, + { + .name = "INSERT INTO peers (node_id, address) VALUES (?, ?);", + .query = "INSERT INTO peers (node_id, address) VALUES ($1, $2);", + .placeholders = 2, + .readonly = false, + }, + { + .name = "INSERT INTO channels (peer_id, first_blocknum, id) VALUES (?, ?, ?);", + .query = "INSERT INTO channels (peer_id, first_blocknum, id) VALUES ($1, $2, $3);", + .placeholders = 3, + .readonly = false, + }, + { + .name = "DELETE FROM channel_htlcs WHERE channel_id=?", + .query = "DELETE FROM channel_htlcs WHERE channel_id=$1", + .placeholders = 1, + .readonly = false, + }, + { + .name = "DELETE FROM htlc_sigs WHERE channelid=?", + .query = "DELETE FROM htlc_sigs WHERE channelid=$1", + .placeholders = 1, + .readonly = false, + }, + { + .name = "DELETE FROM channeltxs WHERE channel_id=?", + .query = "DELETE FROM channeltxs WHERE channel_id=$1", + .placeholders = 1, + .readonly = false, + }, + { + .name = "DELETE FROM shachains WHERE id IN ( SELECT shachain_remote_id FROM channels WHERE channels.id=?)", + .query = "DELETE FROM shachains WHERE id IN ( SELECT shachain_remote_id FROM channels WHERE channels.id=$1)", + .placeholders = 1, + .readonly = false, + }, + { + .name = "UPDATE channels SET state=?, peer_id=?WHERE channels.id=?", + .query = "UPDATE channels SET state=$1, peer_id=$2WHERE channels.id=$3", + .placeholders = 3, + .readonly = false, + }, + { + .name = "SELECT * FROM channels WHERE peer_id = ?;", + .query = "SELECT * FROM channels WHERE peer_id = $1;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "DELETE FROM peers WHERE id=?", + .query = "DELETE FROM peers WHERE id=$1", + .placeholders = 1, + .readonly = false, + }, + { + .name = "UPDATE outputs SET confirmation_height = ? WHERE prev_out_tx = ?", + .query = "UPDATE outputs SET confirmation_height = $1 WHERE prev_out_tx = $2", + .placeholders = 2, + .readonly = false, + }, + { + .name = "INSERT INTO channel_htlcs ( channel_id, channel_htlc_id, direction, msatoshi, cltv_expiry, payment_hash, payment_key, hstate, shared_secret, routing_onion, received_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + .query = "INSERT INTO channel_htlcs ( channel_id, channel_htlc_id, direction, msatoshi, cltv_expiry, payment_hash, payment_key, hstate, shared_secret, routing_onion, received_time) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);", + .placeholders = 11, + .readonly = false, + }, + { + .name = "INSERT INTO channel_htlcs ( channel_id, channel_htlc_id, direction, origin_htlc, msatoshi, cltv_expiry, payment_hash, payment_key, hstate, routing_onion, partid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + .query = "INSERT INTO channel_htlcs ( channel_id, channel_htlc_id, direction, origin_htlc, msatoshi, cltv_expiry, payment_hash, payment_key, hstate, routing_onion, partid) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);", + .placeholders = 11, + .readonly = false, + }, + { + .name = "UPDATE channel_htlcs SET hstate=?, payment_key=?, malformed_onion=?, failuremsg=?, localfailmsg=?, we_filled=? WHERE id=?", + .query = "UPDATE channel_htlcs SET hstate=$1, payment_key=$2, malformed_onion=$3, failuremsg=$4, localfailmsg=$5, we_filled=$6 WHERE id=$7", + .placeholders = 7, + .readonly = false, + }, + { + .name = "SELECT id, channel_htlc_id, msatoshi, cltv_expiry, hstate, payment_hash, payment_key, routing_onion, failuremsg, malformed_onion, origin_htlc, shared_secret, received_time, we_filled FROM channel_htlcs WHERE direction= ? AND channel_id= ? AND hstate != ?", + .query = "SELECT id, channel_htlc_id, msatoshi, cltv_expiry, hstate, payment_hash, payment_key, routing_onion, failuremsg, malformed_onion, origin_htlc, shared_secret, received_time, we_filled FROM channel_htlcs WHERE direction= $1 AND channel_id= $2 AND hstate != $3", + .placeholders = 3, + .readonly = true, + }, + { + .name = "SELECT id, channel_htlc_id, msatoshi, cltv_expiry, hstate, payment_hash, payment_key, routing_onion, failuremsg, malformed_onion, origin_htlc, shared_secret, received_time, partid, localfailmsg FROM channel_htlcs WHERE direction = ? AND channel_id = ? AND hstate != ?", + .query = "SELECT id, channel_htlc_id, msatoshi, cltv_expiry, hstate, payment_hash, payment_key, routing_onion, failuremsg, malformed_onion, origin_htlc, shared_secret, received_time, partid, localfailmsg FROM channel_htlcs WHERE direction = $1 AND channel_id = $2 AND hstate != $3", + .placeholders = 3, + .readonly = true, + }, + { + .name = "SELECT channel_id, direction, cltv_expiry, channel_htlc_id, payment_hash FROM channel_htlcs WHERE channel_id = ?;", + .query = "SELECT channel_id, direction, cltv_expiry, channel_htlc_id, payment_hash FROM channel_htlcs WHERE channel_id = $1;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "DELETE FROM channel_htlcs WHERE direction = ? AND origin_htlc = ? AND payment_hash = ? AND partid = ?;", + .query = "DELETE FROM channel_htlcs WHERE direction = $1 AND origin_htlc = $2 AND payment_hash = $3 AND partid = $4;", + .placeholders = 4, + .readonly = false, + }, + { + .name = "SELECT status FROM payments WHERE payment_hash=? AND partid = ?;", + .query = "SELECT status FROM payments WHERE payment_hash=$1 AND partid = $2;", + .placeholders = 2, + .readonly = true, + }, + { + .name = "INSERT INTO payments ( status, payment_hash, destination, msatoshi, timestamp, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, total_msat, partid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + .query = "INSERT INTO payments ( status, payment_hash, destination, msatoshi, timestamp, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, total_msat, partid) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);", + .placeholders = 13, + .readonly = false, + }, + { + .name = "DELETE FROM payments WHERE payment_hash = ? AND partid = ?", + .query = "DELETE FROM payments WHERE payment_hash = $1 AND partid = $2", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments WHERE payment_hash = ? AND partid = ?", + .query = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments WHERE payment_hash = $1 AND partid = $2", + .placeholders = 2, + .readonly = true, + }, + { + .name = "UPDATE payments SET status=? WHERE payment_hash=? AND partid=?", + .query = "UPDATE payments SET status=$1 WHERE payment_hash=$2 AND partid=$3", + .placeholders = 3, + .readonly = false, + }, + { + .name = "UPDATE payments SET payment_preimage=? WHERE payment_hash=? AND partid=?", + .query = "UPDATE payments SET payment_preimage=$1 WHERE payment_hash=$2 AND partid=$3", + .placeholders = 3, + .readonly = false, + }, + { + .name = "UPDATE payments SET path_secrets = NULL , route_nodes = NULL , route_channels = NULL WHERE payment_hash = ? AND partid = ?;", + .query = "UPDATE payments SET path_secrets = NULL , route_nodes = NULL , route_channels = NULL WHERE payment_hash = $1 AND partid = $2;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, faildetail, faildirection FROM payments WHERE payment_hash=? AND partid=?;", + .query = "SELECT failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, faildetail, faildirection FROM payments WHERE payment_hash=$1 AND partid=$2;", + .placeholders = 2, + .readonly = true, + }, + { + .name = "UPDATE payments SET failonionreply=? , faildestperm=? , failindex=? , failcode=? , failnode=? , failchannel=? , failupdate=? , faildetail=? , faildirection=? WHERE payment_hash=? AND partid=?;", + .query = "UPDATE payments SET failonionreply=$1 , faildestperm=$2 , failindex=$3 , failcode=$4 , failnode=$5 , failchannel=$6 , failupdate=$7 , faildetail=$8 , faildirection=$9 WHERE payment_hash=$10 AND partid=$11;", + .placeholders = 11, + .readonly = false, + }, + { + .name = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments WHERE payment_hash = ?;", + .query = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments WHERE payment_hash = $1;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments ORDER BY id;", + .query = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments ORDER BY id;", + .placeholders = 0, + .readonly = true, + }, + { + .name = "DELETE FROM htlc_sigs WHERE channelid = ?", + .query = "DELETE FROM htlc_sigs WHERE channelid = $1", + .placeholders = 1, + .readonly = false, + }, + { + .name = "INSERT INTO htlc_sigs (channelid, signature) VALUES (?, ?)", + .query = "INSERT INTO htlc_sigs (channelid, signature) VALUES ($1, $2)", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT blobval FROM vars WHERE name='genesis_hash'", + .query = "SELECT blobval FROM vars WHERE name='genesis_hash'", + .placeholders = 0, + .readonly = true, + }, + { + .name = "INSERT INTO vars (name, blobval) VALUES ('genesis_hash', ?);", + .query = "INSERT INTO vars (name, blobval) VALUES ('genesis_hash', $1);", + .placeholders = 1, + .readonly = false, + }, + { + .name = "SELECT txid, outnum FROM utxoset WHERE spendheight < ?", + .query = "SELECT txid, outnum FROM utxoset WHERE spendheight < $1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "DELETE FROM utxoset WHERE spendheight < ?", + .query = "DELETE FROM utxoset WHERE spendheight < $1", + .placeholders = 1, + .readonly = false, + }, + { + .name = "INSERT INTO blocks (height, hash, prev_hash) VALUES (?, ?, ?);", + .query = "INSERT INTO blocks (height, hash, prev_hash) VALUES ($1, $2, $3);", + .placeholders = 3, + .readonly = false, + }, + { + .name = "DELETE FROM blocks WHERE hash = ?", + .query = "DELETE FROM blocks WHERE hash = $1", + .placeholders = 1, + .readonly = false, + }, + { + .name = "SELECT * FROM blocks WHERE height >= ?;", + .query = "SELECT * FROM blocks WHERE height >= $1;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "DELETE FROM blocks WHERE height > ?", + .query = "DELETE FROM blocks WHERE height > $1", + .placeholders = 1, + .readonly = false, + }, + { + .name = "UPDATE outputs SET spend_height = ? WHERE prev_out_tx = ? AND prev_out_index = ?", + .query = "UPDATE outputs SET spend_height = $1 WHERE prev_out_tx = $2 AND prev_out_index = $3", + .placeholders = 3, + .readonly = false, + }, + { + .name = "UPDATE utxoset SET spendheight = ? WHERE txid = ? AND outnum = ?", + .query = "UPDATE utxoset SET spendheight = $1 WHERE txid = $2 AND outnum = $3", + .placeholders = 3, + .readonly = false, + }, + { + .name = "SELECT blockheight, txindex FROM utxoset WHERE txid = ? AND outnum = ?", + .query = "SELECT blockheight, txindex FROM utxoset WHERE txid = $1 AND outnum = $2", + .placeholders = 2, + .readonly = true, + }, + { + .name = "INSERT INTO utxoset ( txid, outnum, blockheight, spendheight, txindex, scriptpubkey, satoshis) VALUES(?, ?, ?, ?, ?, ?, ?);", + .query = "INSERT INTO utxoset ( txid, outnum, blockheight, spendheight, txindex, scriptpubkey, satoshis) VALUES($1, $2, $3, $4, $5, $6, $7);", + .placeholders = 7, + .readonly = false, + }, + { + .name = "SELECT height FROM blocks WHERE height = ?", + .query = "SELECT height FROM blocks WHERE height = $1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT txid, spendheight, scriptpubkey, satoshis FROM utxoset WHERE blockheight = ? AND txindex = ? AND outnum = ? AND spendheight IS NULL", + .query = "SELECT txid, spendheight, scriptpubkey, satoshis FROM utxoset WHERE blockheight = $1 AND txindex = $2 AND outnum = $3 AND spendheight IS NULL", + .placeholders = 3, + .readonly = true, + }, + { + .name = "SELECT blockheight FROM transactions WHERE id=?", + .query = "SELECT blockheight FROM transactions WHERE id=$1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "INSERT INTO transactions ( id, blockheight, txindex, rawtx) VALUES (?, ?, ?, ?);", + .query = "INSERT INTO transactions ( id, blockheight, txindex, rawtx) VALUES ($1, $2, $3, $4);", + .placeholders = 4, + .readonly = false, + }, + { + .name = "UPDATE transactions SET blockheight = ?, txindex = ? WHERE id = ?", + .query = "UPDATE transactions SET blockheight = $1, txindex = $2 WHERE id = $3", + .placeholders = 3, + .readonly = false, + }, + { + .name = "INSERT INTO transaction_annotations (txid, idx, location, type, channel) VALUES (?, ?, ?, ?, ?) ON CONFLICT(txid,idx) DO NOTHING;", + .query = "INSERT INTO transaction_annotations (txid, idx, location, type, channel) VALUES ($1, $2, $3, $4, $5) ON CONFLICT(txid,idx) DO NOTHING;", + .placeholders = 5, + .readonly = false, + }, + { + .name = "SELECT type, channel_id FROM transactions WHERE id=?", + .query = "SELECT type, channel_id FROM transactions WHERE id=$1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "UPDATE transactions SET type = ?, channel_id = ? WHERE id = ?", + .query = "UPDATE transactions SET type = $1, channel_id = $2 WHERE id = $3", + .placeholders = 3, + .readonly = false, + }, + { + .name = "SELECT type FROM transactions WHERE id=?", + .query = "SELECT type FROM transactions WHERE id=$1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT rawtx FROM transactions WHERE id=?", + .query = "SELECT rawtx FROM transactions WHERE id=$1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT blockheight, txindex FROM transactions WHERE id=?", + .query = "SELECT blockheight, txindex FROM transactions WHERE id=$1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT id FROM transactions WHERE blockheight=?", + .query = "SELECT id FROM transactions WHERE blockheight=$1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "INSERT INTO channeltxs ( channel_id, type, transaction_id, input_num, blockheight) VALUES (?, ?, ?, ?, ?);", + .query = "INSERT INTO channeltxs ( channel_id, type, transaction_id, input_num, blockheight) VALUES ($1, $2, $3, $4, $5);", + .placeholders = 5, + .readonly = false, + }, + { + .name = "SELECT DISTINCT(channel_id) FROM channeltxs WHERE type = ?;", + .query = "SELECT DISTINCT(channel_id) FROM channeltxs WHERE type = $1;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT c.type, c.blockheight, t.rawtx, c.input_num, c.blockheight - t.blockheight + 1 AS depth, t.id as txid FROM channeltxs c JOIN transactions t ON t.id = c.transaction_id WHERE c.channel_id = ? ORDER BY c.id ASC;", + .query = "SELECT c.type, c.blockheight, t.rawtx, c.input_num, c.blockheight - t.blockheight + 1 AS depth, t.id as txid FROM channeltxs c JOIN transactions t ON t.id = c.transaction_id WHERE c.channel_id = $1 ORDER BY c.id ASC;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "UPDATE forwarded_payments SET in_msatoshi=?, out_msatoshi=?, state=?, resolved_time=?, failcode=? WHERE in_htlc_id=?", + .query = "UPDATE forwarded_payments SET in_msatoshi=$1, out_msatoshi=$2, state=$3, resolved_time=$4, failcode=$5 WHERE in_htlc_id=$6", + .placeholders = 6, + .readonly = false, + }, + { + .name = "INSERT INTO forwarded_payments ( in_htlc_id, out_htlc_id, in_channel_scid, out_channel_scid, in_msatoshi, out_msatoshi, state, received_time, resolved_time, failcode) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + .query = "INSERT INTO forwarded_payments ( in_htlc_id, out_htlc_id, in_channel_scid, out_channel_scid, in_msatoshi, out_msatoshi, state, received_time, resolved_time, failcode) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);", + .placeholders = 10, + .readonly = false, + }, + { + .name = "SELECT CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)FROM forwarded_payments WHERE state = ?;", + .query = "SELECT CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)FROM forwarded_payments WHERE state = $1;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT f.state, in_msatoshi, out_msatoshi, hin.payment_hash as payment_hash, in_channel_scid, out_channel_scid, f.received_time, f.resolved_time, f.failcode FROM forwarded_payments f LEFT JOIN channel_htlcs hin ON (f.in_htlc_id = hin.id)", + .query = "SELECT f.state, in_msatoshi, out_msatoshi, hin.payment_hash as payment_hash, in_channel_scid, out_channel_scid, f.received_time, f.resolved_time, f.failcode FROM forwarded_payments f LEFT JOIN channel_htlcs hin ON (f.in_htlc_id = hin.id)", + .placeholders = 0, + .readonly = true, + }, + { + .name = "SELECT t.id, t.rawtx, t.blockheight, t.txindex, t.type as txtype, c2.short_channel_id as txchan, a.location, a.idx as ann_idx, a.type as annotation_type, c.short_channel_id FROM transactions t LEFT JOIN transaction_annotations a ON (a.txid = t.id) LEFT JOIN channels c ON (a.channel = c.id) LEFT JOIN channels c2 ON (t.channel_id = c2.id) ORDER BY t.blockheight, t.txindex ASC", + .query = "SELECT t.id, t.rawtx, t.blockheight, t.txindex, t.type as txtype, c2.short_channel_id as txchan, a.location, a.idx as ann_idx, a.type as annotation_type, c.short_channel_id FROM transactions t LEFT JOIN transaction_annotations a ON (a.txid = t.id) LEFT JOIN channels c ON (a.channel = c.id) LEFT JOIN channels c2 ON (t.channel_id = c2.id) ORDER BY t.blockheight, t.txindex ASC", + .placeholders = 0, + .readonly = true, + }, + { + .name = "INSERT INTO penalty_bases ( channel_id, commitnum, txid, outnum, amount) VALUES (?, ?, ?, ?, ?);", + .query = "INSERT INTO penalty_bases ( channel_id, commitnum, txid, outnum, amount) VALUES ($1, $2, $3, $4, $5);", + .placeholders = 5, + .readonly = false, + }, + { + .name = "SELECT commitnum, txid, outnum, amount FROM penalty_bases WHERE channel_id = ?", + .query = "SELECT commitnum, txid, outnum, amount FROM penalty_bases WHERE channel_id = $1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "DELETE FROM penalty_bases WHERE channel_id = ? AND commitnum = ?", + .query = "DELETE FROM penalty_bases WHERE channel_id = $1 AND commitnum = $2", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT name FROM sqlite_master WHERE type='table';", + .query = "SELECT name FROM sqlite_master WHERE type='table';", + .placeholders = 0, + .readonly = true, + }, + { + .name = "not a valid SQL statement", + .query = "not a valid SQL statement", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO channels (id) VALUES (1);", + .query = "INSERT INTO channels (id) VALUES (1);", + .placeholders = 0, + .readonly = false, + }, +}; + +#define DB_POSTGRES_QUERY_COUNT 271 + +#endif /* HAVE_POSTGRES */ + +#endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */ + +// SHA256STAMP:f6a476ea866c2b76892e49d3633fb9c04616995d9bf6b975a67aab1006106dfb diff --git a/wallet/db_sqlite3_sqlgen.c b/wallet/db_sqlite3_sqlgen.c new file mode 100644 index 000000000..08d517ac6 --- /dev/null +++ b/wallet/db_sqlite3_sqlgen.c @@ -0,0 +1,1645 @@ +#ifndef LIGHTNINGD_WALLET_GEN_DB_SQLITE3 +#define LIGHTNINGD_WALLET_GEN_DB_SQLITE3 + +#include +#include + +#if HAVE_SQLITE3 + +struct db_query db_sqlite3_queries[] = { + + { + .name = "CREATE TABLE version (version INTEGER)", + .query = "CREATE TABLE version (version INTEGER)", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO version VALUES (1)", + .query = "INSERT INTO version VALUES (1)", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE outputs ( prev_out_tx BLOB, prev_out_index INTEGER, value BIGINT, type INTEGER, status INTEGER, keyindex INTEGER, PRIMARY KEY (prev_out_tx, prev_out_index));", + .query = "CREATE TABLE outputs ( prev_out_tx BLOB, prev_out_index INTEGER, value INTEGER, type INTEGER, status INTEGER, keyindex INTEGER, PRIMARY KEY (prev_out_tx, prev_out_index));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE vars ( name VARCHAR(32), val VARCHAR(255), PRIMARY KEY (name));", + .query = "CREATE TABLE vars ( name VARCHAR(32), val VARCHAR(255), PRIMARY KEY (name));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE shachains ( id BIGSERIAL, min_index BIGINT, num_valid BIGINT, PRIMARY KEY (id));", + .query = "CREATE TABLE shachains ( id INTEGER, min_index INTEGER, num_valid INTEGER, PRIMARY KEY (id));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE shachain_known ( shachain_id BIGINT REFERENCES shachains(id) ON DELETE CASCADE, pos INTEGER, idx BIGINT, hash BLOB, PRIMARY KEY (shachain_id, pos));", + .query = "CREATE TABLE shachain_known ( shachain_id INTEGER REFERENCES shachains(id) ON DELETE CASCADE, pos INTEGER, idx INTEGER, hash BLOB, PRIMARY KEY (shachain_id, pos));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE peers ( id BIGSERIAL, node_id BLOB UNIQUE, address TEXT, PRIMARY KEY (id));", + .query = "CREATE TABLE peers ( id INTEGER, node_id BLOB UNIQUE, address TEXT, PRIMARY KEY (id));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE channels ( id BIGSERIAL, peer_id BIGINT REFERENCES peers(id) ON DELETE CASCADE, short_channel_id TEXT, channel_config_local BIGINT, channel_config_remote BIGINT, state INTEGER, funder INTEGER, channel_flags INTEGER, minimum_depth INTEGER, next_index_local BIGINT, next_index_remote BIGINT, next_htlc_id BIGINT, funding_tx_id BLOB, funding_tx_outnum INTEGER, funding_satoshi BIGINT, funding_locked_remote INTEGER, push_msatoshi BIGINT, msatoshi_local BIGINT, fundingkey_remote BLOB, revocation_basepoint_remote BLOB, payment_basepoint_remote BLOB, htlc_basepoint_remote BLOB, delayed_payment_basepoint_remote BLOB, per_commit_remote BLOB, old_per_commit_remote BLOB, local_feerate_per_kw INTEGER, remote_feerate_per_kw INTEGER, shachain_remote_id BIGINT, shutdown_scriptpubkey_remote BLOB, shutdown_keyidx_local BIGINT, last_sent_commit_state BIGINT, last_sent_commit_id INTEGER, last_tx BLOB, last_sig BLOB, closing_fee_received INTEGER, closing_sig_received BLOB, PRIMARY KEY (id));", + .query = "CREATE TABLE channels ( id INTEGER, peer_id INTEGER REFERENCES peers(id) ON DELETE CASCADE, short_channel_id TEXT, channel_config_local INTEGER, channel_config_remote INTEGER, state INTEGER, funder INTEGER, channel_flags INTEGER, minimum_depth INTEGER, next_index_local INTEGER, next_index_remote INTEGER, next_htlc_id INTEGER, funding_tx_id BLOB, funding_tx_outnum INTEGER, funding_satoshi INTEGER, funding_locked_remote INTEGER, push_msatoshi INTEGER, msatoshi_local INTEGER, fundingkey_remote BLOB, revocation_basepoint_remote BLOB, payment_basepoint_remote BLOB, htlc_basepoint_remote BLOB, delayed_payment_basepoint_remote BLOB, per_commit_remote BLOB, old_per_commit_remote BLOB, local_feerate_per_kw INTEGER, remote_feerate_per_kw INTEGER, shachain_remote_id INTEGER, shutdown_scriptpubkey_remote BLOB, shutdown_keyidx_local INTEGER, last_sent_commit_state INTEGER, last_sent_commit_id INTEGER, last_tx BLOB, last_sig BLOB, closing_fee_received INTEGER, closing_sig_received BLOB, PRIMARY KEY (id));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE channel_configs ( id BIGSERIAL, dust_limit_satoshis BIGINT, max_htlc_value_in_flight_msat BIGINT, channel_reserve_satoshis BIGINT, htlc_minimum_msat BIGINT, to_self_delay INTEGER, max_accepted_htlcs INTEGER, PRIMARY KEY (id));", + .query = "CREATE TABLE channel_configs ( id INTEGER, dust_limit_satoshis INTEGER, max_htlc_value_in_flight_msat INTEGER, channel_reserve_satoshis INTEGER, htlc_minimum_msat INTEGER, to_self_delay INTEGER, max_accepted_htlcs INTEGER, PRIMARY KEY (id));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE channel_htlcs ( id BIGSERIAL, channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, channel_htlc_id BIGINT, direction INTEGER, origin_htlc BIGINT, msatoshi BIGINT, cltv_expiry INTEGER, payment_hash BLOB, payment_key BLOB, routing_onion BLOB, failuremsg BLOB, malformed_onion INTEGER, hstate INTEGER, shared_secret BLOB, PRIMARY KEY (id), UNIQUE (channel_id, channel_htlc_id, direction));", + .query = "CREATE TABLE channel_htlcs ( id INTEGER, channel_id INTEGER REFERENCES channels(id) ON DELETE CASCADE, channel_htlc_id INTEGER, direction INTEGER, origin_htlc INTEGER, msatoshi INTEGER, cltv_expiry INTEGER, payment_hash BLOB, payment_key BLOB, routing_onion BLOB, failuremsg BLOB, malformed_onion INTEGER, hstate INTEGER, shared_secret BLOB, PRIMARY KEY (id), UNIQUE (channel_id, channel_htlc_id, direction));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE invoices ( id BIGSERIAL, state INTEGER, msatoshi BIGINT, payment_hash BLOB, payment_key BLOB, label TEXT, PRIMARY KEY (id), UNIQUE (label), UNIQUE (payment_hash));", + .query = "CREATE TABLE invoices ( id INTEGER, state INTEGER, msatoshi INTEGER, payment_hash BLOB, payment_key BLOB, label TEXT, PRIMARY KEY (id), UNIQUE (label), UNIQUE (payment_hash));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE payments ( id BIGSERIAL, timestamp INTEGER, status INTEGER, payment_hash BLOB, direction INTEGER, destination BLOB, msatoshi BIGINT, PRIMARY KEY (id), UNIQUE (payment_hash));", + .query = "CREATE TABLE payments ( id INTEGER, timestamp INTEGER, status INTEGER, payment_hash BLOB, direction INTEGER, destination BLOB, msatoshi INTEGER, PRIMARY KEY (id), UNIQUE (payment_hash));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE invoices ADD expiry_time BIGINT;", + .query = "ALTER TABLE invoices ADD expiry_time INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE invoices SET expiry_time=9223372036854775807;", + .query = "UPDATE invoices SET expiry_time=9223372036854775807;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE invoices ADD pay_index BIGINT;", + .query = "ALTER TABLE invoices ADD pay_index INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE UNIQUE INDEX invoices_pay_index ON invoices(pay_index);", + .query = "CREATE UNIQUE INDEX invoices_pay_index ON invoices(pay_index);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE invoices SET pay_index=id WHERE state=1;", + .query = "UPDATE invoices SET pay_index=id WHERE state=1;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO vars(name, val) VALUES('next_pay_index', COALESCE((SELECT MAX(pay_index) FROM invoices WHERE state=1), 0) + 1 );", + .query = "INSERT INTO vars(name, val) VALUES('next_pay_index', COALESCE((SELECT MAX(pay_index) FROM invoices WHERE state=1), 0) + 1 );", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD first_blocknum BIGINT;", + .query = "ALTER TABLE channels ADD first_blocknum INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channels SET first_blocknum=1 WHERE short_channel_id IS NOT NULL;", + .query = "UPDATE channels SET first_blocknum=1 WHERE short_channel_id IS NOT NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD COLUMN channel_id BIGINT;", + .query = "ALTER TABLE outputs ADD COLUMN channel_id INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD COLUMN peer_id BLOB;", + .query = "ALTER TABLE outputs ADD COLUMN peer_id BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD COLUMN commitment_point BLOB;", + .query = "ALTER TABLE outputs ADD COLUMN commitment_point BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE invoices ADD COLUMN msatoshi_received BIGINT;", + .query = "ALTER TABLE invoices ADD COLUMN msatoshi_received INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE invoices SET msatoshi_received=0 WHERE state=1;", + .query = "UPDATE invoices SET msatoshi_received=0 WHERE state=1;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD COLUMN last_was_revoke INTEGER;", + .query = "ALTER TABLE channels ADD COLUMN last_was_revoke INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments RENAME TO temp_payments;", + .query = "ALTER TABLE payments RENAME TO temp_payments;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE payments ( id BIGSERIAL, timestamp INTEGER, status INTEGER, payment_hash BLOB, destination BLOB, msatoshi BIGINT, PRIMARY KEY (id), UNIQUE (payment_hash));", + .query = "CREATE TABLE payments ( id INTEGER, timestamp INTEGER, status INTEGER, payment_hash BLOB, destination BLOB, msatoshi INTEGER, PRIMARY KEY (id), UNIQUE (payment_hash));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO payments SELECT id, timestamp, status, payment_hash, destination, msatoshi FROM temp_payments WHERE direction=1;", + .query = "INSERT INTO payments SELECT id, timestamp, status, payment_hash, destination, msatoshi FROM temp_payments WHERE direction=1;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "DROP TABLE temp_payments;", + .query = "DROP TABLE temp_payments;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD COLUMN payment_preimage BLOB;", + .query = "ALTER TABLE payments ADD COLUMN payment_preimage BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD COLUMN path_secrets BLOB;", + .query = "ALTER TABLE payments ADD COLUMN path_secrets BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE invoices ADD paid_timestamp BIGINT;", + .query = "ALTER TABLE invoices ADD paid_timestamp INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE invoices SET paid_timestamp = CURRENT_TIMESTAMP() WHERE state = 1;", + .query = "UPDATE invoices SET paid_timestamp = strftime('%s', 'now') WHERE state = 1;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD COLUMN route_nodes BLOB;", + .query = "ALTER TABLE payments ADD COLUMN route_nodes BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD COLUMN route_channels BLOB;", + .query = "ALTER TABLE payments ADD COLUMN route_channels BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE htlc_sigs (channelid INTEGER REFERENCES channels(id) ON DELETE CASCADE, signature BLOB);", + .query = "CREATE TABLE htlc_sigs (channelid INTEGER REFERENCES channels(id) ON DELETE CASCADE, signature BLOB);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE INDEX channel_idx ON htlc_sigs (channelid)", + .query = "CREATE INDEX channel_idx ON htlc_sigs (channelid)", + .placeholders = 0, + .readonly = false, + }, + { + .name = "DELETE FROM channels WHERE state=1", + .query = "DELETE FROM channels WHERE state=1", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE db_upgrades (upgrade_from INTEGER, lightning_version TEXT);", + .query = "CREATE TABLE db_upgrades (upgrade_from INTEGER, lightning_version TEXT);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "DELETE FROM peers WHERE id NOT IN (SELECT peer_id FROM channels);", + .query = "DELETE FROM peers WHERE id NOT IN (SELECT peer_id FROM channels);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channels SET STATE = 8 WHERE state > 8;", + .query = "UPDATE channels SET STATE = 8 WHERE state > 8;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE invoices ADD bolt11 TEXT;", + .query = "ALTER TABLE invoices ADD bolt11 TEXT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE blocks (height INT, hash BLOB, prev_hash BLOB, UNIQUE(height));", + .query = "CREATE TABLE blocks (height INT, hash BLOB, prev_hash BLOB, UNIQUE(height));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD COLUMN confirmation_height INTEGER REFERENCES blocks(height) ON DELETE SET NULL;", + .query = "ALTER TABLE outputs ADD COLUMN confirmation_height INTEGER REFERENCES blocks(height) ON DELETE SET NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD COLUMN spend_height INTEGER REFERENCES blocks(height) ON DELETE SET NULL;", + .query = "ALTER TABLE outputs ADD COLUMN spend_height INTEGER REFERENCES blocks(height) ON DELETE SET NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE INDEX output_height_idx ON outputs (confirmation_height, spend_height);", + .query = "CREATE INDEX output_height_idx ON outputs (confirmation_height, spend_height);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE utxoset ( txid BLOB, outnum INT, blockheight INT REFERENCES blocks(height) ON DELETE CASCADE, spendheight INT REFERENCES blocks(height) ON DELETE SET NULL, txindex INT, scriptpubkey BLOB, satoshis BIGINT, PRIMARY KEY(txid, outnum));", + .query = "CREATE TABLE utxoset ( txid BLOB, outnum INT, blockheight INT REFERENCES blocks(height) ON DELETE CASCADE, spendheight INT REFERENCES blocks(height) ON DELETE SET NULL, txindex INT, scriptpubkey BLOB, satoshis INTEGER, PRIMARY KEY(txid, outnum));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE INDEX short_channel_id ON utxoset (blockheight, txindex, outnum)", + .query = "CREATE INDEX short_channel_id ON utxoset (blockheight, txindex, outnum)", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE INDEX utxoset_spend ON utxoset (spendheight)", + .query = "CREATE INDEX utxoset_spend ON utxoset (spendheight)", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channels SET shutdown_keyidx_local=0 WHERE shutdown_keyidx_local = -1;", + .query = "UPDATE channels SET shutdown_keyidx_local=0 WHERE shutdown_keyidx_local = -1;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD failonionreply BLOB;", + .query = "ALTER TABLE payments ADD failonionreply BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD faildestperm INTEGER;", + .query = "ALTER TABLE payments ADD faildestperm INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD failindex INTEGER;", + .query = "ALTER TABLE payments ADD failindex INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD failcode INTEGER;", + .query = "ALTER TABLE payments ADD failcode INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD failnode BLOB;", + .query = "ALTER TABLE payments ADD failnode BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD failchannel TEXT;", + .query = "ALTER TABLE payments ADD failchannel TEXT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD failupdate BLOB;", + .query = "ALTER TABLE payments ADD failupdate BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE payments SET path_secrets = NULL , route_nodes = NULL , route_channels = NULL WHERE status <> 0;", + .query = "UPDATE payments SET path_secrets = NULL , route_nodes = NULL , route_channels = NULL WHERE status <> 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD in_payments_offered INTEGER DEFAULT 0;", + .query = "ALTER TABLE channels ADD in_payments_offered INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD in_payments_fulfilled INTEGER DEFAULT 0;", + .query = "ALTER TABLE channels ADD in_payments_fulfilled INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD in_msatoshi_offered BIGINT DEFAULT 0;", + .query = "ALTER TABLE channels ADD in_msatoshi_offered INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD in_msatoshi_fulfilled BIGINT DEFAULT 0;", + .query = "ALTER TABLE channels ADD in_msatoshi_fulfilled INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD out_payments_offered INTEGER DEFAULT 0;", + .query = "ALTER TABLE channels ADD out_payments_offered INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD out_payments_fulfilled INTEGER DEFAULT 0;", + .query = "ALTER TABLE channels ADD out_payments_fulfilled INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD out_msatoshi_offered BIGINT DEFAULT 0;", + .query = "ALTER TABLE channels ADD out_msatoshi_offered INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD out_msatoshi_fulfilled BIGINT DEFAULT 0;", + .query = "ALTER TABLE channels ADD out_msatoshi_fulfilled INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channels SET in_payments_offered = 0, in_payments_fulfilled = 0 , in_msatoshi_offered = 0, in_msatoshi_fulfilled = 0 , out_payments_offered = 0, out_payments_fulfilled = 0 , out_msatoshi_offered = 0, out_msatoshi_fulfilled = 0 ;", + .query = "UPDATE channels SET in_payments_offered = 0, in_payments_fulfilled = 0 , in_msatoshi_offered = 0, in_msatoshi_fulfilled = 0 , out_payments_offered = 0, out_payments_fulfilled = 0 , out_msatoshi_offered = 0, out_msatoshi_fulfilled = 0 ;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD msatoshi_sent BIGINT;", + .query = "ALTER TABLE payments ADD msatoshi_sent INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE payments SET msatoshi_sent = msatoshi;", + .query = "UPDATE payments SET msatoshi_sent = msatoshi;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "DELETE FROM utxoset WHERE blockheight IN ( SELECT DISTINCT(blockheight) FROM utxoset LEFT OUTER JOIN blocks on (blockheight = blocks.height) WHERE blocks.hash IS NULL);", + .query = "DELETE FROM utxoset WHERE blockheight IN ( SELECT DISTINCT(blockheight) FROM utxoset LEFT OUTER JOIN blocks on (blockheight = blocks.height) WHERE blocks.hash IS NULL);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD min_possible_feerate INTEGER;", + .query = "ALTER TABLE channels ADD min_possible_feerate INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD max_possible_feerate INTEGER;", + .query = "ALTER TABLE channels ADD max_possible_feerate INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channels SET min_possible_feerate=0, max_possible_feerate=250000;", + .query = "UPDATE channels SET min_possible_feerate=0, max_possible_feerate=250000;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD msatoshi_to_us_min BIGINT;", + .query = "ALTER TABLE channels ADD msatoshi_to_us_min INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD msatoshi_to_us_max BIGINT;", + .query = "ALTER TABLE channels ADD msatoshi_to_us_max INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channels SET msatoshi_to_us_min = msatoshi_local , msatoshi_to_us_max = msatoshi_local ;", + .query = "UPDATE channels SET msatoshi_to_us_min = msatoshi_local , msatoshi_to_us_max = msatoshi_local ;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE transactions ( id BLOB, blockheight INTEGER REFERENCES blocks(height) ON DELETE SET NULL, txindex INTEGER, rawtx BLOB, PRIMARY KEY (id));", + .query = "CREATE TABLE transactions ( id BLOB, blockheight INTEGER REFERENCES blocks(height) ON DELETE SET NULL, txindex INTEGER, rawtx BLOB, PRIMARY KEY (id));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD faildetail TEXT;", + .query = "ALTER TABLE payments ADD faildetail TEXT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE payments SET faildetail = 'unspecified payment failure reason' WHERE status = 2;", + .query = "UPDATE payments SET faildetail = 'unspecified payment failure reason' WHERE status = 2;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE channeltxs ( id BIGSERIAL, channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, type INTEGER, transaction_id BLOB REFERENCES transactions(id) ON DELETE CASCADE, input_num INTEGER, blockheight INTEGER REFERENCES blocks(height) ON DELETE CASCADE, PRIMARY KEY(id));", + .query = "CREATE TABLE channeltxs ( id INTEGER, channel_id INTEGER REFERENCES channels(id) ON DELETE CASCADE, type INTEGER, transaction_id BLOB REFERENCES transactions(id) ON DELETE CASCADE, input_num INTEGER, blockheight INTEGER REFERENCES blocks(height) ON DELETE CASCADE, PRIMARY KEY(id));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "DELETE FROM blocks WHERE height > (SELECT MIN(first_blocknum) FROM channels);", + .query = "DELETE FROM blocks WHERE height > (SELECT MIN(first_blocknum) FROM channels);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO blocks (height) VALUES ((SELECT MIN(first_blocknum) FROM channels)) ON CONFLICT(height) DO NOTHING;", + .query = "INSERT OR IGNORE INTO blocks (height) VALUES ((SELECT MIN(first_blocknum) FROM channels));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "DELETE FROM blocks WHERE height IS NULL;", + .query = "DELETE FROM blocks WHERE height IS NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE invoices ADD description TEXT;", + .query = "ALTER TABLE invoices ADD description TEXT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD description TEXT;", + .query = "ALTER TABLE payments ADD description TEXT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD future_per_commitment_point BLOB;", + .query = "ALTER TABLE channels ADD future_per_commitment_point BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD last_sent_commit BLOB;", + .query = "ALTER TABLE channels ADD last_sent_commit BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE forwarded_payments ( in_htlc_id BIGINT REFERENCES channel_htlcs(id) ON DELETE SET NULL, out_htlc_id BIGINT REFERENCES channel_htlcs(id) ON DELETE SET NULL, in_channel_scid BIGINT, out_channel_scid BIGINT, in_msatoshi BIGINT, out_msatoshi BIGINT, state INTEGER, UNIQUE(in_htlc_id, out_htlc_id));", + .query = "CREATE TABLE forwarded_payments ( in_htlc_id INTEGER REFERENCES channel_htlcs(id) ON DELETE SET NULL, out_htlc_id INTEGER REFERENCES channel_htlcs(id) ON DELETE SET NULL, in_channel_scid INTEGER, out_channel_scid INTEGER, in_msatoshi INTEGER, out_msatoshi INTEGER, state INTEGER, UNIQUE(in_htlc_id, out_htlc_id));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD faildirection INTEGER;", + .query = "ALTER TABLE payments ADD faildirection INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD scriptpubkey BLOB;", + .query = "ALTER TABLE outputs ADD scriptpubkey BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE payments ADD bolt11 TEXT;", + .query = "ALTER TABLE payments ADD bolt11 TEXT;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD feerate_base INTEGER;", + .query = "ALTER TABLE channels ADD feerate_base INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD feerate_ppm INTEGER;", + .query = "ALTER TABLE channels ADD feerate_ppm INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channel_htlcs ADD received_time BIGINT", + .query = "ALTER TABLE channel_htlcs ADD received_time INTEGER", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE forwarded_payments ADD received_time BIGINT", + .query = "ALTER TABLE forwarded_payments ADD received_time INTEGER", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE forwarded_payments ADD resolved_time BIGINT", + .query = "ALTER TABLE forwarded_payments ADD resolved_time INTEGER", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD remote_upfront_shutdown_script BLOB;", + .query = "ALTER TABLE channels ADD remote_upfront_shutdown_script BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE forwarded_payments ADD failcode INTEGER;", + .query = "ALTER TABLE forwarded_payments ADD failcode INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD remote_ann_node_sig BLOB;", + .query = "ALTER TABLE channels ADD remote_ann_node_sig BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD remote_ann_bitcoin_sig BLOB;", + .query = "ALTER TABLE channels ADD remote_ann_bitcoin_sig BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE transactions ADD type BIGINT;", + .query = "ALTER TABLE transactions ADD type INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE transactions ADD channel_id BIGINT;", + .query = "ALTER TABLE transactions ADD channel_id INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channels SET short_channel_id = REPLACE(short_channel_id, ':', 'x') WHERE short_channel_id IS NOT NULL;", + .query = "UPDATE channels SET short_channel_id = REPLACE(short_channel_id, ':', 'x') WHERE short_channel_id IS NOT NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE payments SET failchannel = REPLACE(failchannel, ':', 'x') WHERE failchannel IS NOT NULL;", + .query = "UPDATE payments SET failchannel = REPLACE(failchannel, ':', 'x') WHERE failchannel IS NOT NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD COLUMN option_static_remotekey INTEGER DEFAULT 0;", + .query = "ALTER TABLE channels ADD COLUMN option_static_remotekey INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE vars ADD COLUMN intval INTEGER", + .query = "ALTER TABLE vars ADD COLUMN intval INTEGER", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE vars ADD COLUMN blobval BLOB", + .query = "ALTER TABLE vars ADD COLUMN blobval BLOB", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE vars SET intval = CAST(val AS INTEGER) WHERE name IN ('bip32_max_index', 'last_processed_block', 'next_pay_index')", + .query = "UPDATE vars SET intval = CAST(val AS INTEGER) WHERE name IN ('bip32_max_index', 'last_processed_block', 'next_pay_index')", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE vars SET blobval = CAST(val AS BLOB) WHERE name = 'genesis_hash'", + .query = "UPDATE vars SET blobval = CAST(val AS BLOB) WHERE name = 'genesis_hash'", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE transaction_annotations ( txid BLOB, idx INTEGER, location INTEGER, type INTEGER, channel BIGINT REFERENCES channels(id), UNIQUE(txid, idx));", + .query = "CREATE TABLE transaction_annotations ( txid BLOB, idx INTEGER, location INTEGER, type INTEGER, channel INTEGER REFERENCES channels(id), UNIQUE(txid, idx));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD shutdown_scriptpubkey_local BLOB;", + .query = "ALTER TABLE channels ADD shutdown_scriptpubkey_local BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE forwarded_payments SET received_time=0 WHERE received_time IS NULL;", + .query = "UPDATE forwarded_payments SET received_time=0 WHERE received_time IS NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE invoices ADD COLUMN features BLOB DEFAULT '';", + .query = "ALTER TABLE invoices ADD COLUMN features BLOB DEFAULT '';", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE payments ( id BIGSERIAL, timestamp INTEGER, status INTEGER, payment_hash BLOB, destination BLOB, msatoshi BIGINT, payment_preimage BLOB, path_secrets BLOB, route_nodes BLOB, route_channels BLOB, failonionreply BLOB, faildestperm INTEGER, failindex INTEGER, failcode INTEGER, failnode BLOB, failchannel TEXT, failupdate BLOB, msatoshi_sent BIGINT, faildetail TEXT, description TEXT, faildirection INTEGER, bolt11 TEXT, total_msat BIGINT, partid BIGINT, PRIMARY KEY (id), UNIQUE (payment_hash, partid))", + .query = "CREATE TABLE payments ( id INTEGER, timestamp INTEGER, status INTEGER, payment_hash BLOB, destination BLOB, msatoshi INTEGER, payment_preimage BLOB, path_secrets BLOB, route_nodes BLOB, route_channels BLOB, failonionreply BLOB, faildestperm INTEGER, failindex INTEGER, failcode INTEGER, failnode BLOB, failchannel TEXT, failupdate BLOB, msatoshi_sent INTEGER, faildetail TEXT, description TEXT, faildirection INTEGER, bolt11 TEXT, total_msat INTEGER, partid INTEGER, PRIMARY KEY (id), UNIQUE (payment_hash, partid))", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO payments (id, timestamp, status, payment_hash, destination, msatoshi, payment_preimage, path_secrets, route_nodes, route_channels, failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, msatoshi_sent, faildetail, description, faildirection, bolt11)SELECT id, timestamp, status, payment_hash, destination, msatoshi, payment_preimage, path_secrets, route_nodes, route_channels, failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, msatoshi_sent, faildetail, description, faildirection, bolt11 FROM temp_payments;", + .query = "INSERT INTO payments (id, timestamp, status, payment_hash, destination, msatoshi, payment_preimage, path_secrets, route_nodes, route_channels, failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, msatoshi_sent, faildetail, description, faildirection, bolt11)SELECT id, timestamp, status, payment_hash, destination, msatoshi, payment_preimage, path_secrets, route_nodes, route_channels, failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, msatoshi_sent, faildetail, description, faildirection, bolt11 FROM temp_payments;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE payments SET total_msat = msatoshi;", + .query = "UPDATE payments SET total_msat = msatoshi;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE payments SET partid = 0;", + .query = "UPDATE payments SET partid = 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channel_htlcs ADD partid BIGINT;", + .query = "ALTER TABLE channel_htlcs ADD partid INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channel_htlcs SET partid = 0;", + .query = "UPDATE channel_htlcs SET partid = 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE channel_feerates ( channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, hstate INTEGER, feerate_per_kw INTEGER, UNIQUE (channel_id, hstate));", + .query = "CREATE TABLE channel_feerates ( channel_id INTEGER REFERENCES channels(id) ON DELETE CASCADE, hstate INTEGER, feerate_per_kw INTEGER, UNIQUE (channel_id, hstate));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 4, local_feerate_per_kw FROM channels WHERE funder = 0;", + .query = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 4, local_feerate_per_kw FROM channels WHERE funder = 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 1, remote_feerate_per_kw FROM channels WHERE funder = 0 and local_feerate_per_kw != remote_feerate_per_kw;", + .query = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 1, remote_feerate_per_kw FROM channels WHERE funder = 0 and local_feerate_per_kw != remote_feerate_per_kw;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 14, remote_feerate_per_kw FROM channels WHERE funder = 1;", + .query = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 14, remote_feerate_per_kw FROM channels WHERE funder = 1;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 11, local_feerate_per_kw FROM channels WHERE funder = 1 and local_feerate_per_kw != remote_feerate_per_kw;", + .query = "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 11, local_feerate_per_kw FROM channels WHERE funder = 1 and local_feerate_per_kw != remote_feerate_per_kw;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO vars (name, intval) VALUES ('data_version', 0);", + .query = "INSERT INTO vars (name, intval) VALUES ('data_version', 0);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channel_htlcs ADD localfailmsg BLOB;", + .query = "ALTER TABLE channel_htlcs ADD localfailmsg BLOB;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channel_htlcs SET localfailmsg=decode('2002', 'hex') WHERE malformed_onion != 0 AND direction = 1;", + .query = "UPDATE channel_htlcs SET localfailmsg=x'2002' WHERE malformed_onion != 0 AND direction = 1;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD our_funding_satoshi BIGINT DEFAULT 0;", + .query = "ALTER TABLE channels ADD our_funding_satoshi INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "CREATE TABLE penalty_bases ( channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, commitnum BIGINT, txid BLOB, outnum INTEGER, amount BIGINT, PRIMARY KEY (channel_id, commitnum));", + .query = "CREATE TABLE penalty_bases ( channel_id INTEGER REFERENCES channels(id) ON DELETE CASCADE, commitnum INTEGER, txid BLOB, outnum INTEGER, amount INTEGER, PRIMARY KEY (channel_id, commitnum));", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channel_htlcs ADD we_filled INTEGER;", + .query = "ALTER TABLE channel_htlcs ADD we_filled INTEGER;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO vars (name, intval) VALUES ('coin_moves_count', 0);", + .query = "INSERT INTO vars (name, intval) VALUES ('coin_moves_count', 0);", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD reserved_til INTEGER DEFAULT NULL;", + .query = "ALTER TABLE outputs ADD reserved_til INTEGER DEFAULT NULL;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE channels ADD COLUMN option_anchor_outputs INTEGER DEFAULT 0;", + .query = "ALTER TABLE channels ADD COLUMN option_anchor_outputs INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "ALTER TABLE outputs ADD option_anchor_outputs INTEGER DEFAULT 0;", + .query = "ALTER TABLE outputs ADD option_anchor_outputs INTEGER DEFAULT 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?", + .query = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?", + .placeholders = 1, + .readonly = false, + }, + { + .name = "SELECT version FROM version LIMIT 1", + .query = "SELECT version FROM version LIMIT 1", + .placeholders = 0, + .readonly = true, + }, + { + .name = "UPDATE version SET version=?;", + .query = "UPDATE version SET version=?;", + .placeholders = 1, + .readonly = false, + }, + { + .name = "INSERT INTO db_upgrades VALUES (?, ?);", + .query = "INSERT INTO db_upgrades VALUES (?, ?);", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT intval FROM vars WHERE name = 'data_version'", + .query = "SELECT intval FROM vars WHERE name = 'data_version'", + .placeholders = 0, + .readonly = true, + }, + { + .name = "SELECT intval FROM vars WHERE name= ? LIMIT 1", + .query = "SELECT intval FROM vars WHERE name= ? LIMIT 1", + .placeholders = 1, + .readonly = true, + }, + { + .name = "UPDATE vars SET intval=? WHERE name=?;", + .query = "UPDATE vars SET intval=? WHERE name=?;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "INSERT INTO vars (name, intval) VALUES (?, ?);", + .query = "INSERT INTO vars (name, intval) VALUES (?, ?);", + .placeholders = 2, + .readonly = false, + }, + { + .name = "UPDATE channels SET feerate_base = ?, feerate_ppm = ?;", + .query = "UPDATE channels SET feerate_base = ?, feerate_ppm = ?;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "UPDATE channels SET our_funding_satoshi = funding_satoshi WHERE funder = 0;", + .query = "UPDATE channels SET our_funding_satoshi = funding_satoshi WHERE funder = 0;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "SELECT type, keyindex, prev_out_tx, prev_out_index, channel_id, peer_id, commitment_point FROM outputs WHERE scriptpubkey IS NULL;", + .query = "SELECT type, keyindex, prev_out_tx, prev_out_index, channel_id, peer_id, commitment_point FROM outputs WHERE scriptpubkey IS NULL;", + .placeholders = 0, + .readonly = true, + }, + { + .name = "UPDATE outputs SET scriptpubkey = ? WHERE prev_out_tx = ? AND prev_out_index = ?", + .query = "UPDATE outputs SET scriptpubkey = ? WHERE prev_out_tx = ? AND prev_out_index = ?", + .placeholders = 3, + .readonly = false, + }, + { + .name = "SELECT c.id, p.node_id, c.last_tx, c.funding_satoshi, c.fundingkey_remote, c.last_sig FROM channels c LEFT OUTER JOIN peers p ON p.id = c.peer_id;", + .query = "SELECT c.id, p.node_id, c.last_tx, c.funding_satoshi, c.fundingkey_remote, c.last_sig FROM channels c LEFT OUTER JOIN peers p ON p.id = c.peer_id;", + .placeholders = 0, + .readonly = true, + }, + { + .name = "UPDATE channels SET last_tx = ? WHERE id = ?;", + .query = "UPDATE channels SET last_tx = ? WHERE id = ?;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "UPDATE invoices SET state = ? WHERE state = ? AND expiry_time <= ?;", + .query = "UPDATE invoices SET state = ? WHERE state = ? AND expiry_time <= ?;", + .placeholders = 3, + .readonly = false, + }, + { + .name = "SELECT id FROM invoices WHERE state = ? AND expiry_time <= ?", + .query = "SELECT id FROM invoices WHERE state = ? AND expiry_time <= ?", + .placeholders = 2, + .readonly = true, + }, + { + .name = "SELECT MIN(expiry_time) FROM invoices WHERE state = ?;", + .query = "SELECT MIN(expiry_time) FROM invoices WHERE state = ?;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "INSERT INTO invoices ( payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features) VALUES ( ?, ?, ? , ?, ?, ? , NULL, NULL , NULL, ?, ?, ?);", + .query = "INSERT INTO invoices ( payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features) VALUES ( ?, ?, ? , ?, ?, ? , NULL, NULL , NULL, ?, ?, ?);", + .placeholders = 9, + .readonly = false, + }, + { + .name = "SELECT id FROM invoices WHERE label = ?;", + .query = "SELECT id FROM invoices WHERE label = ?;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT id FROM invoices WHERE payment_hash = ?;", + .query = "SELECT id FROM invoices WHERE payment_hash = ?;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT id FROM invoices WHERE payment_hash = ? AND state = ?;", + .query = "SELECT id FROM invoices WHERE payment_hash = ? AND state = ?;", + .placeholders = 2, + .readonly = true, + }, + { + .name = "DELETE FROM invoices WHERE id=?;", + .query = "DELETE FROM invoices WHERE id=?;", + .placeholders = 1, + .readonly = false, + }, + { + .name = "DELETE FROM invoices WHERE state = ? AND expiry_time <= ?;", + .query = "DELETE FROM invoices WHERE state = ? AND expiry_time <= ?;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices ORDER BY id;", + .query = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices ORDER BY id;", + .placeholders = 0, + .readonly = true, + }, + { + .name = "SELECT state FROM invoices WHERE id = ?;", + .query = "SELECT state FROM invoices WHERE id = ?;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "UPDATE invoices SET state=? , pay_index=? , msatoshi_received=? , paid_timestamp=? WHERE id=?;", + .query = "UPDATE invoices SET state=? , pay_index=? , msatoshi_received=? , paid_timestamp=? WHERE id=?;", + .placeholders = 5, + .readonly = false, + }, + { + .name = "SELECT id FROM invoices WHERE pay_index IS NOT NULL AND pay_index > ? ORDER BY pay_index ASC LIMIT 1;", + .query = "SELECT id FROM invoices WHERE pay_index IS NOT NULL AND pay_index > ? ORDER BY pay_index ASC LIMIT 1;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices WHERE id = ?;", + .query = "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices WHERE id = ?;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT txid, outnum FROM utxoset WHERE spendheight is NULL", + .query = "SELECT txid, outnum FROM utxoset WHERE spendheight is NULL", + .placeholders = 0, + .readonly = true, + }, + { + .name = "SELECT * from outputs WHERE prev_out_tx=? AND prev_out_index=?", + .query = "SELECT * from outputs WHERE prev_out_tx=? AND prev_out_index=?", + .placeholders = 2, + .readonly = true, + }, + { + .name = "INSERT INTO outputs ( prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + .query = "INSERT INTO outputs ( prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + .placeholders = 13, + .readonly = false, + }, + { + .name = "UPDATE outputs SET status=? WHERE status=? AND prev_out_tx=? AND prev_out_index=?", + .query = "UPDATE outputs SET status=? WHERE status=? AND prev_out_tx=? AND prev_out_index=?", + .placeholders = 4, + .readonly = false, + }, + { + .name = "UPDATE outputs SET status=? WHERE prev_out_tx=? AND prev_out_index=?", + .query = "UPDATE outputs SET status=? WHERE prev_out_tx=? AND prev_out_index=?", + .placeholders = 3, + .readonly = false, + }, + { + .name = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs", + .query = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs", + .placeholders = 0, + .readonly = true, + }, + { + .name = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs WHERE status= ? ", + .query = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs WHERE status= ? ", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey, reserved_til FROM outputs WHERE channel_id IS NOT NULL AND confirmation_height IS NULL", + .query = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey, reserved_til FROM outputs WHERE channel_id IS NOT NULL AND confirmation_height IS NULL", + .placeholders = 0, + .readonly = true, + }, + { + .name = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey, reserved_til FROM outputs WHERE prev_out_tx = ? AND prev_out_index = ?", + .query = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey, reserved_til FROM outputs WHERE prev_out_tx = ? AND prev_out_index = ?", + .placeholders = 2, + .readonly = true, + }, + { + .name = "UPDATE outputs SET status=?, reserved_til=?WHERE prev_out_tx=? AND prev_out_index=?", + .query = "UPDATE outputs SET status=?, reserved_til=?WHERE prev_out_tx=? AND prev_out_index=?", + .placeholders = 4, + .readonly = false, + }, + { + .name = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs WHERE status = ? OR (status = ? AND reserved_til <= ?)ORDER BY RANDOM();", + .query = "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs WHERE status = ? OR (status = ? AND reserved_til <= ?)ORDER BY RANDOM();", + .placeholders = 3, + .readonly = true, + }, + { + .name = "INSERT INTO shachains (min_index, num_valid) VALUES (?, 0);", + .query = "INSERT INTO shachains (min_index, num_valid) VALUES (?, 0);", + .placeholders = 1, + .readonly = false, + }, + { + .name = "UPDATE shachains SET num_valid=?, min_index=? WHERE id=?", + .query = "UPDATE shachains SET num_valid=?, min_index=? WHERE id=?", + .placeholders = 3, + .readonly = false, + }, + { + .name = "UPDATE shachain_known SET idx=?, hash=? WHERE shachain_id=? AND pos=?", + .query = "UPDATE shachain_known SET idx=?, hash=? WHERE shachain_id=? AND pos=?", + .placeholders = 4, + .readonly = false, + }, + { + .name = "INSERT INTO shachain_known (shachain_id, pos, idx, hash) VALUES (?, ?, ?, ?);", + .query = "INSERT INTO shachain_known (shachain_id, pos, idx, hash) VALUES (?, ?, ?, ?);", + .placeholders = 4, + .readonly = false, + }, + { + .name = "SELECT min_index, num_valid FROM shachains WHERE id=?", + .query = "SELECT min_index, num_valid FROM shachains WHERE id=?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT idx, hash, pos FROM shachain_known WHERE shachain_id=?", + .query = "SELECT idx, hash, pos FROM shachain_known WHERE shachain_id=?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT id, node_id, address FROM peers WHERE id=?;", + .query = "SELECT id, node_id, address FROM peers WHERE id=?;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT signature FROM htlc_sigs WHERE channelid = ?", + .query = "SELECT signature FROM htlc_sigs WHERE channelid = ?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT remote_ann_node_sig, remote_ann_bitcoin_sig FROM channels WHERE id = ?", + .query = "SELECT remote_ann_node_sig, remote_ann_bitcoin_sig FROM channels WHERE id = ?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT hstate, feerate_per_kw FROM channel_feerates WHERE channel_id = ?", + .query = "SELECT hstate, feerate_per_kw FROM channel_feerates WHERE channel_id = ?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT id FROM channels ORDER BY id DESC LIMIT 1;", + .query = "SELECT id FROM channels ORDER BY id DESC LIMIT 1;", + .placeholders = 0, + .readonly = true, + }, + { + .name = "SELECT id, peer_id, short_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, option_static_remotekey, option_anchor_outputs, shutdown_scriptpubkey_local FROM channels WHERE state < ?;", + .query = "SELECT id, peer_id, short_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, option_static_remotekey, option_anchor_outputs, shutdown_scriptpubkey_local FROM channels WHERE state < ?;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "UPDATE channels SET in_payments_offered = COALESCE(in_payments_offered, 0) + 1 , in_msatoshi_offered = COALESCE(in_msatoshi_offered, 0) + ? WHERE id = ?;", + .query = "UPDATE channels SET in_payments_offered = COALESCE(in_payments_offered, 0) + 1 , in_msatoshi_offered = COALESCE(in_msatoshi_offered, 0) + ? WHERE id = ?;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "UPDATE channels SET in_payments_fulfilled = COALESCE(in_payments_fulfilled, 0) + 1 , in_msatoshi_fulfilled = COALESCE(in_msatoshi_fulfilled, 0) + ? WHERE id = ?;", + .query = "UPDATE channels SET in_payments_fulfilled = COALESCE(in_payments_fulfilled, 0) + 1 , in_msatoshi_fulfilled = COALESCE(in_msatoshi_fulfilled, 0) + ? WHERE id = ?;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "UPDATE channels SET out_payments_offered = COALESCE(out_payments_offered, 0) + 1 , out_msatoshi_offered = COALESCE(out_msatoshi_offered, 0) + ? WHERE id = ?;", + .query = "UPDATE channels SET out_payments_offered = COALESCE(out_payments_offered, 0) + 1 , out_msatoshi_offered = COALESCE(out_msatoshi_offered, 0) + ? WHERE id = ?;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "UPDATE channels SET out_payments_fulfilled = COALESCE(out_payments_fulfilled, 0) + 1 , out_msatoshi_fulfilled = COALESCE(out_msatoshi_fulfilled, 0) + ? WHERE id = ?;", + .query = "UPDATE channels SET out_payments_fulfilled = COALESCE(out_payments_fulfilled, 0) + 1 , out_msatoshi_fulfilled = COALESCE(out_msatoshi_fulfilled, 0) + ? WHERE id = ?;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT in_payments_offered, in_payments_fulfilled, in_msatoshi_offered, in_msatoshi_fulfilled, out_payments_offered, out_payments_fulfilled, out_msatoshi_offered, out_msatoshi_fulfilled FROM channels WHERE id = ?", + .query = "SELECT in_payments_offered, in_payments_fulfilled, in_msatoshi_offered, in_msatoshi_fulfilled, out_payments_offered, out_payments_fulfilled, out_msatoshi_offered, out_msatoshi_fulfilled FROM channels WHERE id = ?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT MIN(height), MAX(height) FROM blocks;", + .query = "SELECT MIN(height), MAX(height) FROM blocks;", + .placeholders = 0, + .readonly = true, + }, + { + .name = "INSERT INTO channel_configs DEFAULT VALUES;", + .query = "INSERT INTO channel_configs DEFAULT VALUES;", + .placeholders = 0, + .readonly = false, + }, + { + .name = "UPDATE channel_configs SET dust_limit_satoshis=?, max_htlc_value_in_flight_msat=?, channel_reserve_satoshis=?, htlc_minimum_msat=?, to_self_delay=?, max_accepted_htlcs=? WHERE id=?;", + .query = "UPDATE channel_configs SET dust_limit_satoshis=?, max_htlc_value_in_flight_msat=?, channel_reserve_satoshis=?, htlc_minimum_msat=?, to_self_delay=?, max_accepted_htlcs=? WHERE id=?;", + .placeholders = 7, + .readonly = false, + }, + { + .name = "SELECT id, dust_limit_satoshis, max_htlc_value_in_flight_msat, channel_reserve_satoshis, htlc_minimum_msat, to_self_delay, max_accepted_htlcs FROM channel_configs WHERE id= ? ;", + .query = "SELECT id, dust_limit_satoshis, max_htlc_value_in_flight_msat, channel_reserve_satoshis, htlc_minimum_msat, to_self_delay, max_accepted_htlcs FROM channel_configs WHERE id= ? ;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "UPDATE channels SET remote_ann_node_sig=?, remote_ann_bitcoin_sig=? WHERE id=?", + .query = "UPDATE channels SET remote_ann_node_sig=?, remote_ann_bitcoin_sig=? WHERE id=?", + .placeholders = 3, + .readonly = false, + }, + { + .name = "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=? WHERE id=?", + .query = "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=? WHERE id=?", + .placeholders = 33, + .readonly = false, + }, + { + .name = "UPDATE channels SET fundingkey_remote=?, revocation_basepoint_remote=?, payment_basepoint_remote=?, htlc_basepoint_remote=?, delayed_payment_basepoint_remote=?, per_commit_remote=?, old_per_commit_remote=?, channel_config_remote=?, future_per_commitment_point=? WHERE id=?", + .query = "UPDATE channels SET fundingkey_remote=?, revocation_basepoint_remote=?, payment_basepoint_remote=?, htlc_basepoint_remote=?, delayed_payment_basepoint_remote=?, per_commit_remote=?, old_per_commit_remote=?, channel_config_remote=?, future_per_commitment_point=? WHERE id=?", + .placeholders = 10, + .readonly = false, + }, + { + .name = "DELETE FROM channel_feerates WHERE channel_id=?", + .query = "DELETE FROM channel_feerates WHERE channel_id=?", + .placeholders = 1, + .readonly = false, + }, + { + .name = "INSERT INTO channel_feerates VALUES(?, ?, ?)", + .query = "INSERT INTO channel_feerates VALUES(?, ?, ?)", + .placeholders = 3, + .readonly = false, + }, + { + .name = "UPDATE channels SET last_sent_commit=? WHERE id=?", + .query = "UPDATE channels SET last_sent_commit=? WHERE id=?", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT id FROM peers WHERE node_id = ?", + .query = "SELECT id FROM peers WHERE node_id = ?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "UPDATE peers SET address = ? WHERE id = ?", + .query = "UPDATE peers SET address = ? WHERE id = ?", + .placeholders = 2, + .readonly = false, + }, + { + .name = "INSERT INTO peers (node_id, address) VALUES (?, ?);", + .query = "INSERT INTO peers (node_id, address) VALUES (?, ?);", + .placeholders = 2, + .readonly = false, + }, + { + .name = "INSERT INTO channels (peer_id, first_blocknum, id) VALUES (?, ?, ?);", + .query = "INSERT INTO channels (peer_id, first_blocknum, id) VALUES (?, ?, ?);", + .placeholders = 3, + .readonly = false, + }, + { + .name = "DELETE FROM channel_htlcs WHERE channel_id=?", + .query = "DELETE FROM channel_htlcs WHERE channel_id=?", + .placeholders = 1, + .readonly = false, + }, + { + .name = "DELETE FROM htlc_sigs WHERE channelid=?", + .query = "DELETE FROM htlc_sigs WHERE channelid=?", + .placeholders = 1, + .readonly = false, + }, + { + .name = "DELETE FROM channeltxs WHERE channel_id=?", + .query = "DELETE FROM channeltxs WHERE channel_id=?", + .placeholders = 1, + .readonly = false, + }, + { + .name = "DELETE FROM shachains WHERE id IN ( SELECT shachain_remote_id FROM channels WHERE channels.id=?)", + .query = "DELETE FROM shachains WHERE id IN ( SELECT shachain_remote_id FROM channels WHERE channels.id=?)", + .placeholders = 1, + .readonly = false, + }, + { + .name = "UPDATE channels SET state=?, peer_id=?WHERE channels.id=?", + .query = "UPDATE channels SET state=?, peer_id=?WHERE channels.id=?", + .placeholders = 3, + .readonly = false, + }, + { + .name = "SELECT * FROM channels WHERE peer_id = ?;", + .query = "SELECT * FROM channels WHERE peer_id = ?;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "DELETE FROM peers WHERE id=?", + .query = "DELETE FROM peers WHERE id=?", + .placeholders = 1, + .readonly = false, + }, + { + .name = "UPDATE outputs SET confirmation_height = ? WHERE prev_out_tx = ?", + .query = "UPDATE outputs SET confirmation_height = ? WHERE prev_out_tx = ?", + .placeholders = 2, + .readonly = false, + }, + { + .name = "INSERT INTO channel_htlcs ( channel_id, channel_htlc_id, direction, msatoshi, cltv_expiry, payment_hash, payment_key, hstate, shared_secret, routing_onion, received_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + .query = "INSERT INTO channel_htlcs ( channel_id, channel_htlc_id, direction, msatoshi, cltv_expiry, payment_hash, payment_key, hstate, shared_secret, routing_onion, received_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + .placeholders = 11, + .readonly = false, + }, + { + .name = "INSERT INTO channel_htlcs ( channel_id, channel_htlc_id, direction, origin_htlc, msatoshi, cltv_expiry, payment_hash, payment_key, hstate, routing_onion, partid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + .query = "INSERT INTO channel_htlcs ( channel_id, channel_htlc_id, direction, origin_htlc, msatoshi, cltv_expiry, payment_hash, payment_key, hstate, routing_onion, partid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + .placeholders = 11, + .readonly = false, + }, + { + .name = "UPDATE channel_htlcs SET hstate=?, payment_key=?, malformed_onion=?, failuremsg=?, localfailmsg=?, we_filled=? WHERE id=?", + .query = "UPDATE channel_htlcs SET hstate=?, payment_key=?, malformed_onion=?, failuremsg=?, localfailmsg=?, we_filled=? WHERE id=?", + .placeholders = 7, + .readonly = false, + }, + { + .name = "SELECT id, channel_htlc_id, msatoshi, cltv_expiry, hstate, payment_hash, payment_key, routing_onion, failuremsg, malformed_onion, origin_htlc, shared_secret, received_time, we_filled FROM channel_htlcs WHERE direction= ? AND channel_id= ? AND hstate != ?", + .query = "SELECT id, channel_htlc_id, msatoshi, cltv_expiry, hstate, payment_hash, payment_key, routing_onion, failuremsg, malformed_onion, origin_htlc, shared_secret, received_time, we_filled FROM channel_htlcs WHERE direction= ? AND channel_id= ? AND hstate != ?", + .placeholders = 3, + .readonly = true, + }, + { + .name = "SELECT id, channel_htlc_id, msatoshi, cltv_expiry, hstate, payment_hash, payment_key, routing_onion, failuremsg, malformed_onion, origin_htlc, shared_secret, received_time, partid, localfailmsg FROM channel_htlcs WHERE direction = ? AND channel_id = ? AND hstate != ?", + .query = "SELECT id, channel_htlc_id, msatoshi, cltv_expiry, hstate, payment_hash, payment_key, routing_onion, failuremsg, malformed_onion, origin_htlc, shared_secret, received_time, partid, localfailmsg FROM channel_htlcs WHERE direction = ? AND channel_id = ? AND hstate != ?", + .placeholders = 3, + .readonly = true, + }, + { + .name = "SELECT channel_id, direction, cltv_expiry, channel_htlc_id, payment_hash FROM channel_htlcs WHERE channel_id = ?;", + .query = "SELECT channel_id, direction, cltv_expiry, channel_htlc_id, payment_hash FROM channel_htlcs WHERE channel_id = ?;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "DELETE FROM channel_htlcs WHERE direction = ? AND origin_htlc = ? AND payment_hash = ? AND partid = ?;", + .query = "DELETE FROM channel_htlcs WHERE direction = ? AND origin_htlc = ? AND payment_hash = ? AND partid = ?;", + .placeholders = 4, + .readonly = false, + }, + { + .name = "SELECT status FROM payments WHERE payment_hash=? AND partid = ?;", + .query = "SELECT status FROM payments WHERE payment_hash=? AND partid = ?;", + .placeholders = 2, + .readonly = true, + }, + { + .name = "INSERT INTO payments ( status, payment_hash, destination, msatoshi, timestamp, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, total_msat, partid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + .query = "INSERT INTO payments ( status, payment_hash, destination, msatoshi, timestamp, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, total_msat, partid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + .placeholders = 13, + .readonly = false, + }, + { + .name = "DELETE FROM payments WHERE payment_hash = ? AND partid = ?", + .query = "DELETE FROM payments WHERE payment_hash = ? AND partid = ?", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments WHERE payment_hash = ? AND partid = ?", + .query = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments WHERE payment_hash = ? AND partid = ?", + .placeholders = 2, + .readonly = true, + }, + { + .name = "UPDATE payments SET status=? WHERE payment_hash=? AND partid=?", + .query = "UPDATE payments SET status=? WHERE payment_hash=? AND partid=?", + .placeholders = 3, + .readonly = false, + }, + { + .name = "UPDATE payments SET payment_preimage=? WHERE payment_hash=? AND partid=?", + .query = "UPDATE payments SET payment_preimage=? WHERE payment_hash=? AND partid=?", + .placeholders = 3, + .readonly = false, + }, + { + .name = "UPDATE payments SET path_secrets = NULL , route_nodes = NULL , route_channels = NULL WHERE payment_hash = ? AND partid = ?;", + .query = "UPDATE payments SET path_secrets = NULL , route_nodes = NULL , route_channels = NULL WHERE payment_hash = ? AND partid = ?;", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, faildetail, faildirection FROM payments WHERE payment_hash=? AND partid=?;", + .query = "SELECT failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, faildetail, faildirection FROM payments WHERE payment_hash=? AND partid=?;", + .placeholders = 2, + .readonly = true, + }, + { + .name = "UPDATE payments SET failonionreply=? , faildestperm=? , failindex=? , failcode=? , failnode=? , failchannel=? , failupdate=? , faildetail=? , faildirection=? WHERE payment_hash=? AND partid=?;", + .query = "UPDATE payments SET failonionreply=? , faildestperm=? , failindex=? , failcode=? , failnode=? , failchannel=? , failupdate=? , faildetail=? , faildirection=? WHERE payment_hash=? AND partid=?;", + .placeholders = 11, + .readonly = false, + }, + { + .name = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments WHERE payment_hash = ?;", + .query = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments WHERE payment_hash = ?;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments ORDER BY id;", + .query = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments ORDER BY id;", + .placeholders = 0, + .readonly = true, + }, + { + .name = "DELETE FROM htlc_sigs WHERE channelid = ?", + .query = "DELETE FROM htlc_sigs WHERE channelid = ?", + .placeholders = 1, + .readonly = false, + }, + { + .name = "INSERT INTO htlc_sigs (channelid, signature) VALUES (?, ?)", + .query = "INSERT INTO htlc_sigs (channelid, signature) VALUES (?, ?)", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT blobval FROM vars WHERE name='genesis_hash'", + .query = "SELECT blobval FROM vars WHERE name='genesis_hash'", + .placeholders = 0, + .readonly = true, + }, + { + .name = "INSERT INTO vars (name, blobval) VALUES ('genesis_hash', ?);", + .query = "INSERT INTO vars (name, blobval) VALUES ('genesis_hash', ?);", + .placeholders = 1, + .readonly = false, + }, + { + .name = "SELECT txid, outnum FROM utxoset WHERE spendheight < ?", + .query = "SELECT txid, outnum FROM utxoset WHERE spendheight < ?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "DELETE FROM utxoset WHERE spendheight < ?", + .query = "DELETE FROM utxoset WHERE spendheight < ?", + .placeholders = 1, + .readonly = false, + }, + { + .name = "INSERT INTO blocks (height, hash, prev_hash) VALUES (?, ?, ?);", + .query = "INSERT INTO blocks (height, hash, prev_hash) VALUES (?, ?, ?);", + .placeholders = 3, + .readonly = false, + }, + { + .name = "DELETE FROM blocks WHERE hash = ?", + .query = "DELETE FROM blocks WHERE hash = ?", + .placeholders = 1, + .readonly = false, + }, + { + .name = "SELECT * FROM blocks WHERE height >= ?;", + .query = "SELECT * FROM blocks WHERE height >= ?;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "DELETE FROM blocks WHERE height > ?", + .query = "DELETE FROM blocks WHERE height > ?", + .placeholders = 1, + .readonly = false, + }, + { + .name = "UPDATE outputs SET spend_height = ? WHERE prev_out_tx = ? AND prev_out_index = ?", + .query = "UPDATE outputs SET spend_height = ? WHERE prev_out_tx = ? AND prev_out_index = ?", + .placeholders = 3, + .readonly = false, + }, + { + .name = "UPDATE utxoset SET spendheight = ? WHERE txid = ? AND outnum = ?", + .query = "UPDATE utxoset SET spendheight = ? WHERE txid = ? AND outnum = ?", + .placeholders = 3, + .readonly = false, + }, + { + .name = "SELECT blockheight, txindex FROM utxoset WHERE txid = ? AND outnum = ?", + .query = "SELECT blockheight, txindex FROM utxoset WHERE txid = ? AND outnum = ?", + .placeholders = 2, + .readonly = true, + }, + { + .name = "INSERT INTO utxoset ( txid, outnum, blockheight, spendheight, txindex, scriptpubkey, satoshis) VALUES(?, ?, ?, ?, ?, ?, ?);", + .query = "INSERT INTO utxoset ( txid, outnum, blockheight, spendheight, txindex, scriptpubkey, satoshis) VALUES(?, ?, ?, ?, ?, ?, ?);", + .placeholders = 7, + .readonly = false, + }, + { + .name = "SELECT height FROM blocks WHERE height = ?", + .query = "SELECT height FROM blocks WHERE height = ?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT txid, spendheight, scriptpubkey, satoshis FROM utxoset WHERE blockheight = ? AND txindex = ? AND outnum = ? AND spendheight IS NULL", + .query = "SELECT txid, spendheight, scriptpubkey, satoshis FROM utxoset WHERE blockheight = ? AND txindex = ? AND outnum = ? AND spendheight IS NULL", + .placeholders = 3, + .readonly = true, + }, + { + .name = "SELECT blockheight FROM transactions WHERE id=?", + .query = "SELECT blockheight FROM transactions WHERE id=?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "INSERT INTO transactions ( id, blockheight, txindex, rawtx) VALUES (?, ?, ?, ?);", + .query = "INSERT INTO transactions ( id, blockheight, txindex, rawtx) VALUES (?, ?, ?, ?);", + .placeholders = 4, + .readonly = false, + }, + { + .name = "UPDATE transactions SET blockheight = ?, txindex = ? WHERE id = ?", + .query = "UPDATE transactions SET blockheight = ?, txindex = ? WHERE id = ?", + .placeholders = 3, + .readonly = false, + }, + { + .name = "INSERT INTO transaction_annotations (txid, idx, location, type, channel) VALUES (?, ?, ?, ?, ?) ON CONFLICT(txid,idx) DO NOTHING;", + .query = "INSERT OR IGNORE INTO transaction_annotations (txid, idx, location, type, channel) VALUES (?, ?, ?, ?, ?);", + .placeholders = 5, + .readonly = false, + }, + { + .name = "SELECT type, channel_id FROM transactions WHERE id=?", + .query = "SELECT type, channel_id FROM transactions WHERE id=?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "UPDATE transactions SET type = ?, channel_id = ? WHERE id = ?", + .query = "UPDATE transactions SET type = ?, channel_id = ? WHERE id = ?", + .placeholders = 3, + .readonly = false, + }, + { + .name = "SELECT type FROM transactions WHERE id=?", + .query = "SELECT type FROM transactions WHERE id=?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT rawtx FROM transactions WHERE id=?", + .query = "SELECT rawtx FROM transactions WHERE id=?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT blockheight, txindex FROM transactions WHERE id=?", + .query = "SELECT blockheight, txindex FROM transactions WHERE id=?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT id FROM transactions WHERE blockheight=?", + .query = "SELECT id FROM transactions WHERE blockheight=?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "INSERT INTO channeltxs ( channel_id, type, transaction_id, input_num, blockheight) VALUES (?, ?, ?, ?, ?);", + .query = "INSERT INTO channeltxs ( channel_id, type, transaction_id, input_num, blockheight) VALUES (?, ?, ?, ?, ?);", + .placeholders = 5, + .readonly = false, + }, + { + .name = "SELECT DISTINCT(channel_id) FROM channeltxs WHERE type = ?;", + .query = "SELECT DISTINCT(channel_id) FROM channeltxs WHERE type = ?;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT c.type, c.blockheight, t.rawtx, c.input_num, c.blockheight - t.blockheight + 1 AS depth, t.id as txid FROM channeltxs c JOIN transactions t ON t.id = c.transaction_id WHERE c.channel_id = ? ORDER BY c.id ASC;", + .query = "SELECT c.type, c.blockheight, t.rawtx, c.input_num, c.blockheight - t.blockheight + 1 AS depth, t.id as txid FROM channeltxs c JOIN transactions t ON t.id = c.transaction_id WHERE c.channel_id = ? ORDER BY c.id ASC;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "UPDATE forwarded_payments SET in_msatoshi=?, out_msatoshi=?, state=?, resolved_time=?, failcode=? WHERE in_htlc_id=?", + .query = "UPDATE forwarded_payments SET in_msatoshi=?, out_msatoshi=?, state=?, resolved_time=?, failcode=? WHERE in_htlc_id=?", + .placeholders = 6, + .readonly = false, + }, + { + .name = "INSERT INTO forwarded_payments ( in_htlc_id, out_htlc_id, in_channel_scid, out_channel_scid, in_msatoshi, out_msatoshi, state, received_time, resolved_time, failcode) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + .query = "INSERT INTO forwarded_payments ( in_htlc_id, out_htlc_id, in_channel_scid, out_channel_scid, in_msatoshi, out_msatoshi, state, received_time, resolved_time, failcode) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + .placeholders = 10, + .readonly = false, + }, + { + .name = "SELECT CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)FROM forwarded_payments WHERE state = ?;", + .query = "SELECT CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS INTEGER)FROM forwarded_payments WHERE state = ?;", + .placeholders = 1, + .readonly = true, + }, + { + .name = "SELECT f.state, in_msatoshi, out_msatoshi, hin.payment_hash as payment_hash, in_channel_scid, out_channel_scid, f.received_time, f.resolved_time, f.failcode FROM forwarded_payments f LEFT JOIN channel_htlcs hin ON (f.in_htlc_id = hin.id)", + .query = "SELECT f.state, in_msatoshi, out_msatoshi, hin.payment_hash as payment_hash, in_channel_scid, out_channel_scid, f.received_time, f.resolved_time, f.failcode FROM forwarded_payments f LEFT JOIN channel_htlcs hin ON (f.in_htlc_id = hin.id)", + .placeholders = 0, + .readonly = true, + }, + { + .name = "SELECT t.id, t.rawtx, t.blockheight, t.txindex, t.type as txtype, c2.short_channel_id as txchan, a.location, a.idx as ann_idx, a.type as annotation_type, c.short_channel_id FROM transactions t LEFT JOIN transaction_annotations a ON (a.txid = t.id) LEFT JOIN channels c ON (a.channel = c.id) LEFT JOIN channels c2 ON (t.channel_id = c2.id) ORDER BY t.blockheight, t.txindex ASC", + .query = "SELECT t.id, t.rawtx, t.blockheight, t.txindex, t.type as txtype, c2.short_channel_id as txchan, a.location, a.idx as ann_idx, a.type as annotation_type, c.short_channel_id FROM transactions t LEFT JOIN transaction_annotations a ON (a.txid = t.id) LEFT JOIN channels c ON (a.channel = c.id) LEFT JOIN channels c2 ON (t.channel_id = c2.id) ORDER BY t.blockheight, t.txindex ASC", + .placeholders = 0, + .readonly = true, + }, + { + .name = "INSERT INTO penalty_bases ( channel_id, commitnum, txid, outnum, amount) VALUES (?, ?, ?, ?, ?);", + .query = "INSERT INTO penalty_bases ( channel_id, commitnum, txid, outnum, amount) VALUES (?, ?, ?, ?, ?);", + .placeholders = 5, + .readonly = false, + }, + { + .name = "SELECT commitnum, txid, outnum, amount FROM penalty_bases WHERE channel_id = ?", + .query = "SELECT commitnum, txid, outnum, amount FROM penalty_bases WHERE channel_id = ?", + .placeholders = 1, + .readonly = true, + }, + { + .name = "DELETE FROM penalty_bases WHERE channel_id = ? AND commitnum = ?", + .query = "DELETE FROM penalty_bases WHERE channel_id = ? AND commitnum = ?", + .placeholders = 2, + .readonly = false, + }, + { + .name = "SELECT name FROM sqlite_master WHERE type='table';", + .query = "SELECT name FROM sqlite_master WHERE type='table';", + .placeholders = 0, + .readonly = true, + }, + { + .name = "not a valid SQL statement", + .query = "not a valid SQL statement", + .placeholders = 0, + .readonly = false, + }, + { + .name = "INSERT INTO channels (id) VALUES (1);", + .query = "INSERT INTO channels (id) VALUES (1);", + .placeholders = 0, + .readonly = false, + }, +}; + +#define DB_SQLITE3_QUERY_COUNT 271 + +#endif /* HAVE_SQLITE3 */ + +#endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */ + +// SHA256STAMP:f6a476ea866c2b76892e49d3633fb9c04616995d9bf6b975a67aab1006106dfb diff --git a/wallet/statements_gettextgen.po b/wallet/statements_gettextgen.po new file mode 100644 index 000000000..f55bcac58 --- /dev/null +++ b/wallet/statements_gettextgen.po @@ -0,0 +1,1084 @@ +#: wallet/db.c:48 +msgid "CREATE TABLE version (version INTEGER)" +msgstr "" + +#: wallet/db.c:49 +msgid "INSERT INTO version VALUES (1)" +msgstr "" + +#: wallet/db.c:50 +msgid "CREATE TABLE outputs ( prev_out_tx BLOB, prev_out_index INTEGER, value BIGINT, type INTEGER, status INTEGER, keyindex INTEGER, PRIMARY KEY (prev_out_tx, prev_out_index));" +msgstr "" + +#: wallet/db.c:59 +msgid "CREATE TABLE vars ( name VARCHAR(32), val VARCHAR(255), PRIMARY KEY (name));" +msgstr "" + +#: wallet/db.c:65 +msgid "CREATE TABLE shachains ( id BIGSERIAL, min_index BIGINT, num_valid BIGINT, PRIMARY KEY (id));" +msgstr "" + +#: wallet/db.c:72 +msgid "CREATE TABLE shachain_known ( shachain_id BIGINT REFERENCES shachains(id) ON DELETE CASCADE, pos INTEGER, idx BIGINT, hash BLOB, PRIMARY KEY (shachain_id, pos));" +msgstr "" + +#: wallet/db.c:80 +msgid "CREATE TABLE peers ( id BIGSERIAL, node_id BLOB UNIQUE, address TEXT, PRIMARY KEY (id));" +msgstr "" + +#: wallet/db.c:87 +msgid "CREATE TABLE channels ( id BIGSERIAL, peer_id BIGINT REFERENCES peers(id) ON DELETE CASCADE, short_channel_id TEXT, channel_config_local BIGINT, channel_config_remote BIGINT, state INTEGER, funder INTEGER, channel_flags INTEGER, minimum_depth INTEGER, next_index_local BIGINT, next_index_remote BIGINT, next_htlc_id BIGINT, funding_tx_id BLOB, funding_tx_outnum INTEGER, funding_satoshi BIGINT, funding_locked_remote INTEGER, push_msatoshi BIGINT, msatoshi_local BIGINT, fundingkey_remote BLOB, revocation_basepoint_remote BLOB, payment_basepoint_remote BLOB, htlc_basepoint_remote BLOB, delayed_payment_basepoint_remote BLOB, per_commit_remote BLOB, old_per_commit_remote BLOB, local_feerate_per_kw INTEGER, remote_feerate_per_kw INTEGER, shachain_remote_id BIGINT, shutdown_scriptpubkey_remote BLOB, shutdown_keyidx_local BIGINT, last_sent_commit_state BIGINT, last_sent_commit_id INTEGER, last_tx BLOB, last_sig BLOB, closing_fee_received INTEGER, closing_sig_received BLOB, PRIMARY KEY (id));" +msgstr "" + +#: wallet/db.c:129 +msgid "CREATE TABLE channel_configs ( id BIGSERIAL, dust_limit_satoshis BIGINT, max_htlc_value_in_flight_msat BIGINT, channel_reserve_satoshis BIGINT, htlc_minimum_msat BIGINT, to_self_delay INTEGER, max_accepted_htlcs INTEGER, PRIMARY KEY (id));" +msgstr "" + +#: wallet/db.c:140 +msgid "CREATE TABLE channel_htlcs ( id BIGSERIAL, channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, channel_htlc_id BIGINT, direction INTEGER, origin_htlc BIGINT, msatoshi BIGINT, cltv_expiry INTEGER, payment_hash BLOB, payment_key BLOB, routing_onion BLOB, failuremsg BLOB, malformed_onion INTEGER, hstate INTEGER, shared_secret BLOB, PRIMARY KEY (id), UNIQUE (channel_id, channel_htlc_id, direction));" +msgstr "" + +#: wallet/db.c:160 +msgid "CREATE TABLE invoices ( id BIGSERIAL, state INTEGER, msatoshi BIGINT, payment_hash BLOB, payment_key BLOB, label TEXT, PRIMARY KEY (id), UNIQUE (label), UNIQUE (payment_hash));" +msgstr "" + +#: wallet/db.c:172 +msgid "CREATE TABLE payments ( id BIGSERIAL, timestamp INTEGER, status INTEGER, payment_hash BLOB, direction INTEGER, destination BLOB, msatoshi BIGINT, PRIMARY KEY (id), UNIQUE (payment_hash));" +msgstr "" + +#: wallet/db.c:185 +msgid "ALTER TABLE invoices ADD expiry_time BIGINT;" +msgstr "" + +#: wallet/db.c:186 +msgid "UPDATE invoices SET expiry_time=9223372036854775807;" +msgstr "" + +#: wallet/db.c:188 +msgid "ALTER TABLE invoices ADD pay_index BIGINT;" +msgstr "" + +#: wallet/db.c:189 +msgid "CREATE UNIQUE INDEX invoices_pay_index ON invoices(pay_index);" +msgstr "" + +#: wallet/db.c:191 +msgid "UPDATE invoices SET pay_index=id WHERE state=1;" +msgstr "" + +#: wallet/db.c:194 +msgid "INSERT INTO vars(name, val) VALUES('next_pay_index', COALESCE((SELECT MAX(pay_index) FROM invoices WHERE state=1), 0) + 1 );" +msgstr "" + +#: wallet/db.c:203 +msgid "ALTER TABLE channels ADD first_blocknum BIGINT;" +msgstr "" + +#: wallet/db.c:204 +msgid "UPDATE channels SET first_blocknum=1 WHERE short_channel_id IS NOT NULL;" +msgstr "" + +#: wallet/db.c:206 +msgid "ALTER TABLE outputs ADD COLUMN channel_id BIGINT;" +msgstr "" + +#: wallet/db.c:207 +msgid "ALTER TABLE outputs ADD COLUMN peer_id BLOB;" +msgstr "" + +#: wallet/db.c:208 +msgid "ALTER TABLE outputs ADD COLUMN commitment_point BLOB;" +msgstr "" + +#: wallet/db.c:209 +msgid "ALTER TABLE invoices ADD COLUMN msatoshi_received BIGINT;" +msgstr "" + +#: wallet/db.c:211 +msgid "UPDATE invoices SET msatoshi_received=0 WHERE state=1;" +msgstr "" + +#: wallet/db.c:212 +msgid "ALTER TABLE channels ADD COLUMN last_was_revoke INTEGER;" +msgstr "" + +#: wallet/db.c:216 wallet/db.c:509 +msgid "ALTER TABLE payments RENAME TO temp_payments;" +msgstr "" + +#: wallet/db.c:217 +msgid "CREATE TABLE payments ( id BIGSERIAL, timestamp INTEGER, status INTEGER, payment_hash BLOB, destination BLOB, msatoshi BIGINT, PRIMARY KEY (id), UNIQUE (payment_hash));" +msgstr "" + +#: wallet/db.c:228 +msgid "INSERT INTO payments SELECT id, timestamp, status, payment_hash, destination, msatoshi FROM temp_payments WHERE direction=1;" +msgstr "" + +#: wallet/db.c:231 wallet/db.c:584 +msgid "DROP TABLE temp_payments;" +msgstr "" + +#: wallet/db.c:233 +msgid "ALTER TABLE payments ADD COLUMN payment_preimage BLOB;" +msgstr "" + +#: wallet/db.c:235 +msgid "ALTER TABLE payments ADD COLUMN path_secrets BLOB;" +msgstr "" + +#: wallet/db.c:238 +msgid "ALTER TABLE invoices ADD paid_timestamp BIGINT;" +msgstr "" + +#: wallet/db.c:239 +msgid "UPDATE invoices SET paid_timestamp = CURRENT_TIMESTAMP() WHERE state = 1;" +msgstr "" + +#: wallet/db.c:247 +msgid "ALTER TABLE payments ADD COLUMN route_nodes BLOB;" +msgstr "" + +#: wallet/db.c:248 +msgid "ALTER TABLE payments ADD COLUMN route_channels BLOB;" +msgstr "" + +#: wallet/db.c:249 +msgid "CREATE TABLE htlc_sigs (channelid INTEGER REFERENCES channels(id) ON DELETE CASCADE, signature BLOB);" +msgstr "" + +#: wallet/db.c:252 +msgid "CREATE INDEX channel_idx ON htlc_sigs (channelid)" +msgstr "" + +#: wallet/db.c:254 +msgid "DELETE FROM channels WHERE state=1" +msgstr "" + +#: wallet/db.c:256 +msgid "CREATE TABLE db_upgrades (upgrade_from INTEGER, lightning_version TEXT);" +msgstr "" + +#: wallet/db.c:260 wallet/db.c:450 +msgid "DELETE FROM peers WHERE id NOT IN (SELECT peer_id FROM channels);" +msgstr "" + +#: wallet/db.c:264 +msgid "UPDATE channels SET STATE = 8 WHERE state > 8;" +msgstr "" + +#: wallet/db.c:266 +msgid "ALTER TABLE invoices ADD bolt11 TEXT;" +msgstr "" + +#: wallet/db.c:270 +msgid "CREATE TABLE blocks (height INT, hash BLOB, prev_hash BLOB, UNIQUE(height));" +msgstr "" + +#: wallet/db.c:280 +msgid "ALTER TABLE outputs ADD COLUMN confirmation_height INTEGER REFERENCES blocks(height) ON DELETE SET NULL;" +msgstr "" + +#: wallet/db.c:283 +msgid "ALTER TABLE outputs ADD COLUMN spend_height INTEGER REFERENCES blocks(height) ON DELETE SET NULL;" +msgstr "" + +#: wallet/db.c:287 +msgid "CREATE INDEX output_height_idx ON outputs (confirmation_height, spend_height);" +msgstr "" + +#: wallet/db.c:290 +msgid "CREATE TABLE utxoset ( txid BLOB, outnum INT, blockheight INT REFERENCES blocks(height) ON DELETE CASCADE, spendheight INT REFERENCES blocks(height) ON DELETE SET NULL, txindex INT, scriptpubkey BLOB, satoshis BIGINT, PRIMARY KEY(txid, outnum));" +msgstr "" + +#: wallet/db.c:300 +msgid "CREATE INDEX short_channel_id ON utxoset (blockheight, txindex, outnum)" +msgstr "" + +#: wallet/db.c:305 +msgid "CREATE INDEX utxoset_spend ON utxoset (spendheight)" +msgstr "" + +#: wallet/db.c:307 +msgid "UPDATE channels SET shutdown_keyidx_local=0 WHERE shutdown_keyidx_local = -1;" +msgstr "" + +#: wallet/db.c:313 +msgid "ALTER TABLE payments ADD failonionreply BLOB;" +msgstr "" + +#: wallet/db.c:315 +msgid "ALTER TABLE payments ADD faildestperm INTEGER;" +msgstr "" + +#: wallet/db.c:317 +msgid "ALTER TABLE payments ADD failindex INTEGER;" +msgstr "" + +#: wallet/db.c:319 +msgid "ALTER TABLE payments ADD failcode INTEGER;" +msgstr "" + +#: wallet/db.c:320 +msgid "ALTER TABLE payments ADD failnode BLOB;" +msgstr "" + +#: wallet/db.c:321 +msgid "ALTER TABLE payments ADD failchannel TEXT;" +msgstr "" + +#: wallet/db.c:323 +msgid "ALTER TABLE payments ADD failupdate BLOB;" +msgstr "" + +#: wallet/db.c:327 +msgid "UPDATE payments SET path_secrets = NULL , route_nodes = NULL , route_channels = NULL WHERE status <> 0;" +msgstr "" + +#: wallet/db.c:334 +msgid "ALTER TABLE channels ADD in_payments_offered INTEGER DEFAULT 0;" +msgstr "" + +#: wallet/db.c:335 +msgid "ALTER TABLE channels ADD in_payments_fulfilled INTEGER DEFAULT 0;" +msgstr "" + +#: wallet/db.c:336 +msgid "ALTER TABLE channels ADD in_msatoshi_offered BIGINT DEFAULT 0;" +msgstr "" + +#: wallet/db.c:337 +msgid "ALTER TABLE channels ADD in_msatoshi_fulfilled BIGINT DEFAULT 0;" +msgstr "" + +#: wallet/db.c:338 +msgid "ALTER TABLE channels ADD out_payments_offered INTEGER DEFAULT 0;" +msgstr "" + +#: wallet/db.c:339 +msgid "ALTER TABLE channels ADD out_payments_fulfilled INTEGER DEFAULT 0;" +msgstr "" + +#: wallet/db.c:340 +msgid "ALTER TABLE channels ADD out_msatoshi_offered BIGINT DEFAULT 0;" +msgstr "" + +#: wallet/db.c:341 +msgid "ALTER TABLE channels ADD out_msatoshi_fulfilled BIGINT DEFAULT 0;" +msgstr "" + +#: wallet/db.c:342 +msgid "UPDATE channels SET in_payments_offered = 0, in_payments_fulfilled = 0 , in_msatoshi_offered = 0, in_msatoshi_fulfilled = 0 , out_payments_offered = 0, out_payments_fulfilled = 0 , out_msatoshi_offered = 0, out_msatoshi_fulfilled = 0 ;" +msgstr "" + +#: wallet/db.c:351 +msgid "ALTER TABLE payments ADD msatoshi_sent BIGINT;" +msgstr "" + +#: wallet/db.c:352 +msgid "UPDATE payments SET msatoshi_sent = msatoshi;" +msgstr "" + +#: wallet/db.c:354 +msgid "DELETE FROM utxoset WHERE blockheight IN ( SELECT DISTINCT(blockheight) FROM utxoset LEFT OUTER JOIN blocks on (blockheight = blocks.height) WHERE blocks.hash IS NULL);" +msgstr "" + +#: wallet/db.c:362 +msgid "ALTER TABLE channels ADD min_possible_feerate INTEGER;" +msgstr "" + +#: wallet/db.c:363 +msgid "ALTER TABLE channels ADD max_possible_feerate INTEGER;" +msgstr "" + +#: wallet/db.c:366 +msgid "UPDATE channels SET min_possible_feerate=0, max_possible_feerate=250000;" +msgstr "" + +#: wallet/db.c:370 +msgid "ALTER TABLE channels ADD msatoshi_to_us_min BIGINT;" +msgstr "" + +#: wallet/db.c:371 +msgid "ALTER TABLE channels ADD msatoshi_to_us_max BIGINT;" +msgstr "" + +#: wallet/db.c:372 +msgid "UPDATE channels SET msatoshi_to_us_min = msatoshi_local , msatoshi_to_us_max = msatoshi_local ;" +msgstr "" + +#: wallet/db.c:381 +msgid "CREATE TABLE transactions ( id BLOB, blockheight INTEGER REFERENCES blocks(height) ON DELETE SET NULL, txindex INTEGER, rawtx BLOB, PRIMARY KEY (id));" +msgstr "" + +#: wallet/db.c:390 +msgid "ALTER TABLE payments ADD faildetail TEXT;" +msgstr "" + +#: wallet/db.c:391 +msgid "UPDATE payments SET faildetail = 'unspecified payment failure reason' WHERE status = 2;" +msgstr "" + +#: wallet/db.c:396 +msgid "CREATE TABLE channeltxs ( id BIGSERIAL, channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, type INTEGER, transaction_id BLOB REFERENCES transactions(id) ON DELETE CASCADE, input_num INTEGER, blockheight INTEGER REFERENCES blocks(height) ON DELETE CASCADE, PRIMARY KEY(id));" +msgstr "" + +#: wallet/db.c:412 +msgid "DELETE FROM blocks WHERE height > (SELECT MIN(first_blocknum) FROM channels);" +msgstr "" + +#: wallet/db.c:418 +msgid "INSERT INTO blocks (height) VALUES ((SELECT MIN(first_blocknum) FROM channels)) ON CONFLICT(height) DO NOTHING;" +msgstr "" + +#: wallet/db.c:422 +msgid "DELETE FROM blocks WHERE height IS NULL;" +msgstr "" + +#: wallet/db.c:424 +msgid "ALTER TABLE invoices ADD description TEXT;" +msgstr "" + +#: wallet/db.c:426 +msgid "ALTER TABLE payments ADD description TEXT;" +msgstr "" + +#: wallet/db.c:428 +msgid "ALTER TABLE channels ADD future_per_commitment_point BLOB;" +msgstr "" + +#: wallet/db.c:430 +msgid "ALTER TABLE channels ADD last_sent_commit BLOB;" +msgstr "" + +#: wallet/db.c:435 +msgid "CREATE TABLE forwarded_payments ( in_htlc_id BIGINT REFERENCES channel_htlcs(id) ON DELETE SET NULL, out_htlc_id BIGINT REFERENCES channel_htlcs(id) ON DELETE SET NULL, in_channel_scid BIGINT, out_channel_scid BIGINT, in_msatoshi BIGINT, out_msatoshi BIGINT, state INTEGER, UNIQUE(in_htlc_id, out_htlc_id));" +msgstr "" + +#: wallet/db.c:447 +msgid "ALTER TABLE payments ADD faildirection INTEGER;" +msgstr "" + +#: wallet/db.c:452 +msgid "ALTER TABLE outputs ADD scriptpubkey BLOB;" +msgstr "" + +#: wallet/db.c:454 +msgid "ALTER TABLE payments ADD bolt11 TEXT;" +msgstr "" + +#: wallet/db.c:456 +msgid "ALTER TABLE channels ADD feerate_base INTEGER;" +msgstr "" + +#: wallet/db.c:457 +msgid "ALTER TABLE channels ADD feerate_ppm INTEGER;" +msgstr "" + +#: wallet/db.c:459 +msgid "ALTER TABLE channel_htlcs ADD received_time BIGINT" +msgstr "" + +#: wallet/db.c:460 +msgid "ALTER TABLE forwarded_payments ADD received_time BIGINT" +msgstr "" + +#: wallet/db.c:461 +msgid "ALTER TABLE forwarded_payments ADD resolved_time BIGINT" +msgstr "" + +#: wallet/db.c:462 +msgid "ALTER TABLE channels ADD remote_upfront_shutdown_script BLOB;" +msgstr "" + +#: wallet/db.c:465 +msgid "ALTER TABLE forwarded_payments ADD failcode INTEGER;" +msgstr "" + +#: wallet/db.c:467 +msgid "ALTER TABLE channels ADD remote_ann_node_sig BLOB;" +msgstr "" + +#: wallet/db.c:468 +msgid "ALTER TABLE channels ADD remote_ann_bitcoin_sig BLOB;" +msgstr "" + +#: wallet/db.c:470 +msgid "ALTER TABLE transactions ADD type BIGINT;" +msgstr "" + +#: wallet/db.c:475 +msgid "ALTER TABLE transactions ADD channel_id BIGINT;" +msgstr "" + +#: wallet/db.c:477 +msgid "UPDATE channels SET short_channel_id = REPLACE(short_channel_id, ':', 'x') WHERE short_channel_id IS NOT NULL;" +msgstr "" + +#: wallet/db.c:480 +msgid "UPDATE payments SET failchannel = REPLACE(failchannel, ':', 'x') WHERE failchannel IS NOT NULL;" +msgstr "" + +#: wallet/db.c:483 +msgid "ALTER TABLE channels ADD COLUMN option_static_remotekey INTEGER DEFAULT 0;" +msgstr "" + +#: wallet/db.c:485 +msgid "ALTER TABLE vars ADD COLUMN intval INTEGER" +msgstr "" + +#: wallet/db.c:486 +msgid "ALTER TABLE vars ADD COLUMN blobval BLOB" +msgstr "" + +#: wallet/db.c:487 +msgid "UPDATE vars SET intval = CAST(val AS INTEGER) WHERE name IN ('bip32_max_index', 'last_processed_block', 'next_pay_index')" +msgstr "" + +#: wallet/db.c:488 +msgid "UPDATE vars SET blobval = CAST(val AS BLOB) WHERE name = 'genesis_hash'" +msgstr "" + +#: wallet/db.c:489 +msgid "CREATE TABLE transaction_annotations ( txid BLOB, idx INTEGER, location INTEGER, type INTEGER, channel BIGINT REFERENCES channels(id), UNIQUE(txid, idx));" +msgstr "" + +#: wallet/db.c:501 +msgid "ALTER TABLE channels ADD shutdown_scriptpubkey_local BLOB;" +msgstr "" + +#: wallet/db.c:504 +msgid "UPDATE forwarded_payments SET received_time=0 WHERE received_time IS NULL;" +msgstr "" + +#: wallet/db.c:506 +msgid "ALTER TABLE invoices ADD COLUMN features BLOB DEFAULT '';" +msgstr "" + +#: wallet/db.c:510 +msgid "CREATE TABLE payments ( id BIGSERIAL, timestamp INTEGER, status INTEGER, payment_hash BLOB, destination BLOB, msatoshi BIGINT, payment_preimage BLOB, path_secrets BLOB, route_nodes BLOB, route_channels BLOB, failonionreply BLOB, faildestperm INTEGER, failindex INTEGER, failcode INTEGER, failnode BLOB, failchannel TEXT, failupdate BLOB, msatoshi_sent BIGINT, faildetail TEXT, description TEXT, faildirection INTEGER, bolt11 TEXT, total_msat BIGINT, partid BIGINT, PRIMARY KEY (id), UNIQUE (payment_hash, partid))" +msgstr "" + +#: wallet/db.c:537 +msgid "INSERT INTO payments (id, timestamp, status, payment_hash, destination, msatoshi, payment_preimage, path_secrets, route_nodes, route_channels, failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, msatoshi_sent, faildetail, description, faildirection, bolt11)SELECT id, timestamp, status, payment_hash, destination, msatoshi, payment_preimage, path_secrets, route_nodes, route_channels, failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, msatoshi_sent, faildetail, description, faildirection, bolt11 FROM temp_payments;" +msgstr "" + +#: wallet/db.c:582 +msgid "UPDATE payments SET total_msat = msatoshi;" +msgstr "" + +#: wallet/db.c:583 +msgid "UPDATE payments SET partid = 0;" +msgstr "" + +#: wallet/db.c:585 +msgid "ALTER TABLE channel_htlcs ADD partid BIGINT;" +msgstr "" + +#: wallet/db.c:586 +msgid "UPDATE channel_htlcs SET partid = 0;" +msgstr "" + +#: wallet/db.c:587 +msgid "CREATE TABLE channel_feerates ( channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, hstate INTEGER, feerate_per_kw INTEGER, UNIQUE (channel_id, hstate));" +msgstr "" + +#: wallet/db.c:598 +msgid "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 4, local_feerate_per_kw FROM channels WHERE funder = 0;" +msgstr "" + +#: wallet/db.c:602 +msgid "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 1, remote_feerate_per_kw FROM channels WHERE funder = 0 and local_feerate_per_kw != remote_feerate_per_kw;" +msgstr "" + +#: wallet/db.c:607 +msgid "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 14, remote_feerate_per_kw FROM channels WHERE funder = 1;" +msgstr "" + +#: wallet/db.c:611 +msgid "INSERT INTO channel_feerates(channel_id, hstate, feerate_per_kw) SELECT id, 11, local_feerate_per_kw FROM channels WHERE funder = 1 and local_feerate_per_kw != remote_feerate_per_kw;" +msgstr "" + +#: wallet/db.c:615 +msgid "INSERT INTO vars (name, intval) VALUES ('data_version', 0);" +msgstr "" + +#: wallet/db.c:618 +msgid "ALTER TABLE channel_htlcs ADD localfailmsg BLOB;" +msgstr "" + +#: wallet/db.c:619 +msgid "UPDATE channel_htlcs SET localfailmsg=decode('2002', 'hex') WHERE malformed_onion != 0 AND direction = 1;" +msgstr "" + +#: wallet/db.c:620 +msgid "ALTER TABLE channels ADD our_funding_satoshi BIGINT DEFAULT 0;" +msgstr "" + +#: wallet/db.c:621 +msgid "CREATE TABLE penalty_bases ( channel_id BIGINT REFERENCES channels(id) ON DELETE CASCADE, commitnum BIGINT, txid BLOB, outnum INTEGER, amount BIGINT, PRIMARY KEY (channel_id, commitnum));" +msgstr "" + +#: wallet/db.c:631 +msgid "ALTER TABLE channel_htlcs ADD we_filled INTEGER;" +msgstr "" + +#: wallet/db.c:633 +msgid "INSERT INTO vars (name, intval) VALUES ('coin_moves_count', 0);" +msgstr "" + +#: wallet/db.c:635 +msgid "ALTER TABLE outputs ADD reserved_til INTEGER DEFAULT NULL;" +msgstr "" + +#: wallet/db.c:638 +msgid "ALTER TABLE channels ADD COLUMN option_anchor_outputs INTEGER DEFAULT 0;" +msgstr "" + +#: wallet/db.c:641 +msgid "ALTER TABLE outputs ADD option_anchor_outputs INTEGER DEFAULT 0;" +msgstr "" + +#: wallet/db.c:869 +msgid "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?" +msgstr "" + +#: wallet/db.c:969 +msgid "SELECT version FROM version LIMIT 1" +msgstr "" + +#: wallet/db.c:1027 +msgid "UPDATE version SET version=?;" +msgstr "" + +#: wallet/db.c:1035 +msgid "INSERT INTO db_upgrades VALUES (?, ?);" +msgstr "" + +#: wallet/db.c:1047 +msgid "SELECT intval FROM vars WHERE name = 'data_version'" +msgstr "" + +#: wallet/db.c:1074 +msgid "SELECT intval FROM vars WHERE name= ? LIMIT 1" +msgstr "" + +#: wallet/db.c:1090 +msgid "UPDATE vars SET intval=? WHERE name=?;" +msgstr "" + +#: wallet/db.c:1099 +msgid "INSERT INTO vars (name, intval) VALUES (?, ?);" +msgstr "" + +#: wallet/db.c:1113 +msgid "UPDATE channels SET feerate_base = ?, feerate_ppm = ?;" +msgstr "" + +#: wallet/db.c:1134 +msgid "UPDATE channels SET our_funding_satoshi = funding_satoshi WHERE funder = 0;" +msgstr "" + +#: wallet/db.c:1150 +msgid "SELECT type, keyindex, prev_out_tx, prev_out_index, channel_id, peer_id, commitment_point FROM outputs WHERE scriptpubkey IS NULL;" +msgstr "" + +#: wallet/db.c:1212 +msgid "UPDATE outputs SET scriptpubkey = ? WHERE prev_out_tx = ? AND prev_out_index = ?" +msgstr "" + +#: wallet/db.c:1236 +msgid "SELECT c.id, p.node_id, c.last_tx, c.funding_satoshi, c.fundingkey_remote, c.last_sig FROM channels c LEFT OUTER JOIN peers p ON p.id = c.peer_id;" +msgstr "" + +#: wallet/db.c:1302 +msgid "UPDATE channels SET last_tx = ? WHERE id = ?;" +msgstr "" + +#: wallet/invoices.c:129 +msgid "UPDATE invoices SET state = ? WHERE state = ? AND expiry_time <= ?;" +msgstr "" + +#: wallet/invoices.c:177 +msgid "SELECT id FROM invoices WHERE state = ? AND expiry_time <= ?" +msgstr "" + +#: wallet/invoices.c:216 +msgid "SELECT MIN(expiry_time) FROM invoices WHERE state = ?;" +msgstr "" + +#: wallet/invoices.c:282 +msgid "INSERT INTO invoices ( payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features) VALUES ( ?, ?, ? , ?, ?, ? , NULL, NULL , NULL, ?, ?, ?);" +msgstr "" + +#: wallet/invoices.c:330 +msgid "SELECT id FROM invoices WHERE label = ?;" +msgstr "" + +#: wallet/invoices.c:352 +msgid "SELECT id FROM invoices WHERE payment_hash = ?;" +msgstr "" + +#: wallet/invoices.c:373 +msgid "SELECT id FROM invoices WHERE payment_hash = ? AND state = ?;" +msgstr "" + +#: wallet/invoices.c:397 +msgid "DELETE FROM invoices WHERE id=?;" +msgstr "" + +#: wallet/invoices.c:417 +msgid "DELETE FROM invoices WHERE state = ? AND expiry_time <= ?;" +msgstr "" + +#: wallet/invoices.c:431 +msgid "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices ORDER BY id;" +msgstr "" + +#: wallet/invoices.c:488 +msgid "SELECT state FROM invoices WHERE id = ?;" +msgstr "" + +#: wallet/invoices.c:515 +msgid "UPDATE invoices SET state=? , pay_index=? , msatoshi_received=? , paid_timestamp=? WHERE id=?;" +msgstr "" + +#: wallet/invoices.c:571 +msgid "SELECT id FROM invoices WHERE pay_index IS NOT NULL AND pay_index > ? ORDER BY pay_index ASC LIMIT 1;" +msgstr "" + +#: wallet/invoices.c:620 +msgid "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices WHERE id = ?;" +msgstr "" + +#: wallet/wallet.c:50 +msgid "SELECT txid, outnum FROM utxoset WHERE spendheight is NULL" +msgstr "" + +#: wallet/wallet.c:92 wallet/wallet.c:595 +msgid "SELECT * from outputs WHERE prev_out_tx=? AND prev_out_index=?" +msgstr "" + +#: wallet/wallet.c:106 wallet/wallet.c:609 +msgid "INSERT INTO outputs ( prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" +msgstr "" + +#: wallet/wallet.c:227 +msgid "UPDATE outputs SET status=? WHERE status=? AND prev_out_tx=? AND prev_out_index=?" +msgstr "" + +#: wallet/wallet.c:235 +msgid "UPDATE outputs SET status=? WHERE prev_out_tx=? AND prev_out_index=?" +msgstr "" + +#: wallet/wallet.c:254 +msgid "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs" +msgstr "" + +#: wallet/wallet.c:271 +msgid "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs WHERE status= ? " +msgstr "" + +#: wallet/wallet.c:309 +msgid "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey, reserved_til FROM outputs WHERE channel_id IS NOT NULL AND confirmation_height IS NULL" +msgstr "" + +#: wallet/wallet.c:346 +msgid "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey, reserved_til FROM outputs WHERE prev_out_tx = ? AND prev_out_index = ?" +msgstr "" + +#: wallet/wallet.c:438 +msgid "UPDATE outputs SET status=?, reserved_til=?WHERE prev_out_tx=? AND prev_out_index=?" +msgstr "" + +#: wallet/wallet.c:544 +msgid "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs WHERE status = ? OR (status = ? AND reserved_til <= ?)ORDER BY RANDOM();" +msgstr "" + +#: wallet/wallet.c:882 +msgid "INSERT INTO shachains (min_index, num_valid) VALUES (?, 0);" +msgstr "" + +#: wallet/wallet.c:926 +msgid "UPDATE shachains SET num_valid=?, min_index=? WHERE id=?" +msgstr "" + +#: wallet/wallet.c:933 +msgid "UPDATE shachain_known SET idx=?, hash=? WHERE shachain_id=? AND pos=?" +msgstr "" + +#: wallet/wallet.c:945 +msgid "INSERT INTO shachain_known (shachain_id, pos, idx, hash) VALUES (?, ?, ?, ?);" +msgstr "" + +#: wallet/wallet.c:967 +msgid "SELECT min_index, num_valid FROM shachains WHERE id=?" +msgstr "" + +#: wallet/wallet.c:982 +msgid "SELECT idx, hash, pos FROM shachain_known WHERE shachain_id=?" +msgstr "" + +#: wallet/wallet.c:1005 +msgid "SELECT id, node_id, address FROM peers WHERE id=?;" +msgstr "" + +#: wallet/wallet.c:1036 +msgid "SELECT signature FROM htlc_sigs WHERE channelid = ?" +msgstr "" + +#: wallet/wallet.c:1070 +msgid "SELECT remote_ann_node_sig, remote_ann_bitcoin_sig FROM channels WHERE id = ?" +msgstr "" + +#: wallet/wallet.c:1114 +msgid "SELECT hstate, feerate_per_kw FROM channel_feerates WHERE channel_id = ?" +msgstr "" + +#: wallet/wallet.c:1319 +msgid "SELECT id FROM channels ORDER BY id DESC LIMIT 1;" +msgstr "" + +#: wallet/wallet.c:1336 +msgid "SELECT id, peer_id, short_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, option_static_remotekey, option_anchor_outputs, shutdown_scriptpubkey_local FROM channels WHERE state < ?;" +msgstr "" + +#: wallet/wallet.c:1424 +msgid "UPDATE channels SET in_payments_offered = COALESCE(in_payments_offered, 0) + 1 , in_msatoshi_offered = COALESCE(in_msatoshi_offered, 0) + ? WHERE id = ?;" +msgstr "" + +#: wallet/wallet.c:1429 +msgid "UPDATE channels SET in_payments_fulfilled = COALESCE(in_payments_fulfilled, 0) + 1 , in_msatoshi_fulfilled = COALESCE(in_msatoshi_fulfilled, 0) + ? WHERE id = ?;" +msgstr "" + +#: wallet/wallet.c:1434 +msgid "UPDATE channels SET out_payments_offered = COALESCE(out_payments_offered, 0) + 1 , out_msatoshi_offered = COALESCE(out_msatoshi_offered, 0) + ? WHERE id = ?;" +msgstr "" + +#: wallet/wallet.c:1439 +msgid "UPDATE channels SET out_payments_fulfilled = COALESCE(out_payments_fulfilled, 0) + 1 , out_msatoshi_fulfilled = COALESCE(out_msatoshi_fulfilled, 0) + ? WHERE id = ?;" +msgstr "" + +#: wallet/wallet.c:1481 +msgid "SELECT in_payments_offered, in_payments_fulfilled, in_msatoshi_offered, in_msatoshi_fulfilled, out_payments_offered, out_payments_fulfilled, out_msatoshi_offered, out_msatoshi_fulfilled FROM channels WHERE id = ?" +msgstr "" + +#: wallet/wallet.c:1510 +msgid "SELECT MIN(height), MAX(height) FROM blocks;" +msgstr "" + +#: wallet/wallet.c:1532 +msgid "INSERT INTO channel_configs DEFAULT VALUES;" +msgstr "" + +#: wallet/wallet.c:1544 +msgid "UPDATE channel_configs SET dust_limit_satoshis=?, max_htlc_value_in_flight_msat=?, channel_reserve_satoshis=?, htlc_minimum_msat=?, to_self_delay=?, max_accepted_htlcs=? WHERE id=?;" +msgstr "" + +#: wallet/wallet.c:1568 +msgid "SELECT id, dust_limit_satoshis, max_htlc_value_in_flight_msat, channel_reserve_satoshis, htlc_minimum_msat, to_self_delay, max_accepted_htlcs FROM channel_configs WHERE id= ? ;" +msgstr "" + +#: wallet/wallet.c:1602 +msgid "UPDATE channels SET remote_ann_node_sig=?, remote_ann_bitcoin_sig=? WHERE id=?" +msgstr "" + +#: wallet/wallet.c:1621 +msgid "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=? WHERE id=?" +msgstr "" + +#: wallet/wallet.c:1709 +msgid "UPDATE channels SET fundingkey_remote=?, revocation_basepoint_remote=?, payment_basepoint_remote=?, htlc_basepoint_remote=?, delayed_payment_basepoint_remote=?, per_commit_remote=?, old_per_commit_remote=?, channel_config_remote=?, future_per_commitment_point=? WHERE id=?" +msgstr "" + +#: wallet/wallet.c:1736 +msgid "DELETE FROM channel_feerates WHERE channel_id=?" +msgstr "" + +#: wallet/wallet.c:1746 +msgid "INSERT INTO channel_feerates VALUES(?, ?, ?)" +msgstr "" + +#: wallet/wallet.c:1760 +msgid "UPDATE channels SET last_sent_commit=? WHERE id=?" +msgstr "" + +#: wallet/wallet.c:1778 +msgid "SELECT id FROM peers WHERE node_id = ?" +msgstr "" + +#: wallet/wallet.c:1790 +msgid "UPDATE peers SET address = ? WHERE id = ?" +msgstr "" + +#: wallet/wallet.c:1799 +msgid "INSERT INTO peers (node_id, address) VALUES (?, ?);" +msgstr "" + +#: wallet/wallet.c:1817 +msgid "INSERT INTO channels (peer_id, first_blocknum, id) VALUES (?, ?, ?);" +msgstr "" + +#: wallet/wallet.c:1843 +msgid "DELETE FROM channel_htlcs WHERE channel_id=?" +msgstr "" + +#: wallet/wallet.c:1849 +msgid "DELETE FROM htlc_sigs WHERE channelid=?" +msgstr "" + +#: wallet/wallet.c:1855 +msgid "DELETE FROM channeltxs WHERE channel_id=?" +msgstr "" + +#: wallet/wallet.c:1861 +msgid "DELETE FROM shachains WHERE id IN ( SELECT shachain_remote_id FROM channels WHERE channels.id=?)" +msgstr "" + +#: wallet/wallet.c:1871 +msgid "UPDATE channels SET state=?, peer_id=?WHERE channels.id=?" +msgstr "" + +#: wallet/wallet.c:1885 +msgid "SELECT * FROM channels WHERE peer_id = ?;" +msgstr "" + +#: wallet/wallet.c:1893 +msgid "DELETE FROM peers WHERE id=?" +msgstr "" + +#: wallet/wallet.c:1904 +msgid "UPDATE outputs SET confirmation_height = ? WHERE prev_out_tx = ?" +msgstr "" + +#: wallet/wallet.c:2007 +msgid "INSERT INTO channel_htlcs ( channel_id, channel_htlc_id, direction, msatoshi, cltv_expiry, payment_hash, payment_key, hstate, shared_secret, routing_onion, received_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" +msgstr "" + +#: wallet/wallet.c:2060 +msgid "INSERT INTO channel_htlcs ( channel_id, channel_htlc_id, direction, origin_htlc, msatoshi, cltv_expiry, payment_hash, payment_key, hstate, routing_onion, partid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" +msgstr "" + +#: wallet/wallet.c:2120 +msgid "UPDATE channel_htlcs SET hstate=?, payment_key=?, malformed_onion=?, failuremsg=?, localfailmsg=?, we_filled=? WHERE id=?" +msgstr "" + +#: wallet/wallet.c:2339 +msgid "SELECT id, channel_htlc_id, msatoshi, cltv_expiry, hstate, payment_hash, payment_key, routing_onion, failuremsg, malformed_onion, origin_htlc, shared_secret, received_time, we_filled FROM channel_htlcs WHERE direction= ? AND channel_id= ? AND hstate != ?" +msgstr "" + +#: wallet/wallet.c:2386 +msgid "SELECT id, channel_htlc_id, msatoshi, cltv_expiry, hstate, payment_hash, payment_key, routing_onion, failuremsg, malformed_onion, origin_htlc, shared_secret, received_time, partid, localfailmsg FROM channel_htlcs WHERE direction = ? AND channel_id = ? AND hstate != ?" +msgstr "" + +#: wallet/wallet.c:2516 +msgid "SELECT channel_id, direction, cltv_expiry, channel_htlc_id, payment_hash FROM channel_htlcs WHERE channel_id = ?;" +msgstr "" + +#: wallet/wallet.c:2550 +msgid "DELETE FROM channel_htlcs WHERE direction = ? AND origin_htlc = ? AND payment_hash = ? AND partid = ?;" +msgstr "" + +#: wallet/wallet.c:2603 +msgid "SELECT status FROM payments WHERE payment_hash=? AND partid = ?;" +msgstr "" + +#: wallet/wallet.c:2621 +msgid "INSERT INTO payments ( status, payment_hash, destination, msatoshi, timestamp, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, total_msat, partid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" +msgstr "" + +#: wallet/wallet.c:2704 +msgid "DELETE FROM payments WHERE payment_hash = ? AND partid = ?" +msgstr "" + +#: wallet/wallet.c:2802 +msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments WHERE payment_hash = ? AND partid = ?" +msgstr "" + +#: wallet/wallet.c:2851 +msgid "UPDATE payments SET status=? WHERE payment_hash=? AND partid=?" +msgstr "" + +#: wallet/wallet.c:2861 +msgid "UPDATE payments SET payment_preimage=? WHERE payment_hash=? AND partid=?" +msgstr "" + +#: wallet/wallet.c:2871 +msgid "UPDATE payments SET path_secrets = NULL , route_nodes = NULL , route_channels = NULL WHERE payment_hash = ? AND partid = ?;" +msgstr "" + +#: wallet/wallet.c:2903 +msgid "SELECT failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, faildetail, faildirection FROM payments WHERE payment_hash=? AND partid=?;" +msgstr "" + +#: wallet/wallet.c:2970 +msgid "UPDATE payments SET failonionreply=? , faildestperm=? , failindex=? , failcode=? , failnode=? , failchannel=? , failupdate=? , faildetail=? , faildirection=? WHERE payment_hash=? AND partid=?;" +msgstr "" + +#: wallet/wallet.c:3034 +msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments WHERE payment_hash = ?;" +msgstr "" + +#: wallet/wallet.c:3055 +msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid FROM payments ORDER BY id;" +msgstr "" + +#: wallet/wallet.c:3099 +msgid "DELETE FROM htlc_sigs WHERE channelid = ?" +msgstr "" + +#: wallet/wallet.c:3106 +msgid "INSERT INTO htlc_sigs (channelid, signature) VALUES (?, ?)" +msgstr "" + +#: wallet/wallet.c:3118 +msgid "SELECT blobval FROM vars WHERE name='genesis_hash'" +msgstr "" + +#: wallet/wallet.c:3142 +msgid "INSERT INTO vars (name, blobval) VALUES ('genesis_hash', ?);" +msgstr "" + +#: wallet/wallet.c:3160 +msgid "SELECT txid, outnum FROM utxoset WHERE spendheight < ?" +msgstr "" + +#: wallet/wallet.c:3172 +msgid "DELETE FROM utxoset WHERE spendheight < ?" +msgstr "" + +#: wallet/wallet.c:3180 wallet/wallet.c:3324 +msgid "INSERT INTO blocks (height, hash, prev_hash) VALUES (?, ?, ?);" +msgstr "" + +#: wallet/wallet.c:3199 +msgid "DELETE FROM blocks WHERE hash = ?" +msgstr "" + +#: wallet/wallet.c:3205 +msgid "SELECT * FROM blocks WHERE height >= ?;" +msgstr "" + +#: wallet/wallet.c:3214 +msgid "DELETE FROM blocks WHERE height > ?" +msgstr "" + +#: wallet/wallet.c:3230 +msgid "UPDATE outputs SET spend_height = ? WHERE prev_out_tx = ? AND prev_out_index = ?" +msgstr "" + +#: wallet/wallet.c:3246 +msgid "UPDATE utxoset SET spendheight = ? WHERE txid = ? AND outnum = ?" +msgstr "" + +#: wallet/wallet.c:3265 +msgid "SELECT blockheight, txindex FROM utxoset WHERE txid = ? AND outnum = ?" +msgstr "" + +#: wallet/wallet.c:3297 wallet/wallet.c:3335 +msgid "INSERT INTO utxoset ( txid, outnum, blockheight, spendheight, txindex, scriptpubkey, satoshis) VALUES(?, ?, ?, ?, ?, ?, ?);" +msgstr "" + +#: wallet/wallet.c:3362 +msgid "SELECT height FROM blocks WHERE height = ?" +msgstr "" + +#: wallet/wallet.c:3375 +msgid "SELECT txid, spendheight, scriptpubkey, satoshis FROM utxoset WHERE blockheight = ? AND txindex = ? AND outnum = ? AND spendheight IS NULL" +msgstr "" + +#: wallet/wallet.c:3417 wallet/wallet.c:3577 +msgid "SELECT blockheight FROM transactions WHERE id=?" +msgstr "" + +#: wallet/wallet.c:3427 +msgid "INSERT INTO transactions ( id, blockheight, txindex, rawtx) VALUES (?, ?, ?, ?);" +msgstr "" + +#: wallet/wallet.c:3448 +msgid "UPDATE transactions SET blockheight = ?, txindex = ? WHERE id = ?" +msgstr "" + +#: wallet/wallet.c:3465 +msgid "INSERT INTO transaction_annotations (txid, idx, location, type, channel) VALUES (?, ?, ?, ?, ?) ON CONFLICT(txid,idx) DO NOTHING;" +msgstr "" + +#: wallet/wallet.c:3497 +msgid "SELECT type, channel_id FROM transactions WHERE id=?" +msgstr "" + +#: wallet/wallet.c:3513 +msgid "UPDATE transactions SET type = ?, channel_id = ? WHERE id = ?" +msgstr "" + +#: wallet/wallet.c:3532 +msgid "SELECT type FROM transactions WHERE id=?" +msgstr "" + +#: wallet/wallet.c:3555 +msgid "SELECT rawtx FROM transactions WHERE id=?" +msgstr "" + +#: wallet/wallet.c:3601 +msgid "SELECT blockheight, txindex FROM transactions WHERE id=?" +msgstr "" + +#: wallet/wallet.c:3629 +msgid "SELECT id FROM transactions WHERE blockheight=?" +msgstr "" + +#: wallet/wallet.c:3648 +msgid "INSERT INTO channeltxs ( channel_id, type, transaction_id, input_num, blockheight) VALUES (?, ?, ?, ?, ?);" +msgstr "" + +#: wallet/wallet.c:3672 +msgid "SELECT DISTINCT(channel_id) FROM channeltxs WHERE type = ?;" +msgstr "" + +#: wallet/wallet.c:3693 +msgid "SELECT c.type, c.blockheight, t.rawtx, c.input_num, c.blockheight - t.blockheight + 1 AS depth, t.id as txid FROM channeltxs c JOIN transactions t ON t.id = c.transaction_id WHERE c.channel_id = ? ORDER BY c.id ASC;" +msgstr "" + +#: wallet/wallet.c:3738 +msgid "UPDATE forwarded_payments SET in_msatoshi=?, out_msatoshi=?, state=?, resolved_time=?, failcode=? WHERE in_htlc_id=?" +msgstr "" + +#: wallet/wallet.c:3796 +msgid "INSERT INTO forwarded_payments ( in_htlc_id, out_htlc_id, in_channel_scid, out_channel_scid, in_msatoshi, out_msatoshi, state, received_time, resolved_time, failcode) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" +msgstr "" + +#: wallet/wallet.c:3855 +msgid "SELECT CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)FROM forwarded_payments WHERE state = ?;" +msgstr "" + +#: wallet/wallet.c:3879 +msgid "SELECT f.state, in_msatoshi, out_msatoshi, hin.payment_hash as payment_hash, in_channel_scid, out_channel_scid, f.received_time, f.resolved_time, f.failcode FROM forwarded_payments f LEFT JOIN channel_htlcs hin ON (f.in_htlc_id = hin.id)" +msgstr "" + +#: wallet/wallet.c:4046 +msgid "SELECT t.id, t.rawtx, t.blockheight, t.txindex, t.type as txtype, c2.short_channel_id as txchan, a.location, a.idx as ann_idx, a.type as annotation_type, c.short_channel_id FROM transactions t LEFT JOIN transaction_annotations a ON (a.txid = t.id) LEFT JOIN channels c ON (a.channel = c.id) LEFT JOIN channels c2 ON (t.channel_id = c2.id) ORDER BY t.blockheight, t.txindex ASC" +msgstr "" + +#: wallet/wallet.c:4140 +msgid "INSERT INTO penalty_bases ( channel_id, commitnum, txid, outnum, amount) VALUES (?, ?, ?, ?, ?);" +msgstr "" + +#: wallet/wallet.c:4165 +msgid "SELECT commitnum, txid, outnum, amount FROM penalty_bases WHERE channel_id = ?" +msgstr "" + +#: wallet/wallet.c:4189 +msgid "DELETE FROM penalty_bases WHERE channel_id = ? AND commitnum = ?" +msgstr "" + +#: wallet/test/run-db.c:115 +msgid "SELECT name FROM sqlite_master WHERE type='table';" +msgstr "" + +#: wallet/test/run-db.c:120 +msgid "not a valid SQL statement" +msgstr "" + +#: wallet/test/run-wallet.c:1334 +msgid "INSERT INTO channels (id) VALUES (1);" +msgstr "" +# SHA256STAMP:d704e1158fa5e66660baa0075dff55eff58a60a6710be35ebcb46a8d3a2c23f4 diff --git a/wire/common_wiregen.c b/wire/common_wiregen.c new file mode 100644 index 000000000..ad1b689ff --- /dev/null +++ b/wire/common_wiregen.c @@ -0,0 +1,104 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Original template can be found at tools/gen/impl_template */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef SUPERVERBOSE +#define SUPERVERBOSE(...) +#endif + + +const char *common_wire_name(int e) +{ + static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; + + switch ((enum common_wire)e) { + case WIRE_CUSTOMMSG_IN: return "WIRE_CUSTOMMSG_IN"; + case WIRE_CUSTOMMSG_OUT: return "WIRE_CUSTOMMSG_OUT"; + } + + snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); + return invalidbuf; +} + +bool common_wire_is_defined(u16 type) +{ + switch ((enum common_wire)type) { + case WIRE_CUSTOMMSG_IN:; + case WIRE_CUSTOMMSG_OUT:; + return true; + } + return false; +} + + + + + +/* WIRE: CUSTOMMSG_IN */ +/* A custom message that we got from a peer and don't know how to handle */ +/* forward it to the master for further handling. */ +u8 *towire_custommsg_in(const tal_t *ctx, const u8 *msg) +{ + u16 msg_len = tal_count(msg); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CUSTOMMSG_IN); + towire_u16(&p, msg_len); + towire_u8_array(&p, msg, msg_len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_custommsg_in(const tal_t *ctx, const void *p, u8 **msg) +{ + u16 msg_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CUSTOMMSG_IN) + return false; + msg_len = fromwire_u16(&cursor, &plen); + // 2nd case msg + *msg = msg_len ? tal_arr(ctx, u8, msg_len) : NULL; + fromwire_u8_array(&cursor, &plen, *msg, msg_len); + return cursor != NULL; +} + +/* WIRE: CUSTOMMSG_OUT */ +/* A custom message that the master tells us to send to the peer. */ +u8 *towire_custommsg_out(const tal_t *ctx, const u8 *msg) +{ + u16 msg_len = tal_count(msg); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CUSTOMMSG_OUT); + towire_u16(&p, msg_len); + towire_u8_array(&p, msg, msg_len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_custommsg_out(const tal_t *ctx, const void *p, u8 **msg) +{ + u16 msg_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CUSTOMMSG_OUT) + return false; + msg_len = fromwire_u16(&cursor, &plen); + // 2nd case msg + *msg = msg_len ? tal_arr(ctx, u8, msg_len) : NULL; + fromwire_u8_array(&cursor, &plen, *msg, msg_len); + return cursor != NULL; +} + +// SHA256STAMP:exp-0-dfcb1617f1ac102da12d72fa0d9b3abe6c1183dd3b75a5452e7d4c1ea159478f diff --git a/wire/common_wiregen.h b/wire/common_wiregen.h new file mode 100644 index 000000000..80d695573 --- /dev/null +++ b/wire/common_wiregen.h @@ -0,0 +1,45 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the _csv file it was generated from. */ +/* Original template can be found at tools/gen/header_template */ + +#ifndef LIGHTNING_WIRE_COMMON_WIREGEN_H +#define LIGHTNING_WIRE_COMMON_WIREGEN_H +#include +#include +#include + +enum common_wire { + /* A custom message that we got from a peer and don't know how to handle */ + /* forward it to the master for further handling. */ + WIRE_CUSTOMMSG_IN = 1030, + /* A custom message that the master tells us to send to the peer. */ + WIRE_CUSTOMMSG_OUT = 1031, +}; + +const char *common_wire_name(int e); + +/** + * Determine whether a given message type is defined as a message. + * + * Returns true if the message type is part of the message definitions we have + * generated parsers for, false if it is a custom message that cannot be + * handled internally. + */ +bool common_wire_is_defined(u16 type); + + +/* WIRE: CUSTOMMSG_IN */ +/* A custom message that we got from a peer and don't know how to handle */ +/* forward it to the master for further handling. */ +u8 *towire_custommsg_in(const tal_t *ctx, const u8 *msg); +bool fromwire_custommsg_in(const tal_t *ctx, const void *p, u8 **msg); + +/* WIRE: CUSTOMMSG_OUT */ +/* A custom message that the master tells us to send to the peer. */ +u8 *towire_custommsg_out(const tal_t *ctx, const u8 *msg); +bool fromwire_custommsg_out(const tal_t *ctx, const void *p, u8 **msg); + + +#endif /* LIGHTNING_WIRE_COMMON_WIREGEN_H */ + +// SHA256STAMP:exp-0-dfcb1617f1ac102da12d72fa0d9b3abe6c1183dd3b75a5452e7d4c1ea159478f diff --git a/wire/onion_printgen.c b/wire/onion_printgen.c new file mode 100644 index 000000000..a9db06867 --- /dev/null +++ b/wire/onion_printgen.c @@ -0,0 +1,657 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ + +#include "wire/onion_printgen.h" +#include +#include +#include +#include +#include +#include + +void printonion_wire_message(const u8 *msg) +{ + switch ((enum onion_wire)fromwire_peektype(msg)) { + case WIRE_INVALID_REALM: + printf("WIRE_INVALID_REALM:\n"); + printwire_invalid_realm("invalid_realm", msg); + return; + case WIRE_TEMPORARY_NODE_FAILURE: + printf("WIRE_TEMPORARY_NODE_FAILURE:\n"); + printwire_temporary_node_failure("temporary_node_failure", msg); + return; + case WIRE_PERMANENT_NODE_FAILURE: + printf("WIRE_PERMANENT_NODE_FAILURE:\n"); + printwire_permanent_node_failure("permanent_node_failure", msg); + return; + case WIRE_REQUIRED_NODE_FEATURE_MISSING: + printf("WIRE_REQUIRED_NODE_FEATURE_MISSING:\n"); + printwire_required_node_feature_missing("required_node_feature_missing", msg); + return; + case WIRE_INVALID_ONION_VERSION: + printf("WIRE_INVALID_ONION_VERSION:\n"); + printwire_invalid_onion_version("invalid_onion_version", msg); + return; + case WIRE_INVALID_ONION_HMAC: + printf("WIRE_INVALID_ONION_HMAC:\n"); + printwire_invalid_onion_hmac("invalid_onion_hmac", msg); + return; + case WIRE_INVALID_ONION_KEY: + printf("WIRE_INVALID_ONION_KEY:\n"); + printwire_invalid_onion_key("invalid_onion_key", msg); + return; + case WIRE_TEMPORARY_CHANNEL_FAILURE: + printf("WIRE_TEMPORARY_CHANNEL_FAILURE:\n"); + printwire_temporary_channel_failure("temporary_channel_failure", msg); + return; + case WIRE_PERMANENT_CHANNEL_FAILURE: + printf("WIRE_PERMANENT_CHANNEL_FAILURE:\n"); + printwire_permanent_channel_failure("permanent_channel_failure", msg); + return; + case WIRE_REQUIRED_CHANNEL_FEATURE_MISSING: + printf("WIRE_REQUIRED_CHANNEL_FEATURE_MISSING:\n"); + printwire_required_channel_feature_missing("required_channel_feature_missing", msg); + return; + case WIRE_UNKNOWN_NEXT_PEER: + printf("WIRE_UNKNOWN_NEXT_PEER:\n"); + printwire_unknown_next_peer("unknown_next_peer", msg); + return; + case WIRE_AMOUNT_BELOW_MINIMUM: + printf("WIRE_AMOUNT_BELOW_MINIMUM:\n"); + printwire_amount_below_minimum("amount_below_minimum", msg); + return; + case WIRE_FEE_INSUFFICIENT: + printf("WIRE_FEE_INSUFFICIENT:\n"); + printwire_fee_insufficient("fee_insufficient", msg); + return; + case WIRE_INCORRECT_CLTV_EXPIRY: + printf("WIRE_INCORRECT_CLTV_EXPIRY:\n"); + printwire_incorrect_cltv_expiry("incorrect_cltv_expiry", msg); + return; + case WIRE_EXPIRY_TOO_SOON: + printf("WIRE_EXPIRY_TOO_SOON:\n"); + printwire_expiry_too_soon("expiry_too_soon", msg); + return; + case WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS: + printf("WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS:\n"); + printwire_incorrect_or_unknown_payment_details("incorrect_or_unknown_payment_details", msg); + return; + case WIRE_FINAL_INCORRECT_CLTV_EXPIRY: + printf("WIRE_FINAL_INCORRECT_CLTV_EXPIRY:\n"); + printwire_final_incorrect_cltv_expiry("final_incorrect_cltv_expiry", msg); + return; + case WIRE_FINAL_INCORRECT_HTLC_AMOUNT: + printf("WIRE_FINAL_INCORRECT_HTLC_AMOUNT:\n"); + printwire_final_incorrect_htlc_amount("final_incorrect_htlc_amount", msg); + return; + case WIRE_CHANNEL_DISABLED: + printf("WIRE_CHANNEL_DISABLED:\n"); + printwire_channel_disabled("channel_disabled", msg); + return; + case WIRE_EXPIRY_TOO_FAR: + printf("WIRE_EXPIRY_TOO_FAR:\n"); + printwire_expiry_too_far("expiry_too_far", msg); + return; + case WIRE_INVALID_ONION_PAYLOAD: + printf("WIRE_INVALID_ONION_PAYLOAD:\n"); + printwire_invalid_onion_payload("invalid_onion_payload", msg); + return; + case WIRE_MPP_TIMEOUT: + printf("WIRE_MPP_TIMEOUT:\n"); + printwire_mpp_timeout("mpp_timeout", msg); + return; + } + + printf("UNKNOWN: %s\\n", tal_hex(msg, msg)); +} + + +static void printwire_tlv_tlv_payload_amt_to_forward(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "amt_to_forward"); + + printf("amt_to_forward="); + u64 amt_to_forward = fromwire_tu64(cursor, plen); + + printwire_u64(tal_fmt(NULL, "%s.amt_to_forward", fieldname), &amt_to_forward); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} +static void printwire_tlv_tlv_payload_outgoing_cltv_value(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "outgoing_cltv_value"); + + printf("outgoing_cltv_value="); + u32 outgoing_cltv_value = fromwire_tu32(cursor, plen); + + printwire_u32(tal_fmt(NULL, "%s.outgoing_cltv_value", fieldname), &outgoing_cltv_value); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} +static void printwire_tlv_tlv_payload_short_channel_id(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "short_channel_id"); + + printf("short_channel_id="); + struct short_channel_id short_channel_id; + fromwire_short_channel_id(cursor, plen, &short_channel_id); + + printwire_short_channel_id(tal_fmt(NULL, "%s.short_channel_id", fieldname), &short_channel_id); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} +static void printwire_tlv_tlv_payload_payment_data(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "payment_data"); + + printf("payment_secret="); + struct secret payment_secret; + fromwire_secret(cursor, plen, &payment_secret); + + printwire_secret(tal_fmt(NULL, "%s.payment_secret", fieldname), &payment_secret); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("total_msat="); + u64 total_msat = fromwire_tu64(cursor, plen); + + printwire_u64(tal_fmt(NULL, "%s.total_msat", fieldname), &total_msat); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} + +static const struct tlv_print_record_type print_tlvs_tlv_payload[] = { + { 2, printwire_tlv_tlv_payload_amt_to_forward }, + { 4, printwire_tlv_tlv_payload_outgoing_cltv_value }, + { 6, printwire_tlv_tlv_payload_short_channel_id }, + { 8, printwire_tlv_tlv_payload_payment_data }, +}; +void printwire_invalid_realm(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_INVALID_REALM) { + printf("WRONG TYPE?!\n"); + return; + } + + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_temporary_node_failure(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_TEMPORARY_NODE_FAILURE) { + printf("WRONG TYPE?!\n"); + return; + } + + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_permanent_node_failure(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_PERMANENT_NODE_FAILURE) { + printf("WRONG TYPE?!\n"); + return; + } + + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_required_node_feature_missing(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_REQUIRED_NODE_FEATURE_MISSING) { + printf("WRONG TYPE?!\n"); + return; + } + + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_invalid_onion_version(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_INVALID_ONION_VERSION) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("sha256_of_onion="); + struct sha256 sha256_of_onion; + fromwire_sha256(&cursor, &plen, &sha256_of_onion); + + printwire_sha256(tal_fmt(NULL, "%s.sha256_of_onion", fieldname), &sha256_of_onion); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_invalid_onion_hmac(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_INVALID_ONION_HMAC) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("sha256_of_onion="); + struct sha256 sha256_of_onion; + fromwire_sha256(&cursor, &plen, &sha256_of_onion); + + printwire_sha256(tal_fmt(NULL, "%s.sha256_of_onion", fieldname), &sha256_of_onion); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_invalid_onion_key(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_INVALID_ONION_KEY) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("sha256_of_onion="); + struct sha256 sha256_of_onion; + fromwire_sha256(&cursor, &plen, &sha256_of_onion); + + printwire_sha256(tal_fmt(NULL, "%s.sha256_of_onion", fieldname), &sha256_of_onion); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_temporary_channel_failure(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_TEMPORARY_CHANNEL_FAILURE) { + printf("WRONG TYPE?!\n"); + return; + } + + u16 len = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("channel_update="); + printwire_u8_array(tal_fmt(NULL, "%s.channel_update", fieldname), &cursor, &plen, len); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_permanent_channel_failure(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_PERMANENT_CHANNEL_FAILURE) { + printf("WRONG TYPE?!\n"); + return; + } + + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_required_channel_feature_missing(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_REQUIRED_CHANNEL_FEATURE_MISSING) { + printf("WRONG TYPE?!\n"); + return; + } + + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_unknown_next_peer(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_UNKNOWN_NEXT_PEER) { + printf("WRONG TYPE?!\n"); + return; + } + + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_amount_below_minimum(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_AMOUNT_BELOW_MINIMUM) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("htlc_msat="); + struct amount_msat htlc_msat = fromwire_amount_msat(&cursor, &plen); + + printwire_amount_msat(tal_fmt(NULL, "%s.htlc_msat", fieldname), &htlc_msat); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + u16 len = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("channel_update="); + printwire_u8_array(tal_fmt(NULL, "%s.channel_update", fieldname), &cursor, &plen, len); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_fee_insufficient(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_FEE_INSUFFICIENT) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("htlc_msat="); + struct amount_msat htlc_msat = fromwire_amount_msat(&cursor, &plen); + + printwire_amount_msat(tal_fmt(NULL, "%s.htlc_msat", fieldname), &htlc_msat); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + u16 len = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("channel_update="); + printwire_u8_array(tal_fmt(NULL, "%s.channel_update", fieldname), &cursor, &plen, len); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_incorrect_cltv_expiry(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_INCORRECT_CLTV_EXPIRY) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("cltv_expiry="); + u32 cltv_expiry = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.cltv_expiry", fieldname), &cltv_expiry); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + u16 len = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("channel_update="); + printwire_u8_array(tal_fmt(NULL, "%s.channel_update", fieldname), &cursor, &plen, len); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_expiry_too_soon(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_EXPIRY_TOO_SOON) { + printf("WRONG TYPE?!\n"); + return; + } + + u16 len = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("channel_update="); + printwire_u8_array(tal_fmt(NULL, "%s.channel_update", fieldname), &cursor, &plen, len); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_incorrect_or_unknown_payment_details(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("htlc_msat="); + struct amount_msat htlc_msat = fromwire_amount_msat(&cursor, &plen); + + printwire_amount_msat(tal_fmt(NULL, "%s.htlc_msat", fieldname), &htlc_msat); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("height="); + u32 height = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.height", fieldname), &height); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_final_incorrect_cltv_expiry(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_FINAL_INCORRECT_CLTV_EXPIRY) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("cltv_expiry="); + u32 cltv_expiry = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.cltv_expiry", fieldname), &cltv_expiry); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_final_incorrect_htlc_amount(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_FINAL_INCORRECT_HTLC_AMOUNT) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("incoming_htlc_amt="); + struct amount_msat incoming_htlc_amt = fromwire_amount_msat(&cursor, &plen); + + printwire_amount_msat(tal_fmt(NULL, "%s.incoming_htlc_amt", fieldname), &incoming_htlc_amt); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_channel_disabled(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNEL_DISABLED) { + printf("WRONG TYPE?!\n"); + return; + } + + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_expiry_too_far(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_EXPIRY_TOO_FAR) { + printf("WRONG TYPE?!\n"); + return; + } + + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_invalid_onion_payload(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_INVALID_ONION_PAYLOAD) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("type="); + bigsize type = fromwire_bigsize(&cursor, &plen); + + printwire_bigsize(tal_fmt(NULL, "%s.type", fieldname), &type); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("offset="); + u16 offset = fromwire_u16(&cursor, &plen); + + printwire_u16(tal_fmt(NULL, "%s.offset", fieldname), &offset); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_mpp_timeout(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_MPP_TIMEOUT) { + printf("WRONG TYPE?!\n"); + return; + } + + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} + +void printonion_wire_tlv_message(const char *tlv_name, const u8 *msg) { + size_t plen = tal_count(msg); + if (strcmp(tlv_name, "tlv_payload") == 0) { + printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_tlv_payload, ARRAY_SIZE(print_tlvs_tlv_payload)); + } +} + +// SHA256STAMP:exp-0-fb3c7a1b699d41c2fe76eb380a851fe8aea7a15e7740ce2bfdcb3fcf173a1e8a diff --git a/wire/onion_printgen.h b/wire/onion_printgen.h new file mode 100644 index 000000000..0361df96d --- /dev/null +++ b/wire/onion_printgen.h @@ -0,0 +1,61 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Template located at tools/gen/print_header_template */ +#ifndef LIGHTNING_WIRE_ONION_PRINTGEN_H +#define LIGHTNING_WIRE_ONION_PRINTGEN_H +#include +#include +#include + +void printonion_wire_message(const u8 *msg); + +void printonion_wire_tlv_message(const char *tlv_name, const u8 *msg); + +void printwire_invalid_realm(const char *fieldname, const u8 *cursor); + +void printwire_temporary_node_failure(const char *fieldname, const u8 *cursor); + +void printwire_permanent_node_failure(const char *fieldname, const u8 *cursor); + +void printwire_required_node_feature_missing(const char *fieldname, const u8 *cursor); + +void printwire_invalid_onion_version(const char *fieldname, const u8 *cursor); + +void printwire_invalid_onion_hmac(const char *fieldname, const u8 *cursor); + +void printwire_invalid_onion_key(const char *fieldname, const u8 *cursor); + +void printwire_temporary_channel_failure(const char *fieldname, const u8 *cursor); + +void printwire_permanent_channel_failure(const char *fieldname, const u8 *cursor); + +void printwire_required_channel_feature_missing(const char *fieldname, const u8 *cursor); + +void printwire_unknown_next_peer(const char *fieldname, const u8 *cursor); + +void printwire_amount_below_minimum(const char *fieldname, const u8 *cursor); + +void printwire_fee_insufficient(const char *fieldname, const u8 *cursor); + +void printwire_incorrect_cltv_expiry(const char *fieldname, const u8 *cursor); + +void printwire_expiry_too_soon(const char *fieldname, const u8 *cursor); + +void printwire_incorrect_or_unknown_payment_details(const char *fieldname, const u8 *cursor); + +void printwire_final_incorrect_cltv_expiry(const char *fieldname, const u8 *cursor); + +void printwire_final_incorrect_htlc_amount(const char *fieldname, const u8 *cursor); + +void printwire_channel_disabled(const char *fieldname, const u8 *cursor); + +void printwire_expiry_too_far(const char *fieldname, const u8 *cursor); + +void printwire_invalid_onion_payload(const char *fieldname, const u8 *cursor); + +void printwire_mpp_timeout(const char *fieldname, const u8 *cursor); + + +#endif /* LIGHTNING_WIRE_ONION_PRINTGEN_H */ + +// SHA256STAMP:exp-0-fb3c7a1b699d41c2fe76eb380a851fe8aea7a15e7740ce2bfdcb3fcf173a1e8a diff --git a/wire/onion_wiregen.c b/wire/onion_wiregen.c new file mode 100644 index 000000000..daff9fd3c --- /dev/null +++ b/wire/onion_wiregen.c @@ -0,0 +1,841 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Original template can be found at tools/gen/impl_template */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef SUPERVERBOSE +#define SUPERVERBOSE(...) +#endif + + +const char *onion_wire_name(int e) +{ + static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; + + switch ((enum onion_wire)e) { + case WIRE_INVALID_REALM: return "WIRE_INVALID_REALM"; + case WIRE_TEMPORARY_NODE_FAILURE: return "WIRE_TEMPORARY_NODE_FAILURE"; + case WIRE_PERMANENT_NODE_FAILURE: return "WIRE_PERMANENT_NODE_FAILURE"; + case WIRE_REQUIRED_NODE_FEATURE_MISSING: return "WIRE_REQUIRED_NODE_FEATURE_MISSING"; + case WIRE_INVALID_ONION_VERSION: return "WIRE_INVALID_ONION_VERSION"; + case WIRE_INVALID_ONION_HMAC: return "WIRE_INVALID_ONION_HMAC"; + case WIRE_INVALID_ONION_KEY: return "WIRE_INVALID_ONION_KEY"; + case WIRE_TEMPORARY_CHANNEL_FAILURE: return "WIRE_TEMPORARY_CHANNEL_FAILURE"; + case WIRE_PERMANENT_CHANNEL_FAILURE: return "WIRE_PERMANENT_CHANNEL_FAILURE"; + case WIRE_REQUIRED_CHANNEL_FEATURE_MISSING: return "WIRE_REQUIRED_CHANNEL_FEATURE_MISSING"; + case WIRE_UNKNOWN_NEXT_PEER: return "WIRE_UNKNOWN_NEXT_PEER"; + case WIRE_AMOUNT_BELOW_MINIMUM: return "WIRE_AMOUNT_BELOW_MINIMUM"; + case WIRE_FEE_INSUFFICIENT: return "WIRE_FEE_INSUFFICIENT"; + case WIRE_INCORRECT_CLTV_EXPIRY: return "WIRE_INCORRECT_CLTV_EXPIRY"; + case WIRE_EXPIRY_TOO_SOON: return "WIRE_EXPIRY_TOO_SOON"; + case WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS: return "WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS"; + case WIRE_FINAL_INCORRECT_CLTV_EXPIRY: return "WIRE_FINAL_INCORRECT_CLTV_EXPIRY"; + case WIRE_FINAL_INCORRECT_HTLC_AMOUNT: return "WIRE_FINAL_INCORRECT_HTLC_AMOUNT"; + case WIRE_CHANNEL_DISABLED: return "WIRE_CHANNEL_DISABLED"; + case WIRE_EXPIRY_TOO_FAR: return "WIRE_EXPIRY_TOO_FAR"; + case WIRE_INVALID_ONION_PAYLOAD: return "WIRE_INVALID_ONION_PAYLOAD"; + case WIRE_MPP_TIMEOUT: return "WIRE_MPP_TIMEOUT"; + } + + snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); + return invalidbuf; +} + +bool onion_wire_is_defined(u16 type) +{ + switch ((enum onion_wire)type) { + case WIRE_INVALID_REALM:; + case WIRE_TEMPORARY_NODE_FAILURE:; + case WIRE_PERMANENT_NODE_FAILURE:; + case WIRE_REQUIRED_NODE_FEATURE_MISSING:; + case WIRE_INVALID_ONION_VERSION:; + case WIRE_INVALID_ONION_HMAC:; + case WIRE_INVALID_ONION_KEY:; + case WIRE_TEMPORARY_CHANNEL_FAILURE:; + case WIRE_PERMANENT_CHANNEL_FAILURE:; + case WIRE_REQUIRED_CHANNEL_FEATURE_MISSING:; + case WIRE_UNKNOWN_NEXT_PEER:; + case WIRE_AMOUNT_BELOW_MINIMUM:; + case WIRE_FEE_INSUFFICIENT:; + case WIRE_INCORRECT_CLTV_EXPIRY:; + case WIRE_EXPIRY_TOO_SOON:; + case WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS:; + case WIRE_FINAL_INCORRECT_CLTV_EXPIRY:; + case WIRE_FINAL_INCORRECT_HTLC_AMOUNT:; + case WIRE_CHANNEL_DISABLED:; + case WIRE_EXPIRY_TOO_FAR:; + case WIRE_INVALID_ONION_PAYLOAD:; + case WIRE_MPP_TIMEOUT:; + return true; + } + return false; +} + + + + + +struct tlv_tlv_payload *tlv_tlv_payload_new(const tal_t *ctx) +{ + /* Initialize everything to NULL. (Quiet, C pedants!) */ + struct tlv_tlv_payload *inst = talz(ctx, struct tlv_tlv_payload); + + /* Initialized the fields to an empty array. */ + inst->fields = tal_arr(inst, struct tlv_field, 0); + return inst; +} + +/* TLV_PAYLOAD MSG: amt_to_forward */ +static u8 *towire_tlv_tlv_payload_amt_to_forward(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_tlv_payload *r = vrecord; + u8 *ptr; + + if (!r->amt_to_forward) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_tu64(&ptr, *r->amt_to_forward); + return ptr; +} +static void fromwire_tlv_tlv_payload_amt_to_forward(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_tlv_payload *r = vrecord; + + r->amt_to_forward = tal(r, u64); + +*r->amt_to_forward = fromwire_tu64(cursor, plen); +} +/* TLV_PAYLOAD MSG: outgoing_cltv_value */ +static u8 *towire_tlv_tlv_payload_outgoing_cltv_value(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_tlv_payload *r = vrecord; + u8 *ptr; + + if (!r->outgoing_cltv_value) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_tu32(&ptr, *r->outgoing_cltv_value); + return ptr; +} +static void fromwire_tlv_tlv_payload_outgoing_cltv_value(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_tlv_payload *r = vrecord; + + r->outgoing_cltv_value = tal(r, u32); + +*r->outgoing_cltv_value = fromwire_tu32(cursor, plen); +} +/* TLV_PAYLOAD MSG: short_channel_id */ +static u8 *towire_tlv_tlv_payload_short_channel_id(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_tlv_payload *r = vrecord; + u8 *ptr; + + if (!r->short_channel_id) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_short_channel_id(&ptr, r->short_channel_id); + return ptr; +} +static void fromwire_tlv_tlv_payload_short_channel_id(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_tlv_payload *r = vrecord; + + r->short_channel_id = tal(r, struct short_channel_id); + +fromwire_short_channel_id(cursor, plen, &*r->short_channel_id); +} +/* TLV_PAYLOAD MSG: payment_data */ +static u8 *towire_tlv_tlv_payload_payment_data(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_tlv_payload *r = vrecord; + u8 *ptr; + + if (!r->payment_data) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_secret(&ptr, &r->payment_data->payment_secret); + + towire_tu64(&ptr, r->payment_data->total_msat); + return ptr; +} +static void fromwire_tlv_tlv_payload_payment_data(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_tlv_payload *r = vrecord; + + r->payment_data = tal(r, struct tlv_tlv_payload_payment_data); + fromwire_secret(cursor, plen, &r->payment_data->payment_secret); + r->payment_data->total_msat = fromwire_tu64(cursor, plen); +} + +const struct tlv_record_type tlvs_tlv_payload[] = { + { 2, towire_tlv_tlv_payload_amt_to_forward, fromwire_tlv_tlv_payload_amt_to_forward }, + { 4, towire_tlv_tlv_payload_outgoing_cltv_value, fromwire_tlv_tlv_payload_outgoing_cltv_value }, + { 6, towire_tlv_tlv_payload_short_channel_id, fromwire_tlv_tlv_payload_short_channel_id }, + { 8, towire_tlv_tlv_payload_payment_data, fromwire_tlv_tlv_payload_payment_data }, +}; + +void towire_tlv_payload(u8 **pptr, + const void *record) +{ + size_t num_types = 4; + const struct tlv_record_type *types = tlvs_tlv_payload; + if (!record) + return; + + for (size_t i = 0; i < num_types; i++) { + u8 *val; + if (i != 0) + assert(types[i].type > types[i-1].type); + val = types[i].towire(NULL, record); + if (!val) + continue; + + /* BOLT #1: + * + * The sending node: + ... + * - MUST minimally encode `type` and `length`. + */ + towire_bigsize(pptr, types[i].type); + towire_bigsize(pptr, tal_bytelen(val)); + towire(pptr, val, tal_bytelen(val)); + tal_free(val); + } +} + + +bool fromwire_tlv_payload(const u8 **cursor, size_t *max, struct tlv_tlv_payload *record) +{ + size_t num_types = 4; + const struct tlv_record_type *types = tlvs_tlv_payload; + while (*max > 0) { + struct tlv_field field; + + /* BOLT #1: + * + * A `varint` is a variable-length, unsigned integer encoding + * using the [BigSize](#appendix-a-bigsize-test-vectors) + * format + */ + field.numtype = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("type"); + goto fail; + } + field.length = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("length"); + goto fail; + } + + /* BOLT #1: + * - if `length` exceeds the number of bytes remaining in the + * message: + * - MUST fail to parse the `tlv_stream`. + */ + if (field.length > *max) { + SUPERVERBOSE("value"); + goto fail; + } + field.value = tal_dup_arr(record, u8, *cursor, field.length, 0); + + /* BOLT #1: + * - if `type` is known: + * - MUST decode the next `length` bytes using the known + * encoding for `type`. + */ + field.meta = NULL; + for (size_t i = 0; i < num_types; i++) { + if (types[i].type == field.numtype) + field.meta = &types[i]; + } + + if (field.meta) { + /* Length of message can't exceed 16 bits anyway. */ + size_t tlvlen = field.length; + field.meta->fromwire(cursor, &tlvlen, record); + + if (!*cursor) + goto fail; + + /* BOLT #1: + * - if `length` is not exactly equal to that required + * for the known encoding for `type`: + * - MUST fail to parse the `tlv_stream`. + */ + if (tlvlen != 0) { + SUPERVERBOSE("greater than encoding length"); + goto fail; + } + } else { + /* We didn't read from *cursor through a fromwire, so + * update manually. */ + *cursor += field.length; + } + /* We've read bytes in ->fromwire, so update max */ + *max -= field.length; + tal_arr_expand(&record->fields, field); + } + return true; +fail: + fromwire_fail(cursor, max); + return false; +} + +bool tlv_payload_is_valid(const struct tlv_tlv_payload *record, size_t *err_index) +{ + size_t numfields = tal_count(record->fields); + bool first = true; + u64 prev_type = 0; + for (int i=0; ifields[i]; + if (f->numtype % 2 == 0 && f->meta == NULL) { + /* BOLT #1: + * - otherwise, if `type` is unknown: + * - if `type` is even: + * - MUST fail to parse the `tlv_stream`. + * - otherwise, if `type` is odd: + * - MUST discard the next `length` bytes. + */ + SUPERVERBOSE("unknown even"); + if (err_index != NULL) + *err_index = i; + return false; + } else if (!first && f->numtype <= prev_type) { + /* BOLT #1: + * - if decoded `type`s are not monotonically-increasing: + * - MUST fail to parse the `tlv_stream`. + */ + if (f->numtype == prev_type) + SUPERVERBOSE("duplicate tlv type"); + else + SUPERVERBOSE("invalid ordering"); + if (err_index != NULL) + *err_index = i; + return false; + } + first = false; + prev_type = f->numtype; + } + return true; +} + + +/* WIRE: INVALID_REALM */ +u8 *towire_invalid_realm(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_INVALID_REALM); + + return memcheck(p, tal_count(p)); +} +bool fromwire_invalid_realm(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_INVALID_REALM) + return false; + return cursor != NULL; +} + +/* WIRE: TEMPORARY_NODE_FAILURE */ +u8 *towire_temporary_node_failure(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_TEMPORARY_NODE_FAILURE); + + return memcheck(p, tal_count(p)); +} +bool fromwire_temporary_node_failure(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_TEMPORARY_NODE_FAILURE) + return false; + return cursor != NULL; +} + +/* WIRE: PERMANENT_NODE_FAILURE */ +u8 *towire_permanent_node_failure(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_PERMANENT_NODE_FAILURE); + + return memcheck(p, tal_count(p)); +} +bool fromwire_permanent_node_failure(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_PERMANENT_NODE_FAILURE) + return false; + return cursor != NULL; +} + +/* WIRE: REQUIRED_NODE_FEATURE_MISSING */ +u8 *towire_required_node_feature_missing(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_REQUIRED_NODE_FEATURE_MISSING); + + return memcheck(p, tal_count(p)); +} +bool fromwire_required_node_feature_missing(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_REQUIRED_NODE_FEATURE_MISSING) + return false; + return cursor != NULL; +} + +/* WIRE: INVALID_ONION_VERSION */ +u8 *towire_invalid_onion_version(const tal_t *ctx, const struct sha256 *sha256_of_onion) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_INVALID_ONION_VERSION); + towire_sha256(&p, sha256_of_onion); + + return memcheck(p, tal_count(p)); +} +bool fromwire_invalid_onion_version(const void *p, struct sha256 *sha256_of_onion) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_INVALID_ONION_VERSION) + return false; + fromwire_sha256(&cursor, &plen, sha256_of_onion); + return cursor != NULL; +} + +/* WIRE: INVALID_ONION_HMAC */ +u8 *towire_invalid_onion_hmac(const tal_t *ctx, const struct sha256 *sha256_of_onion) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_INVALID_ONION_HMAC); + towire_sha256(&p, sha256_of_onion); + + return memcheck(p, tal_count(p)); +} +bool fromwire_invalid_onion_hmac(const void *p, struct sha256 *sha256_of_onion) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_INVALID_ONION_HMAC) + return false; + fromwire_sha256(&cursor, &plen, sha256_of_onion); + return cursor != NULL; +} + +/* WIRE: INVALID_ONION_KEY */ +u8 *towire_invalid_onion_key(const tal_t *ctx, const struct sha256 *sha256_of_onion) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_INVALID_ONION_KEY); + towire_sha256(&p, sha256_of_onion); + + return memcheck(p, tal_count(p)); +} +bool fromwire_invalid_onion_key(const void *p, struct sha256 *sha256_of_onion) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_INVALID_ONION_KEY) + return false; + fromwire_sha256(&cursor, &plen, sha256_of_onion); + return cursor != NULL; +} + +/* WIRE: TEMPORARY_CHANNEL_FAILURE */ +u8 *towire_temporary_channel_failure(const tal_t *ctx, const u8 *channel_update) +{ + u16 len = tal_count(channel_update); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_TEMPORARY_CHANNEL_FAILURE); + towire_u16(&p, len); + towire_u8_array(&p, channel_update, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_temporary_channel_failure(const tal_t *ctx, const void *p, u8 **channel_update) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_TEMPORARY_CHANNEL_FAILURE) + return false; + len = fromwire_u16(&cursor, &plen); + // 2nd case channel_update + *channel_update = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *channel_update, len); + return cursor != NULL; +} + +/* WIRE: PERMANENT_CHANNEL_FAILURE */ +u8 *towire_permanent_channel_failure(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_PERMANENT_CHANNEL_FAILURE); + + return memcheck(p, tal_count(p)); +} +bool fromwire_permanent_channel_failure(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_PERMANENT_CHANNEL_FAILURE) + return false; + return cursor != NULL; +} + +/* WIRE: REQUIRED_CHANNEL_FEATURE_MISSING */ +u8 *towire_required_channel_feature_missing(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_REQUIRED_CHANNEL_FEATURE_MISSING); + + return memcheck(p, tal_count(p)); +} +bool fromwire_required_channel_feature_missing(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_REQUIRED_CHANNEL_FEATURE_MISSING) + return false; + return cursor != NULL; +} + +/* WIRE: UNKNOWN_NEXT_PEER */ +u8 *towire_unknown_next_peer(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_UNKNOWN_NEXT_PEER); + + return memcheck(p, tal_count(p)); +} +bool fromwire_unknown_next_peer(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_UNKNOWN_NEXT_PEER) + return false; + return cursor != NULL; +} + +/* WIRE: AMOUNT_BELOW_MINIMUM */ +u8 *towire_amount_below_minimum(const tal_t *ctx, struct amount_msat htlc_msat, const u8 *channel_update) +{ + u16 len = tal_count(channel_update); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_AMOUNT_BELOW_MINIMUM); + towire_amount_msat(&p, htlc_msat); + towire_u16(&p, len); + towire_u8_array(&p, channel_update, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_amount_below_minimum(const tal_t *ctx, const void *p, struct amount_msat *htlc_msat, u8 **channel_update) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_AMOUNT_BELOW_MINIMUM) + return false; + *htlc_msat = fromwire_amount_msat(&cursor, &plen); + len = fromwire_u16(&cursor, &plen); + // 2nd case channel_update + *channel_update = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *channel_update, len); + return cursor != NULL; +} + +/* WIRE: FEE_INSUFFICIENT */ +u8 *towire_fee_insufficient(const tal_t *ctx, struct amount_msat htlc_msat, const u8 *channel_update) +{ + u16 len = tal_count(channel_update); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_FEE_INSUFFICIENT); + towire_amount_msat(&p, htlc_msat); + towire_u16(&p, len); + towire_u8_array(&p, channel_update, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_fee_insufficient(const tal_t *ctx, const void *p, struct amount_msat *htlc_msat, u8 **channel_update) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_FEE_INSUFFICIENT) + return false; + *htlc_msat = fromwire_amount_msat(&cursor, &plen); + len = fromwire_u16(&cursor, &plen); + // 2nd case channel_update + *channel_update = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *channel_update, len); + return cursor != NULL; +} + +/* WIRE: INCORRECT_CLTV_EXPIRY */ +u8 *towire_incorrect_cltv_expiry(const tal_t *ctx, u32 cltv_expiry, const u8 *channel_update) +{ + u16 len = tal_count(channel_update); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_INCORRECT_CLTV_EXPIRY); + towire_u32(&p, cltv_expiry); + towire_u16(&p, len); + towire_u8_array(&p, channel_update, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_incorrect_cltv_expiry(const tal_t *ctx, const void *p, u32 *cltv_expiry, u8 **channel_update) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_INCORRECT_CLTV_EXPIRY) + return false; + *cltv_expiry = fromwire_u32(&cursor, &plen); + len = fromwire_u16(&cursor, &plen); + // 2nd case channel_update + *channel_update = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *channel_update, len); + return cursor != NULL; +} + +/* WIRE: EXPIRY_TOO_SOON */ +u8 *towire_expiry_too_soon(const tal_t *ctx, const u8 *channel_update) +{ + u16 len = tal_count(channel_update); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_EXPIRY_TOO_SOON); + towire_u16(&p, len); + towire_u8_array(&p, channel_update, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_expiry_too_soon(const tal_t *ctx, const void *p, u8 **channel_update) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_EXPIRY_TOO_SOON) + return false; + len = fromwire_u16(&cursor, &plen); + // 2nd case channel_update + *channel_update = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *channel_update, len); + return cursor != NULL; +} + +/* WIRE: INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS */ +u8 *towire_incorrect_or_unknown_payment_details(const tal_t *ctx, struct amount_msat htlc_msat, u32 height) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS); + towire_amount_msat(&p, htlc_msat); + towire_u32(&p, height); + + return memcheck(p, tal_count(p)); +} +bool fromwire_incorrect_or_unknown_payment_details(const void *p, struct amount_msat *htlc_msat, u32 *height) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS) + return false; + *htlc_msat = fromwire_amount_msat(&cursor, &plen); + *height = fromwire_u32(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: FINAL_INCORRECT_CLTV_EXPIRY */ +u8 *towire_final_incorrect_cltv_expiry(const tal_t *ctx, u32 cltv_expiry) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_FINAL_INCORRECT_CLTV_EXPIRY); + towire_u32(&p, cltv_expiry); + + return memcheck(p, tal_count(p)); +} +bool fromwire_final_incorrect_cltv_expiry(const void *p, u32 *cltv_expiry) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_FINAL_INCORRECT_CLTV_EXPIRY) + return false; + *cltv_expiry = fromwire_u32(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: FINAL_INCORRECT_HTLC_AMOUNT */ +u8 *towire_final_incorrect_htlc_amount(const tal_t *ctx, struct amount_msat incoming_htlc_amt) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_FINAL_INCORRECT_HTLC_AMOUNT); + towire_amount_msat(&p, incoming_htlc_amt); + + return memcheck(p, tal_count(p)); +} +bool fromwire_final_incorrect_htlc_amount(const void *p, struct amount_msat *incoming_htlc_amt) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_FINAL_INCORRECT_HTLC_AMOUNT) + return false; + *incoming_htlc_amt = fromwire_amount_msat(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CHANNEL_DISABLED */ +u8 *towire_channel_disabled(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNEL_DISABLED); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channel_disabled(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNEL_DISABLED) + return false; + return cursor != NULL; +} + +/* WIRE: EXPIRY_TOO_FAR */ +u8 *towire_expiry_too_far(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_EXPIRY_TOO_FAR); + + return memcheck(p, tal_count(p)); +} +bool fromwire_expiry_too_far(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_EXPIRY_TOO_FAR) + return false; + return cursor != NULL; +} + +/* WIRE: INVALID_ONION_PAYLOAD */ +u8 *towire_invalid_onion_payload(const tal_t *ctx, bigsize type, u16 offset) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_INVALID_ONION_PAYLOAD); + towire_bigsize(&p, type); + towire_u16(&p, offset); + + return memcheck(p, tal_count(p)); +} +bool fromwire_invalid_onion_payload(const void *p, bigsize *type, u16 *offset) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_INVALID_ONION_PAYLOAD) + return false; + *type = fromwire_bigsize(&cursor, &plen); + *offset = fromwire_u16(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: MPP_TIMEOUT */ +u8 *towire_mpp_timeout(const tal_t *ctx) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_MPP_TIMEOUT); + + return memcheck(p, tal_count(p)); +} +bool fromwire_mpp_timeout(const void *p) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_MPP_TIMEOUT) + return false; + return cursor != NULL; +} + +// SHA256STAMP:exp-0-fb3c7a1b699d41c2fe76eb380a851fe8aea7a15e7740ce2bfdcb3fcf173a1e8a diff --git a/wire/onion_wiregen.h b/wire/onion_wiregen.h new file mode 100644 index 000000000..736f97a8b --- /dev/null +++ b/wire/onion_wiregen.h @@ -0,0 +1,211 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the _csv file it was generated from. */ +/* Original template can be found at tools/gen/header_template */ + +#ifndef LIGHTNING_WIRE_ONION_WIREGEN_H +#define LIGHTNING_WIRE_ONION_WIREGEN_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum onion_wire { + WIRE_INVALID_REALM = PERM|1, + WIRE_TEMPORARY_NODE_FAILURE = NODE|2, + WIRE_PERMANENT_NODE_FAILURE = PERM|NODE|2, + WIRE_REQUIRED_NODE_FEATURE_MISSING = PERM|NODE|3, + WIRE_INVALID_ONION_VERSION = BADONION|PERM|4, + WIRE_INVALID_ONION_HMAC = BADONION|PERM|5, + WIRE_INVALID_ONION_KEY = BADONION|PERM|6, + WIRE_TEMPORARY_CHANNEL_FAILURE = UPDATE|7, + WIRE_PERMANENT_CHANNEL_FAILURE = PERM|8, + WIRE_REQUIRED_CHANNEL_FEATURE_MISSING = PERM|9, + WIRE_UNKNOWN_NEXT_PEER = PERM|10, + WIRE_AMOUNT_BELOW_MINIMUM = UPDATE|11, + WIRE_FEE_INSUFFICIENT = UPDATE|12, + WIRE_INCORRECT_CLTV_EXPIRY = UPDATE|13, + WIRE_EXPIRY_TOO_SOON = UPDATE|14, + WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS = PERM|15, + WIRE_FINAL_INCORRECT_CLTV_EXPIRY = 18, + WIRE_FINAL_INCORRECT_HTLC_AMOUNT = 19, + WIRE_CHANNEL_DISABLED = UPDATE|20, + WIRE_EXPIRY_TOO_FAR = 21, + WIRE_INVALID_ONION_PAYLOAD = PERM|22, + WIRE_MPP_TIMEOUT = 23, +}; + +const char *onion_wire_name(int e); + +/** + * Determine whether a given message type is defined as a message. + * + * Returns true if the message type is part of the message definitions we have + * generated parsers for, false if it is a custom message that cannot be + * handled internally. + */ +bool onion_wire_is_defined(u16 type); + +struct tlv_tlv_payload_payment_data { + struct secret payment_secret; + u64 total_msat; +}; +struct tlv_tlv_payload { + /* Raw fields including unknown ones. */ + struct tlv_field *fields; + + /* TODO The following explicit fields could just point into the + * tlv_field entries above to save on memory. */ + u64 *amt_to_forward; + u32 *outgoing_cltv_value; + struct short_channel_id *short_channel_id; + struct tlv_tlv_payload_payment_data *payment_data; +}; + +struct tlv_tlv_payload *tlv_tlv_payload_new(const tal_t *ctx); + +/** + * Deserialize a TLV stream for the tlv_payload namespace. + * + * This function will parse any TLV stream, as long as the type, length and + * value fields are formatted correctly. Fields that are not known in the + * current namespace are stored in the `fields` member. Validity can be + * checked using tlv_payload_is_valid. + */ +bool fromwire_tlv_payload(const u8 **cursor, size_t *max, + struct tlv_tlv_payload * record); + +/** + * Serialize a TLV stream for the tlv_payload namespace. + * + * This function only considers known fields from the tlv_payload namespace, + * and will ignore any fields that may be stored in the `fields` member. This + * ensures that the resulting stream is valid according to + * `tlv_payload_is_valid`. + */ +void towire_tlv_payload(u8 **pptr, const void *record); + +/** + * Check that the TLV stream is valid. + * + * Enforces the followin validity rules: + * - Types must be in monotonic non-repeating order + * - We must understand all even types + * + * Returns false if an error was detected, otherwise returns true. If err_index + * is non-null and we detect an error it is set to the index of the first error + * detected. + */ +bool tlv_payload_is_valid(const struct tlv_tlv_payload *record, + size_t *err_index); + +#define TLVS_TLV_PAYLOAD_ARRAY_SIZE 4 +extern const struct tlv_record_type tlvs_tlv_payload[]; + + + +/* Define an enum with the constants */ +enum tlv_payload_types { + TLV_TLV_PAYLOAD_AMT_TO_FORWARD = 2, + TLV_TLV_PAYLOAD_OUTGOING_CLTV_VALUE = 4, + TLV_TLV_PAYLOAD_SHORT_CHANNEL_ID = 6, + TLV_TLV_PAYLOAD_PAYMENT_DATA = 8, +}; + +/* WIRE: INVALID_REALM */ +u8 *towire_invalid_realm(const tal_t *ctx); +bool fromwire_invalid_realm(const void *p); + +/* WIRE: TEMPORARY_NODE_FAILURE */ +u8 *towire_temporary_node_failure(const tal_t *ctx); +bool fromwire_temporary_node_failure(const void *p); + +/* WIRE: PERMANENT_NODE_FAILURE */ +u8 *towire_permanent_node_failure(const tal_t *ctx); +bool fromwire_permanent_node_failure(const void *p); + +/* WIRE: REQUIRED_NODE_FEATURE_MISSING */ +u8 *towire_required_node_feature_missing(const tal_t *ctx); +bool fromwire_required_node_feature_missing(const void *p); + +/* WIRE: INVALID_ONION_VERSION */ +u8 *towire_invalid_onion_version(const tal_t *ctx, const struct sha256 *sha256_of_onion); +bool fromwire_invalid_onion_version(const void *p, struct sha256 *sha256_of_onion); + +/* WIRE: INVALID_ONION_HMAC */ +u8 *towire_invalid_onion_hmac(const tal_t *ctx, const struct sha256 *sha256_of_onion); +bool fromwire_invalid_onion_hmac(const void *p, struct sha256 *sha256_of_onion); + +/* WIRE: INVALID_ONION_KEY */ +u8 *towire_invalid_onion_key(const tal_t *ctx, const struct sha256 *sha256_of_onion); +bool fromwire_invalid_onion_key(const void *p, struct sha256 *sha256_of_onion); + +/* WIRE: TEMPORARY_CHANNEL_FAILURE */ +u8 *towire_temporary_channel_failure(const tal_t *ctx, const u8 *channel_update); +bool fromwire_temporary_channel_failure(const tal_t *ctx, const void *p, u8 **channel_update); + +/* WIRE: PERMANENT_CHANNEL_FAILURE */ +u8 *towire_permanent_channel_failure(const tal_t *ctx); +bool fromwire_permanent_channel_failure(const void *p); + +/* WIRE: REQUIRED_CHANNEL_FEATURE_MISSING */ +u8 *towire_required_channel_feature_missing(const tal_t *ctx); +bool fromwire_required_channel_feature_missing(const void *p); + +/* WIRE: UNKNOWN_NEXT_PEER */ +u8 *towire_unknown_next_peer(const tal_t *ctx); +bool fromwire_unknown_next_peer(const void *p); + +/* WIRE: AMOUNT_BELOW_MINIMUM */ +u8 *towire_amount_below_minimum(const tal_t *ctx, struct amount_msat htlc_msat, const u8 *channel_update); +bool fromwire_amount_below_minimum(const tal_t *ctx, const void *p, struct amount_msat *htlc_msat, u8 **channel_update); + +/* WIRE: FEE_INSUFFICIENT */ +u8 *towire_fee_insufficient(const tal_t *ctx, struct amount_msat htlc_msat, const u8 *channel_update); +bool fromwire_fee_insufficient(const tal_t *ctx, const void *p, struct amount_msat *htlc_msat, u8 **channel_update); + +/* WIRE: INCORRECT_CLTV_EXPIRY */ +u8 *towire_incorrect_cltv_expiry(const tal_t *ctx, u32 cltv_expiry, const u8 *channel_update); +bool fromwire_incorrect_cltv_expiry(const tal_t *ctx, const void *p, u32 *cltv_expiry, u8 **channel_update); + +/* WIRE: EXPIRY_TOO_SOON */ +u8 *towire_expiry_too_soon(const tal_t *ctx, const u8 *channel_update); +bool fromwire_expiry_too_soon(const tal_t *ctx, const void *p, u8 **channel_update); + +/* WIRE: INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS */ +u8 *towire_incorrect_or_unknown_payment_details(const tal_t *ctx, struct amount_msat htlc_msat, u32 height); +bool fromwire_incorrect_or_unknown_payment_details(const void *p, struct amount_msat *htlc_msat, u32 *height); + +/* WIRE: FINAL_INCORRECT_CLTV_EXPIRY */ +u8 *towire_final_incorrect_cltv_expiry(const tal_t *ctx, u32 cltv_expiry); +bool fromwire_final_incorrect_cltv_expiry(const void *p, u32 *cltv_expiry); + +/* WIRE: FINAL_INCORRECT_HTLC_AMOUNT */ +u8 *towire_final_incorrect_htlc_amount(const tal_t *ctx, struct amount_msat incoming_htlc_amt); +bool fromwire_final_incorrect_htlc_amount(const void *p, struct amount_msat *incoming_htlc_amt); + +/* WIRE: CHANNEL_DISABLED */ +u8 *towire_channel_disabled(const tal_t *ctx); +bool fromwire_channel_disabled(const void *p); + +/* WIRE: EXPIRY_TOO_FAR */ +u8 *towire_expiry_too_far(const tal_t *ctx); +bool fromwire_expiry_too_far(const void *p); + +/* WIRE: INVALID_ONION_PAYLOAD */ +u8 *towire_invalid_onion_payload(const tal_t *ctx, bigsize type, u16 offset); +bool fromwire_invalid_onion_payload(const void *p, bigsize *type, u16 *offset); + +/* WIRE: MPP_TIMEOUT */ +u8 *towire_mpp_timeout(const tal_t *ctx); +bool fromwire_mpp_timeout(const void *p); + + +#endif /* LIGHTNING_WIRE_ONION_WIREGEN_H */ + +// SHA256STAMP:exp-0-fb3c7a1b699d41c2fe76eb380a851fe8aea7a15e7740ce2bfdcb3fcf173a1e8a diff --git a/wire/peer_printgen.c b/wire/peer_printgen.c new file mode 100644 index 000000000..0ec089918 --- /dev/null +++ b/wire/peer_printgen.c @@ -0,0 +1,2040 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ + +#include "wire/peer_printgen.h" +#include +#include +#include +#include +#include +#include + +void printpeer_wire_message(const u8 *msg) +{ + switch ((enum peer_wire)fromwire_peektype(msg)) { + case WIRE_INIT: + printf("WIRE_INIT:\n"); + printwire_init("init", msg); + return; + case WIRE_ERROR: + printf("WIRE_ERROR:\n"); + printwire_error("error", msg); + return; + case WIRE_PING: + printf("WIRE_PING:\n"); + printwire_ping("ping", msg); + return; + case WIRE_PONG: + printf("WIRE_PONG:\n"); + printwire_pong("pong", msg); + return; + case WIRE_OPEN_CHANNEL: + printf("WIRE_OPEN_CHANNEL:\n"); + printwire_open_channel("open_channel", msg); + return; + case WIRE_ACCEPT_CHANNEL: + printf("WIRE_ACCEPT_CHANNEL:\n"); + printwire_accept_channel("accept_channel", msg); + return; + case WIRE_FUNDING_CREATED: + printf("WIRE_FUNDING_CREATED:\n"); + printwire_funding_created("funding_created", msg); + return; + case WIRE_FUNDING_SIGNED: + printf("WIRE_FUNDING_SIGNED:\n"); + printwire_funding_signed("funding_signed", msg); + return; + case WIRE_FUNDING_LOCKED: + printf("WIRE_FUNDING_LOCKED:\n"); + printwire_funding_locked("funding_locked", msg); + return; + case WIRE_SHUTDOWN: + printf("WIRE_SHUTDOWN:\n"); + printwire_shutdown("shutdown", msg); + return; + case WIRE_CLOSING_SIGNED: + printf("WIRE_CLOSING_SIGNED:\n"); + printwire_closing_signed("closing_signed", msg); + return; + case WIRE_UPDATE_ADD_HTLC: + printf("WIRE_UPDATE_ADD_HTLC:\n"); + printwire_update_add_htlc("update_add_htlc", msg); + return; + case WIRE_UPDATE_FULFILL_HTLC: + printf("WIRE_UPDATE_FULFILL_HTLC:\n"); + printwire_update_fulfill_htlc("update_fulfill_htlc", msg); + return; + case WIRE_UPDATE_FAIL_HTLC: + printf("WIRE_UPDATE_FAIL_HTLC:\n"); + printwire_update_fail_htlc("update_fail_htlc", msg); + return; + case WIRE_UPDATE_FAIL_MALFORMED_HTLC: + printf("WIRE_UPDATE_FAIL_MALFORMED_HTLC:\n"); + printwire_update_fail_malformed_htlc("update_fail_malformed_htlc", msg); + return; + case WIRE_COMMITMENT_SIGNED: + printf("WIRE_COMMITMENT_SIGNED:\n"); + printwire_commitment_signed("commitment_signed", msg); + return; + case WIRE_REVOKE_AND_ACK: + printf("WIRE_REVOKE_AND_ACK:\n"); + printwire_revoke_and_ack("revoke_and_ack", msg); + return; + case WIRE_UPDATE_FEE: + printf("WIRE_UPDATE_FEE:\n"); + printwire_update_fee("update_fee", msg); + return; + case WIRE_CHANNEL_REESTABLISH: + printf("WIRE_CHANNEL_REESTABLISH:\n"); + printwire_channel_reestablish("channel_reestablish", msg); + return; + case WIRE_ANNOUNCEMENT_SIGNATURES: + printf("WIRE_ANNOUNCEMENT_SIGNATURES:\n"); + printwire_announcement_signatures("announcement_signatures", msg); + return; + case WIRE_CHANNEL_ANNOUNCEMENT: + printf("WIRE_CHANNEL_ANNOUNCEMENT:\n"); + printwire_channel_announcement("channel_announcement", msg); + return; + case WIRE_NODE_ANNOUNCEMENT: + printf("WIRE_NODE_ANNOUNCEMENT:\n"); + printwire_node_announcement("node_announcement", msg); + return; + case WIRE_CHANNEL_UPDATE: + printf("WIRE_CHANNEL_UPDATE:\n"); + printwire_channel_update("channel_update", msg); + return; + case WIRE_QUERY_SHORT_CHANNEL_IDS: + printf("WIRE_QUERY_SHORT_CHANNEL_IDS:\n"); + printwire_query_short_channel_ids("query_short_channel_ids", msg); + return; + case WIRE_REPLY_SHORT_CHANNEL_IDS_END: + printf("WIRE_REPLY_SHORT_CHANNEL_IDS_END:\n"); + printwire_reply_short_channel_ids_end("reply_short_channel_ids_end", msg); + return; + case WIRE_QUERY_CHANNEL_RANGE: + printf("WIRE_QUERY_CHANNEL_RANGE:\n"); + printwire_query_channel_range("query_channel_range", msg); + return; + case WIRE_REPLY_CHANNEL_RANGE: + printf("WIRE_REPLY_CHANNEL_RANGE:\n"); + printwire_reply_channel_range("reply_channel_range", msg); + return; + case WIRE_GOSSIP_TIMESTAMP_FILTER: + printf("WIRE_GOSSIP_TIMESTAMP_FILTER:\n"); + printwire_gossip_timestamp_filter("gossip_timestamp_filter", msg); + return; + } + + printf("UNKNOWN: %s\\n", tal_hex(msg, msg)); +} + + +void printwire_channel_update_checksums(const char *fieldname, const u8 **cursor, size_t *plen) +{ + + printf("checksum_node_id_1="); + u32 checksum_node_id_1 = fromwire_u32(cursor, plen); + + printwire_u32(tal_fmt(NULL, "%s.checksum_node_id_1", fieldname), &checksum_node_id_1); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("checksum_node_id_2="); + u32 checksum_node_id_2 = fromwire_u32(cursor, plen); + + printwire_u32(tal_fmt(NULL, "%s.checksum_node_id_2", fieldname), &checksum_node_id_2); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} + +void printwire_channel_update_timestamps(const char *fieldname, const u8 **cursor, size_t *plen) +{ + + printf("timestamp_node_id_1="); + u32 timestamp_node_id_1 = fromwire_u32(cursor, plen); + + printwire_u32(tal_fmt(NULL, "%s.timestamp_node_id_1", fieldname), ×tamp_node_id_1); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("timestamp_node_id_2="); + u32 timestamp_node_id_2 = fromwire_u32(cursor, plen); + + printwire_u32(tal_fmt(NULL, "%s.timestamp_node_id_2", fieldname), ×tamp_node_id_2); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} + +static void printwire_tlv_init_tlvs_networks(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "networks"); + + printf("chains="); + printf("["); + for (size_t i = 0; i < *plen; i++) { + struct bitcoin_blkid v; + fromwire_bitcoin_blkid(cursor, plen, &v); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + printwire_bitcoin_blkid(tal_fmt(NULL, "%s.chains", fieldname), &v); + } + printf("]"); + + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} + +static const struct tlv_print_record_type print_tlvs_init_tlvs[] = { + { 1, printwire_tlv_init_tlvs_networks }, +}; + +static void printwire_tlv_n1_tlv1(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "tlv1"); + + printf("amount_msat="); + u64 amount_msat = fromwire_tu64(cursor, plen); + + printwire_u64(tal_fmt(NULL, "%s.amount_msat", fieldname), &amount_msat); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} +static void printwire_tlv_n1_tlv2(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "tlv2"); + + printf("scid="); + struct short_channel_id scid; + fromwire_short_channel_id(cursor, plen, &scid); + + printwire_short_channel_id(tal_fmt(NULL, "%s.scid", fieldname), &scid); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} +static void printwire_tlv_n1_tlv3(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "tlv3"); + + printf("node_id="); + struct pubkey node_id; + fromwire_pubkey(cursor, plen, &node_id); + + printwire_pubkey(tal_fmt(NULL, "%s.node_id", fieldname), &node_id); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("amount_msat_1="); + struct amount_msat amount_msat_1 = fromwire_amount_msat(cursor, plen); + + printwire_amount_msat(tal_fmt(NULL, "%s.amount_msat_1", fieldname), &amount_msat_1); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("amount_msat_2="); + struct amount_msat amount_msat_2 = fromwire_amount_msat(cursor, plen); + + printwire_amount_msat(tal_fmt(NULL, "%s.amount_msat_2", fieldname), &amount_msat_2); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} +static void printwire_tlv_n1_tlv4(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "tlv4"); + + printf("cltv_delta="); + u16 cltv_delta = fromwire_u16(cursor, plen); + + printwire_u16(tal_fmt(NULL, "%s.cltv_delta", fieldname), &cltv_delta); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} + +static const struct tlv_print_record_type print_tlvs_n1[] = { + { 1, printwire_tlv_n1_tlv1 }, + { 2, printwire_tlv_n1_tlv2 }, + { 3, printwire_tlv_n1_tlv3 }, + { 254, printwire_tlv_n1_tlv4 }, +}; + +static void printwire_tlv_n2_tlv1(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "tlv1"); + + printf("amount_msat="); + u64 amount_msat = fromwire_tu64(cursor, plen); + + printwire_u64(tal_fmt(NULL, "%s.amount_msat", fieldname), &amount_msat); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} +static void printwire_tlv_n2_tlv2(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "tlv2"); + + printf("cltv_expiry="); + u32 cltv_expiry = fromwire_tu32(cursor, plen); + + printwire_u32(tal_fmt(NULL, "%s.cltv_expiry", fieldname), &cltv_expiry); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} + +static const struct tlv_print_record_type print_tlvs_n2[] = { + { 0, printwire_tlv_n2_tlv1 }, + { 11, printwire_tlv_n2_tlv2 }, +}; + +static void printwire_tlv_open_channel_tlvs_upfront_shutdown_script(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "upfront_shutdown_script"); + + printf("shutdown_scriptpubkey="); + printwire_u8_array(tal_fmt(NULL, "%s.shutdown_scriptpubkey", fieldname), cursor, plen, *plen); + + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} + +static const struct tlv_print_record_type print_tlvs_open_channel_tlvs[] = { + { 0, printwire_tlv_open_channel_tlvs_upfront_shutdown_script }, +}; + +static void printwire_tlv_accept_channel_tlvs_upfront_shutdown_script(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "upfront_shutdown_script"); + + printf("shutdown_scriptpubkey="); + printwire_u8_array(tal_fmt(NULL, "%s.shutdown_scriptpubkey", fieldname), cursor, plen, *plen); + + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} + +static const struct tlv_print_record_type print_tlvs_accept_channel_tlvs[] = { + { 0, printwire_tlv_accept_channel_tlvs_upfront_shutdown_script }, +}; + +static void printwire_tlv_query_short_channel_ids_tlvs_query_flags(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "query_flags"); + + printf("encoding_type="); + u8 encoding_type = fromwire_u8(cursor, plen); + + printwire_u8(tal_fmt(NULL, "%s.encoding_type", fieldname), &encoding_type); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("encoded_query_flags="); + printwire_u8_array(tal_fmt(NULL, "%s.encoded_query_flags", fieldname), cursor, plen, *plen); + + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} + +static const struct tlv_print_record_type print_tlvs_query_short_channel_ids_tlvs[] = { + { 1, printwire_tlv_query_short_channel_ids_tlvs_query_flags }, +}; + +static void printwire_tlv_query_channel_range_tlvs_query_option(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "query_option"); + + printf("query_option_flags="); + bigsize query_option_flags = fromwire_bigsize(cursor, plen); + + printwire_bigsize(tal_fmt(NULL, "%s.query_option_flags", fieldname), &query_option_flags); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} + +static const struct tlv_print_record_type print_tlvs_query_channel_range_tlvs[] = { + { 1, printwire_tlv_query_channel_range_tlvs_query_option }, +}; + +static void printwire_tlv_reply_channel_range_tlvs_timestamps_tlv(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "timestamps_tlv"); + + printf("encoding_type="); + u8 encoding_type = fromwire_u8(cursor, plen); + + printwire_u8(tal_fmt(NULL, "%s.encoding_type", fieldname), &encoding_type); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("encoded_timestamps="); + printwire_u8_array(tal_fmt(NULL, "%s.encoded_timestamps", fieldname), cursor, plen, *plen); + + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} +static void printwire_tlv_reply_channel_range_tlvs_checksums_tlv(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "checksums_tlv"); + + printf("checksums="); + printf("["); + for (size_t i = 0; i < *plen; i++) { + printf("{\n"); + printwire_channel_update_checksums(tal_fmt(NULL, "%s.checksums", fieldname), cursor, plen); + printf("}\n"); + } + printf("]"); + + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} + +static const struct tlv_print_record_type print_tlvs_reply_channel_range_tlvs[] = { + { 1, printwire_tlv_reply_channel_range_tlvs_timestamps_tlv }, + { 3, printwire_tlv_reply_channel_range_tlvs_checksums_tlv }, +}; +void printwire_init(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_INIT) { + printf("WRONG TYPE?!\n"); + return; + } + + u16 gflen = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("globalfeatures="); + printwire_u8_array(tal_fmt(NULL, "%s.globalfeatures", fieldname), &cursor, &plen, gflen); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + u16 flen = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("features="); + printwire_u8_array(tal_fmt(NULL, "%s.features", fieldname), &cursor, &plen, flen); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("tlvs="); + printwire_tlvs(tal_fmt(NULL, "%s.tlvs", fieldname), &cursor, &plen, print_tlvs_init_tlvs, ARRAY_SIZE(print_tlvs_init_tlvs)); + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_error(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_ERROR) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("channel_id="); + struct channel_id channel_id; + fromwire_channel_id(&cursor, &plen, &channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.channel_id", fieldname), &channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + u16 len = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("data="); + printwire_u8_array(tal_fmt(NULL, "%s.data", fieldname), &cursor, &plen, len); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_ping(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_PING) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("num_pong_bytes="); + u16 num_pong_bytes = fromwire_u16(&cursor, &plen); + + printwire_u16(tal_fmt(NULL, "%s.num_pong_bytes", fieldname), &num_pong_bytes); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + u16 byteslen = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("ignored="); + printwire_u8_array(tal_fmt(NULL, "%s.ignored", fieldname), &cursor, &plen, byteslen); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_pong(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_PONG) { + printf("WRONG TYPE?!\n"); + return; + } + + u16 byteslen = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("ignored="); + printwire_u8_array(tal_fmt(NULL, "%s.ignored", fieldname), &cursor, &plen, byteslen); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_open_channel(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_OPEN_CHANNEL) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("chain_hash="); + struct bitcoin_blkid chain_hash; + fromwire_bitcoin_blkid(&cursor, &plen, &chain_hash); + + printwire_bitcoin_blkid(tal_fmt(NULL, "%s.chain_hash", fieldname), &chain_hash); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("temporary_channel_id="); + struct channel_id temporary_channel_id; + fromwire_channel_id(&cursor, &plen, &temporary_channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.temporary_channel_id", fieldname), &temporary_channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("funding_satoshis="); + struct amount_sat funding_satoshis = fromwire_amount_sat(&cursor, &plen); + + printwire_amount_sat(tal_fmt(NULL, "%s.funding_satoshis", fieldname), &funding_satoshis); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("push_msat="); + struct amount_msat push_msat = fromwire_amount_msat(&cursor, &plen); + + printwire_amount_msat(tal_fmt(NULL, "%s.push_msat", fieldname), &push_msat); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("dust_limit_satoshis="); + struct amount_sat dust_limit_satoshis = fromwire_amount_sat(&cursor, &plen); + + printwire_amount_sat(tal_fmt(NULL, "%s.dust_limit_satoshis", fieldname), &dust_limit_satoshis); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("max_htlc_value_in_flight_msat="); + struct amount_msat max_htlc_value_in_flight_msat = fromwire_amount_msat(&cursor, &plen); + + printwire_amount_msat(tal_fmt(NULL, "%s.max_htlc_value_in_flight_msat", fieldname), &max_htlc_value_in_flight_msat); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("channel_reserve_satoshis="); + struct amount_sat channel_reserve_satoshis = fromwire_amount_sat(&cursor, &plen); + + printwire_amount_sat(tal_fmt(NULL, "%s.channel_reserve_satoshis", fieldname), &channel_reserve_satoshis); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("htlc_minimum_msat="); + struct amount_msat htlc_minimum_msat = fromwire_amount_msat(&cursor, &plen); + + printwire_amount_msat(tal_fmt(NULL, "%s.htlc_minimum_msat", fieldname), &htlc_minimum_msat); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("feerate_per_kw="); + u32 feerate_per_kw = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.feerate_per_kw", fieldname), &feerate_per_kw); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("to_self_delay="); + u16 to_self_delay = fromwire_u16(&cursor, &plen); + + printwire_u16(tal_fmt(NULL, "%s.to_self_delay", fieldname), &to_self_delay); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("max_accepted_htlcs="); + u16 max_accepted_htlcs = fromwire_u16(&cursor, &plen); + + printwire_u16(tal_fmt(NULL, "%s.max_accepted_htlcs", fieldname), &max_accepted_htlcs); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("funding_pubkey="); + struct pubkey funding_pubkey; + fromwire_pubkey(&cursor, &plen, &funding_pubkey); + + printwire_pubkey(tal_fmt(NULL, "%s.funding_pubkey", fieldname), &funding_pubkey); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("revocation_basepoint="); + struct pubkey revocation_basepoint; + fromwire_pubkey(&cursor, &plen, &revocation_basepoint); + + printwire_pubkey(tal_fmt(NULL, "%s.revocation_basepoint", fieldname), &revocation_basepoint); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("payment_basepoint="); + struct pubkey payment_basepoint; + fromwire_pubkey(&cursor, &plen, &payment_basepoint); + + printwire_pubkey(tal_fmt(NULL, "%s.payment_basepoint", fieldname), &payment_basepoint); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("delayed_payment_basepoint="); + struct pubkey delayed_payment_basepoint; + fromwire_pubkey(&cursor, &plen, &delayed_payment_basepoint); + + printwire_pubkey(tal_fmt(NULL, "%s.delayed_payment_basepoint", fieldname), &delayed_payment_basepoint); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("htlc_basepoint="); + struct pubkey htlc_basepoint; + fromwire_pubkey(&cursor, &plen, &htlc_basepoint); + + printwire_pubkey(tal_fmt(NULL, "%s.htlc_basepoint", fieldname), &htlc_basepoint); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("first_per_commitment_point="); + struct pubkey first_per_commitment_point; + fromwire_pubkey(&cursor, &plen, &first_per_commitment_point); + + printwire_pubkey(tal_fmt(NULL, "%s.first_per_commitment_point", fieldname), &first_per_commitment_point); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("channel_flags="); + u8 channel_flags = fromwire_u8(&cursor, &plen); + + printwire_u8(tal_fmt(NULL, "%s.channel_flags", fieldname), &channel_flags); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("tlvs="); + printwire_tlvs(tal_fmt(NULL, "%s.tlvs", fieldname), &cursor, &plen, print_tlvs_open_channel_tlvs, ARRAY_SIZE(print_tlvs_open_channel_tlvs)); + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_accept_channel(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_ACCEPT_CHANNEL) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("temporary_channel_id="); + struct channel_id temporary_channel_id; + fromwire_channel_id(&cursor, &plen, &temporary_channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.temporary_channel_id", fieldname), &temporary_channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("dust_limit_satoshis="); + struct amount_sat dust_limit_satoshis = fromwire_amount_sat(&cursor, &plen); + + printwire_amount_sat(tal_fmt(NULL, "%s.dust_limit_satoshis", fieldname), &dust_limit_satoshis); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("max_htlc_value_in_flight_msat="); + struct amount_msat max_htlc_value_in_flight_msat = fromwire_amount_msat(&cursor, &plen); + + printwire_amount_msat(tal_fmt(NULL, "%s.max_htlc_value_in_flight_msat", fieldname), &max_htlc_value_in_flight_msat); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("channel_reserve_satoshis="); + struct amount_sat channel_reserve_satoshis = fromwire_amount_sat(&cursor, &plen); + + printwire_amount_sat(tal_fmt(NULL, "%s.channel_reserve_satoshis", fieldname), &channel_reserve_satoshis); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("htlc_minimum_msat="); + struct amount_msat htlc_minimum_msat = fromwire_amount_msat(&cursor, &plen); + + printwire_amount_msat(tal_fmt(NULL, "%s.htlc_minimum_msat", fieldname), &htlc_minimum_msat); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("minimum_depth="); + u32 minimum_depth = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.minimum_depth", fieldname), &minimum_depth); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("to_self_delay="); + u16 to_self_delay = fromwire_u16(&cursor, &plen); + + printwire_u16(tal_fmt(NULL, "%s.to_self_delay", fieldname), &to_self_delay); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("max_accepted_htlcs="); + u16 max_accepted_htlcs = fromwire_u16(&cursor, &plen); + + printwire_u16(tal_fmt(NULL, "%s.max_accepted_htlcs", fieldname), &max_accepted_htlcs); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("funding_pubkey="); + struct pubkey funding_pubkey; + fromwire_pubkey(&cursor, &plen, &funding_pubkey); + + printwire_pubkey(tal_fmt(NULL, "%s.funding_pubkey", fieldname), &funding_pubkey); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("revocation_basepoint="); + struct pubkey revocation_basepoint; + fromwire_pubkey(&cursor, &plen, &revocation_basepoint); + + printwire_pubkey(tal_fmt(NULL, "%s.revocation_basepoint", fieldname), &revocation_basepoint); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("payment_basepoint="); + struct pubkey payment_basepoint; + fromwire_pubkey(&cursor, &plen, &payment_basepoint); + + printwire_pubkey(tal_fmt(NULL, "%s.payment_basepoint", fieldname), &payment_basepoint); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("delayed_payment_basepoint="); + struct pubkey delayed_payment_basepoint; + fromwire_pubkey(&cursor, &plen, &delayed_payment_basepoint); + + printwire_pubkey(tal_fmt(NULL, "%s.delayed_payment_basepoint", fieldname), &delayed_payment_basepoint); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("htlc_basepoint="); + struct pubkey htlc_basepoint; + fromwire_pubkey(&cursor, &plen, &htlc_basepoint); + + printwire_pubkey(tal_fmt(NULL, "%s.htlc_basepoint", fieldname), &htlc_basepoint); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("first_per_commitment_point="); + struct pubkey first_per_commitment_point; + fromwire_pubkey(&cursor, &plen, &first_per_commitment_point); + + printwire_pubkey(tal_fmt(NULL, "%s.first_per_commitment_point", fieldname), &first_per_commitment_point); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("tlvs="); + printwire_tlvs(tal_fmt(NULL, "%s.tlvs", fieldname), &cursor, &plen, print_tlvs_accept_channel_tlvs, ARRAY_SIZE(print_tlvs_accept_channel_tlvs)); + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_funding_created(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_FUNDING_CREATED) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("temporary_channel_id="); + struct channel_id temporary_channel_id; + fromwire_channel_id(&cursor, &plen, &temporary_channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.temporary_channel_id", fieldname), &temporary_channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("funding_txid="); + struct bitcoin_txid funding_txid; + fromwire_bitcoin_txid(&cursor, &plen, &funding_txid); + + printwire_bitcoin_txid(tal_fmt(NULL, "%s.funding_txid", fieldname), &funding_txid); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("funding_output_index="); + u16 funding_output_index = fromwire_u16(&cursor, &plen); + + printwire_u16(tal_fmt(NULL, "%s.funding_output_index", fieldname), &funding_output_index); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("signature="); + secp256k1_ecdsa_signature signature; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, &signature); + + printwire_secp256k1_ecdsa_signature(tal_fmt(NULL, "%s.signature", fieldname), &signature); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_funding_signed(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_FUNDING_SIGNED) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("channel_id="); + struct channel_id channel_id; + fromwire_channel_id(&cursor, &plen, &channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.channel_id", fieldname), &channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("signature="); + secp256k1_ecdsa_signature signature; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, &signature); + + printwire_secp256k1_ecdsa_signature(tal_fmt(NULL, "%s.signature", fieldname), &signature); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_funding_locked(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_FUNDING_LOCKED) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("channel_id="); + struct channel_id channel_id; + fromwire_channel_id(&cursor, &plen, &channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.channel_id", fieldname), &channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("next_per_commitment_point="); + struct pubkey next_per_commitment_point; + fromwire_pubkey(&cursor, &plen, &next_per_commitment_point); + + printwire_pubkey(tal_fmt(NULL, "%s.next_per_commitment_point", fieldname), &next_per_commitment_point); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_shutdown(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_SHUTDOWN) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("channel_id="); + struct channel_id channel_id; + fromwire_channel_id(&cursor, &plen, &channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.channel_id", fieldname), &channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + u16 len = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("scriptpubkey="); + printwire_u8_array(tal_fmt(NULL, "%s.scriptpubkey", fieldname), &cursor, &plen, len); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_closing_signed(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_CLOSING_SIGNED) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("channel_id="); + struct channel_id channel_id; + fromwire_channel_id(&cursor, &plen, &channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.channel_id", fieldname), &channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("fee_satoshis="); + struct amount_sat fee_satoshis = fromwire_amount_sat(&cursor, &plen); + + printwire_amount_sat(tal_fmt(NULL, "%s.fee_satoshis", fieldname), &fee_satoshis); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("signature="); + secp256k1_ecdsa_signature signature; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, &signature); + + printwire_secp256k1_ecdsa_signature(tal_fmt(NULL, "%s.signature", fieldname), &signature); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_update_add_htlc(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_UPDATE_ADD_HTLC) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("channel_id="); + struct channel_id channel_id; + fromwire_channel_id(&cursor, &plen, &channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.channel_id", fieldname), &channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("id="); + u64 id = fromwire_u64(&cursor, &plen); + + printwire_u64(tal_fmt(NULL, "%s.id", fieldname), &id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("amount_msat="); + struct amount_msat amount_msat = fromwire_amount_msat(&cursor, &plen); + + printwire_amount_msat(tal_fmt(NULL, "%s.amount_msat", fieldname), &amount_msat); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("payment_hash="); + struct sha256 payment_hash; + fromwire_sha256(&cursor, &plen, &payment_hash); + + printwire_sha256(tal_fmt(NULL, "%s.payment_hash", fieldname), &payment_hash); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("cltv_expiry="); + u32 cltv_expiry = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.cltv_expiry", fieldname), &cltv_expiry); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("onion_routing_packet="); + printwire_u8_array(tal_fmt(NULL, "%s.onion_routing_packet", fieldname), &cursor, &plen, 1366); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_update_fulfill_htlc(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_UPDATE_FULFILL_HTLC) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("channel_id="); + struct channel_id channel_id; + fromwire_channel_id(&cursor, &plen, &channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.channel_id", fieldname), &channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("id="); + u64 id = fromwire_u64(&cursor, &plen); + + printwire_u64(tal_fmt(NULL, "%s.id", fieldname), &id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("payment_preimage="); + struct preimage payment_preimage; + fromwire_preimage(&cursor, &plen, &payment_preimage); + + printwire_preimage(tal_fmt(NULL, "%s.payment_preimage", fieldname), &payment_preimage); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_update_fail_htlc(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_UPDATE_FAIL_HTLC) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("channel_id="); + struct channel_id channel_id; + fromwire_channel_id(&cursor, &plen, &channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.channel_id", fieldname), &channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("id="); + u64 id = fromwire_u64(&cursor, &plen); + + printwire_u64(tal_fmt(NULL, "%s.id", fieldname), &id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + u16 len = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("reason="); + printwire_u8_array(tal_fmt(NULL, "%s.reason", fieldname), &cursor, &plen, len); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_update_fail_malformed_htlc(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_UPDATE_FAIL_MALFORMED_HTLC) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("channel_id="); + struct channel_id channel_id; + fromwire_channel_id(&cursor, &plen, &channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.channel_id", fieldname), &channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("id="); + u64 id = fromwire_u64(&cursor, &plen); + + printwire_u64(tal_fmt(NULL, "%s.id", fieldname), &id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("sha256_of_onion="); + struct sha256 sha256_of_onion; + fromwire_sha256(&cursor, &plen, &sha256_of_onion); + + printwire_sha256(tal_fmt(NULL, "%s.sha256_of_onion", fieldname), &sha256_of_onion); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("failure_code="); + u16 failure_code = fromwire_u16(&cursor, &plen); + + printwire_u16(tal_fmt(NULL, "%s.failure_code", fieldname), &failure_code); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_commitment_signed(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_COMMITMENT_SIGNED) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("channel_id="); + struct channel_id channel_id; + fromwire_channel_id(&cursor, &plen, &channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.channel_id", fieldname), &channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("signature="); + secp256k1_ecdsa_signature signature; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, &signature); + + printwire_secp256k1_ecdsa_signature(tal_fmt(NULL, "%s.signature", fieldname), &signature); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + u16 num_htlcs = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("htlc_signature="); + printf("["); + for (size_t i = 0; i < num_htlcs; i++) { + secp256k1_ecdsa_signature v; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, &v); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + printwire_secp256k1_ecdsa_signature(tal_fmt(NULL, "%s.htlc_signature", fieldname), &v); + } + printf("]"); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_revoke_and_ack(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_REVOKE_AND_ACK) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("channel_id="); + struct channel_id channel_id; + fromwire_channel_id(&cursor, &plen, &channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.channel_id", fieldname), &channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("per_commitment_secret="); + struct secret per_commitment_secret; + fromwire_secret(&cursor, &plen, &per_commitment_secret); + + printwire_secret(tal_fmt(NULL, "%s.per_commitment_secret", fieldname), &per_commitment_secret); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("next_per_commitment_point="); + struct pubkey next_per_commitment_point; + fromwire_pubkey(&cursor, &plen, &next_per_commitment_point); + + printwire_pubkey(tal_fmt(NULL, "%s.next_per_commitment_point", fieldname), &next_per_commitment_point); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_update_fee(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_UPDATE_FEE) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("channel_id="); + struct channel_id channel_id; + fromwire_channel_id(&cursor, &plen, &channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.channel_id", fieldname), &channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("feerate_per_kw="); + u32 feerate_per_kw = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.feerate_per_kw", fieldname), &feerate_per_kw); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_channel_reestablish(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNEL_REESTABLISH) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("channel_id="); + struct channel_id channel_id; + fromwire_channel_id(&cursor, &plen, &channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.channel_id", fieldname), &channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("next_commitment_number="); + u64 next_commitment_number = fromwire_u64(&cursor, &plen); + + printwire_u64(tal_fmt(NULL, "%s.next_commitment_number", fieldname), &next_commitment_number); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("next_revocation_number="); + u64 next_revocation_number = fromwire_u64(&cursor, &plen); + + printwire_u64(tal_fmt(NULL, "%s.next_revocation_number", fieldname), &next_revocation_number); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("your_last_per_commitment_secret="); + struct secret your_last_per_commitment_secret; + fromwire_secret(&cursor, &plen, &your_last_per_commitment_secret); + + printwire_secret(tal_fmt(NULL, "%s.your_last_per_commitment_secret", fieldname), &your_last_per_commitment_secret); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("my_current_per_commitment_point="); + struct pubkey my_current_per_commitment_point; + fromwire_pubkey(&cursor, &plen, &my_current_per_commitment_point); + + printwire_pubkey(tal_fmt(NULL, "%s.my_current_per_commitment_point", fieldname), &my_current_per_commitment_point); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_announcement_signatures(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_ANNOUNCEMENT_SIGNATURES) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("channel_id="); + struct channel_id channel_id; + fromwire_channel_id(&cursor, &plen, &channel_id); + + printwire_channel_id(tal_fmt(NULL, "%s.channel_id", fieldname), &channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("short_channel_id="); + struct short_channel_id short_channel_id; + fromwire_short_channel_id(&cursor, &plen, &short_channel_id); + + printwire_short_channel_id(tal_fmt(NULL, "%s.short_channel_id", fieldname), &short_channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("node_signature="); + secp256k1_ecdsa_signature node_signature; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, &node_signature); + + printwire_secp256k1_ecdsa_signature(tal_fmt(NULL, "%s.node_signature", fieldname), &node_signature); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("bitcoin_signature="); + secp256k1_ecdsa_signature bitcoin_signature; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, &bitcoin_signature); + + printwire_secp256k1_ecdsa_signature(tal_fmt(NULL, "%s.bitcoin_signature", fieldname), &bitcoin_signature); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_channel_announcement(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNEL_ANNOUNCEMENT) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("node_signature_1="); + secp256k1_ecdsa_signature node_signature_1; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, &node_signature_1); + + printwire_secp256k1_ecdsa_signature(tal_fmt(NULL, "%s.node_signature_1", fieldname), &node_signature_1); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("node_signature_2="); + secp256k1_ecdsa_signature node_signature_2; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, &node_signature_2); + + printwire_secp256k1_ecdsa_signature(tal_fmt(NULL, "%s.node_signature_2", fieldname), &node_signature_2); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("bitcoin_signature_1="); + secp256k1_ecdsa_signature bitcoin_signature_1; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, &bitcoin_signature_1); + + printwire_secp256k1_ecdsa_signature(tal_fmt(NULL, "%s.bitcoin_signature_1", fieldname), &bitcoin_signature_1); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("bitcoin_signature_2="); + secp256k1_ecdsa_signature bitcoin_signature_2; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, &bitcoin_signature_2); + + printwire_secp256k1_ecdsa_signature(tal_fmt(NULL, "%s.bitcoin_signature_2", fieldname), &bitcoin_signature_2); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + u16 len = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("features="); + printwire_u8_array(tal_fmt(NULL, "%s.features", fieldname), &cursor, &plen, len); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("chain_hash="); + struct bitcoin_blkid chain_hash; + fromwire_bitcoin_blkid(&cursor, &plen, &chain_hash); + + printwire_bitcoin_blkid(tal_fmt(NULL, "%s.chain_hash", fieldname), &chain_hash); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("short_channel_id="); + struct short_channel_id short_channel_id; + fromwire_short_channel_id(&cursor, &plen, &short_channel_id); + + printwire_short_channel_id(tal_fmt(NULL, "%s.short_channel_id", fieldname), &short_channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("node_id_1="); + struct node_id node_id_1; + fromwire_node_id(&cursor, &plen, &node_id_1); + + printwire_node_id(tal_fmt(NULL, "%s.node_id_1", fieldname), &node_id_1); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("node_id_2="); + struct node_id node_id_2; + fromwire_node_id(&cursor, &plen, &node_id_2); + + printwire_node_id(tal_fmt(NULL, "%s.node_id_2", fieldname), &node_id_2); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("bitcoin_key_1="); + struct pubkey bitcoin_key_1; + fromwire_pubkey(&cursor, &plen, &bitcoin_key_1); + + printwire_pubkey(tal_fmt(NULL, "%s.bitcoin_key_1", fieldname), &bitcoin_key_1); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("bitcoin_key_2="); + struct pubkey bitcoin_key_2; + fromwire_pubkey(&cursor, &plen, &bitcoin_key_2); + + printwire_pubkey(tal_fmt(NULL, "%s.bitcoin_key_2", fieldname), &bitcoin_key_2); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_node_announcement(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_NODE_ANNOUNCEMENT) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("signature="); + secp256k1_ecdsa_signature signature; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, &signature); + + printwire_secp256k1_ecdsa_signature(tal_fmt(NULL, "%s.signature", fieldname), &signature); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + u16 flen = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("features="); + printwire_u8_array(tal_fmt(NULL, "%s.features", fieldname), &cursor, &plen, flen); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("timestamp="); + u32 timestamp = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.timestamp", fieldname), ×tamp); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("node_id="); + struct node_id node_id; + fromwire_node_id(&cursor, &plen, &node_id); + + printwire_node_id(tal_fmt(NULL, "%s.node_id", fieldname), &node_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("rgb_color="); + printwire_u8_array(tal_fmt(NULL, "%s.rgb_color", fieldname), &cursor, &plen, 3); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("alias="); + printwire_u8_array(tal_fmt(NULL, "%s.alias", fieldname), &cursor, &plen, 32); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + u16 addrlen = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("addresses="); + printwire_u8_array(tal_fmt(NULL, "%s.addresses", fieldname), &cursor, &plen, addrlen); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_channel_update(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNEL_UPDATE) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("signature="); + secp256k1_ecdsa_signature signature; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, &signature); + + printwire_secp256k1_ecdsa_signature(tal_fmt(NULL, "%s.signature", fieldname), &signature); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("chain_hash="); + struct bitcoin_blkid chain_hash; + fromwire_bitcoin_blkid(&cursor, &plen, &chain_hash); + + printwire_bitcoin_blkid(tal_fmt(NULL, "%s.chain_hash", fieldname), &chain_hash); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("short_channel_id="); + struct short_channel_id short_channel_id; + fromwire_short_channel_id(&cursor, &plen, &short_channel_id); + + printwire_short_channel_id(tal_fmt(NULL, "%s.short_channel_id", fieldname), &short_channel_id); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("timestamp="); + u32 timestamp = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.timestamp", fieldname), ×tamp); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("message_flags="); + u8 message_flags = fromwire_u8(&cursor, &plen); + + printwire_u8(tal_fmt(NULL, "%s.message_flags", fieldname), &message_flags); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("channel_flags="); + u8 channel_flags = fromwire_u8(&cursor, &plen); + + printwire_u8(tal_fmt(NULL, "%s.channel_flags", fieldname), &channel_flags); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("cltv_expiry_delta="); + u16 cltv_expiry_delta = fromwire_u16(&cursor, &plen); + + printwire_u16(tal_fmt(NULL, "%s.cltv_expiry_delta", fieldname), &cltv_expiry_delta); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("htlc_minimum_msat="); + struct amount_msat htlc_minimum_msat = fromwire_amount_msat(&cursor, &plen); + + printwire_amount_msat(tal_fmt(NULL, "%s.htlc_minimum_msat", fieldname), &htlc_minimum_msat); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("fee_base_msat="); + u32 fee_base_msat = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.fee_base_msat", fieldname), &fee_base_msat); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("fee_proportional_millionths="); + u32 fee_proportional_millionths = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.fee_proportional_millionths", fieldname), &fee_proportional_millionths); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + if (plen <= 0) + return; + printf("(option_channel_htlc_max):"); + printf("htlc_maximum_msat="); + struct amount_msat htlc_maximum_msat = fromwire_amount_msat(&cursor, &plen); + + printwire_amount_msat(tal_fmt(NULL, "%s.htlc_maximum_msat", fieldname), &htlc_maximum_msat); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_query_short_channel_ids(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_QUERY_SHORT_CHANNEL_IDS) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("chain_hash="); + struct bitcoin_blkid chain_hash; + fromwire_bitcoin_blkid(&cursor, &plen, &chain_hash); + + printwire_bitcoin_blkid(tal_fmt(NULL, "%s.chain_hash", fieldname), &chain_hash); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + u16 len = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("encoded_short_ids="); + printwire_u8_array(tal_fmt(NULL, "%s.encoded_short_ids", fieldname), &cursor, &plen, len); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("tlvs="); + printwire_tlvs(tal_fmt(NULL, "%s.tlvs", fieldname), &cursor, &plen, print_tlvs_query_short_channel_ids_tlvs, ARRAY_SIZE(print_tlvs_query_short_channel_ids_tlvs)); + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_reply_short_channel_ids_end(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_REPLY_SHORT_CHANNEL_IDS_END) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("chain_hash="); + struct bitcoin_blkid chain_hash; + fromwire_bitcoin_blkid(&cursor, &plen, &chain_hash); + + printwire_bitcoin_blkid(tal_fmt(NULL, "%s.chain_hash", fieldname), &chain_hash); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("full_information="); + u8 full_information = fromwire_u8(&cursor, &plen); + + printwire_u8(tal_fmt(NULL, "%s.full_information", fieldname), &full_information); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_query_channel_range(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_QUERY_CHANNEL_RANGE) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("chain_hash="); + struct bitcoin_blkid chain_hash; + fromwire_bitcoin_blkid(&cursor, &plen, &chain_hash); + + printwire_bitcoin_blkid(tal_fmt(NULL, "%s.chain_hash", fieldname), &chain_hash); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("first_blocknum="); + u32 first_blocknum = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.first_blocknum", fieldname), &first_blocknum); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("number_of_blocks="); + u32 number_of_blocks = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.number_of_blocks", fieldname), &number_of_blocks); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("tlvs="); + printwire_tlvs(tal_fmt(NULL, "%s.tlvs", fieldname), &cursor, &plen, print_tlvs_query_channel_range_tlvs, ARRAY_SIZE(print_tlvs_query_channel_range_tlvs)); + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_reply_channel_range(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_REPLY_CHANNEL_RANGE) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("chain_hash="); + struct bitcoin_blkid chain_hash; + fromwire_bitcoin_blkid(&cursor, &plen, &chain_hash); + + printwire_bitcoin_blkid(tal_fmt(NULL, "%s.chain_hash", fieldname), &chain_hash); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("first_blocknum="); + u32 first_blocknum = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.first_blocknum", fieldname), &first_blocknum); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("number_of_blocks="); + u32 number_of_blocks = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.number_of_blocks", fieldname), &number_of_blocks); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("full_information="); + u8 full_information = fromwire_u8(&cursor, &plen); + + printwire_u8(tal_fmt(NULL, "%s.full_information", fieldname), &full_information); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + u16 len = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("encoded_short_ids="); + printwire_u8_array(tal_fmt(NULL, "%s.encoded_short_ids", fieldname), &cursor, &plen, len); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("tlvs="); + printwire_tlvs(tal_fmt(NULL, "%s.tlvs", fieldname), &cursor, &plen, print_tlvs_reply_channel_range_tlvs, ARRAY_SIZE(print_tlvs_reply_channel_range_tlvs)); + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_gossip_timestamp_filter(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIP_TIMESTAMP_FILTER) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("chain_hash="); + struct bitcoin_blkid chain_hash; + fromwire_bitcoin_blkid(&cursor, &plen, &chain_hash); + + printwire_bitcoin_blkid(tal_fmt(NULL, "%s.chain_hash", fieldname), &chain_hash); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("first_timestamp="); + u32 first_timestamp = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.first_timestamp", fieldname), &first_timestamp); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("timestamp_range="); + u32 timestamp_range = fromwire_u32(&cursor, &plen); + + printwire_u32(tal_fmt(NULL, "%s.timestamp_range", fieldname), ×tamp_range); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} + +void printpeer_wire_tlv_message(const char *tlv_name, const u8 *msg) { + size_t plen = tal_count(msg); + if (strcmp(tlv_name, "init_tlvs") == 0) { + printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_init_tlvs, ARRAY_SIZE(print_tlvs_init_tlvs)); + } + if (strcmp(tlv_name, "n1") == 0) { + printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_n1, ARRAY_SIZE(print_tlvs_n1)); + } + if (strcmp(tlv_name, "n2") == 0) { + printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_n2, ARRAY_SIZE(print_tlvs_n2)); + } + if (strcmp(tlv_name, "open_channel_tlvs") == 0) { + printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_open_channel_tlvs, ARRAY_SIZE(print_tlvs_open_channel_tlvs)); + } + if (strcmp(tlv_name, "accept_channel_tlvs") == 0) { + printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_accept_channel_tlvs, ARRAY_SIZE(print_tlvs_accept_channel_tlvs)); + } + if (strcmp(tlv_name, "query_short_channel_ids_tlvs") == 0) { + printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_query_short_channel_ids_tlvs, ARRAY_SIZE(print_tlvs_query_short_channel_ids_tlvs)); + } + if (strcmp(tlv_name, "query_channel_range_tlvs") == 0) { + printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_query_channel_range_tlvs, ARRAY_SIZE(print_tlvs_query_channel_range_tlvs)); + } + if (strcmp(tlv_name, "reply_channel_range_tlvs") == 0) { + printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_reply_channel_range_tlvs, ARRAY_SIZE(print_tlvs_reply_channel_range_tlvs)); + } +} + +// SHA256STAMP:exp-0-12bb4b7e8e380207af3b51bfc2b65997753bc3d37465eed70409a21998b50238 diff --git a/wire/peer_printgen.h b/wire/peer_printgen.h new file mode 100644 index 000000000..0f29d2ad3 --- /dev/null +++ b/wire/peer_printgen.h @@ -0,0 +1,74 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Template located at tools/gen/print_header_template */ +#ifndef LIGHTNING_WIRE_PEER_PRINTGEN_H +#define LIGHTNING_WIRE_PEER_PRINTGEN_H +#include +#include + +void printpeer_wire_message(const u8 *msg); + +void printpeer_wire_tlv_message(const char *tlv_name, const u8 *msg); + +void printwire_init(const char *fieldname, const u8 *cursor); + +void printwire_error(const char *fieldname, const u8 *cursor); + +void printwire_ping(const char *fieldname, const u8 *cursor); + +void printwire_pong(const char *fieldname, const u8 *cursor); + +void printwire_open_channel(const char *fieldname, const u8 *cursor); + +void printwire_accept_channel(const char *fieldname, const u8 *cursor); + +void printwire_funding_created(const char *fieldname, const u8 *cursor); + +void printwire_funding_signed(const char *fieldname, const u8 *cursor); + +void printwire_funding_locked(const char *fieldname, const u8 *cursor); + +void printwire_shutdown(const char *fieldname, const u8 *cursor); + +void printwire_closing_signed(const char *fieldname, const u8 *cursor); + +void printwire_update_add_htlc(const char *fieldname, const u8 *cursor); + +void printwire_update_fulfill_htlc(const char *fieldname, const u8 *cursor); + +void printwire_update_fail_htlc(const char *fieldname, const u8 *cursor); + +void printwire_update_fail_malformed_htlc(const char *fieldname, const u8 *cursor); + +void printwire_commitment_signed(const char *fieldname, const u8 *cursor); + +void printwire_revoke_and_ack(const char *fieldname, const u8 *cursor); + +void printwire_update_fee(const char *fieldname, const u8 *cursor); + +void printwire_channel_reestablish(const char *fieldname, const u8 *cursor); + +void printwire_announcement_signatures(const char *fieldname, const u8 *cursor); + +void printwire_channel_announcement(const char *fieldname, const u8 *cursor); + +void printwire_node_announcement(const char *fieldname, const u8 *cursor); + +void printwire_channel_update(const char *fieldname, const u8 *cursor); + +void printwire_query_short_channel_ids(const char *fieldname, const u8 *cursor); + +void printwire_reply_short_channel_ids_end(const char *fieldname, const u8 *cursor); + +void printwire_query_channel_range(const char *fieldname, const u8 *cursor); + +void printwire_reply_channel_range(const char *fieldname, const u8 *cursor); + +void printwire_gossip_timestamp_filter(const char *fieldname, const u8 *cursor); + + +void printwire_channel_update_checksums(const char *fieldname, const u8 **cursor, size_t *plen); +void printwire_channel_update_timestamps(const char *fieldname, const u8 **cursor, size_t *plen); +#endif /* LIGHTNING_WIRE_PEER_PRINTGEN_H */ + +// SHA256STAMP:exp-0-12bb4b7e8e380207af3b51bfc2b65997753bc3d37465eed70409a21998b50238 diff --git a/wire/peer_wiregen.c b/wire/peer_wiregen.c new file mode 100644 index 000000000..3a1718553 --- /dev/null +++ b/wire/peer_wiregen.c @@ -0,0 +1,2754 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the .csv file it was generated from. */ +/* Original template can be found at tools/gen/impl_template */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef SUPERVERBOSE +#define SUPERVERBOSE(...) +#endif + + +const char *peer_wire_name(int e) +{ + static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; + + switch ((enum peer_wire)e) { + case WIRE_INIT: return "WIRE_INIT"; + case WIRE_ERROR: return "WIRE_ERROR"; + case WIRE_PING: return "WIRE_PING"; + case WIRE_PONG: return "WIRE_PONG"; + case WIRE_OPEN_CHANNEL: return "WIRE_OPEN_CHANNEL"; + case WIRE_ACCEPT_CHANNEL: return "WIRE_ACCEPT_CHANNEL"; + case WIRE_FUNDING_CREATED: return "WIRE_FUNDING_CREATED"; + case WIRE_FUNDING_SIGNED: return "WIRE_FUNDING_SIGNED"; + case WIRE_FUNDING_LOCKED: return "WIRE_FUNDING_LOCKED"; + case WIRE_SHUTDOWN: return "WIRE_SHUTDOWN"; + case WIRE_CLOSING_SIGNED: return "WIRE_CLOSING_SIGNED"; + case WIRE_UPDATE_ADD_HTLC: return "WIRE_UPDATE_ADD_HTLC"; + case WIRE_UPDATE_FULFILL_HTLC: return "WIRE_UPDATE_FULFILL_HTLC"; + case WIRE_UPDATE_FAIL_HTLC: return "WIRE_UPDATE_FAIL_HTLC"; + case WIRE_UPDATE_FAIL_MALFORMED_HTLC: return "WIRE_UPDATE_FAIL_MALFORMED_HTLC"; + case WIRE_COMMITMENT_SIGNED: return "WIRE_COMMITMENT_SIGNED"; + case WIRE_REVOKE_AND_ACK: return "WIRE_REVOKE_AND_ACK"; + case WIRE_UPDATE_FEE: return "WIRE_UPDATE_FEE"; + case WIRE_CHANNEL_REESTABLISH: return "WIRE_CHANNEL_REESTABLISH"; + case WIRE_ANNOUNCEMENT_SIGNATURES: return "WIRE_ANNOUNCEMENT_SIGNATURES"; + case WIRE_CHANNEL_ANNOUNCEMENT: return "WIRE_CHANNEL_ANNOUNCEMENT"; + case WIRE_NODE_ANNOUNCEMENT: return "WIRE_NODE_ANNOUNCEMENT"; + case WIRE_CHANNEL_UPDATE: return "WIRE_CHANNEL_UPDATE"; + case WIRE_QUERY_SHORT_CHANNEL_IDS: return "WIRE_QUERY_SHORT_CHANNEL_IDS"; + case WIRE_REPLY_SHORT_CHANNEL_IDS_END: return "WIRE_REPLY_SHORT_CHANNEL_IDS_END"; + case WIRE_QUERY_CHANNEL_RANGE: return "WIRE_QUERY_CHANNEL_RANGE"; + case WIRE_REPLY_CHANNEL_RANGE: return "WIRE_REPLY_CHANNEL_RANGE"; + case WIRE_GOSSIP_TIMESTAMP_FILTER: return "WIRE_GOSSIP_TIMESTAMP_FILTER"; + } + + snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); + return invalidbuf; +} + +bool peer_wire_is_defined(u16 type) +{ + switch ((enum peer_wire)type) { + case WIRE_INIT:; + case WIRE_ERROR:; + case WIRE_PING:; + case WIRE_PONG:; + case WIRE_OPEN_CHANNEL:; + case WIRE_ACCEPT_CHANNEL:; + case WIRE_FUNDING_CREATED:; + case WIRE_FUNDING_SIGNED:; + case WIRE_FUNDING_LOCKED:; + case WIRE_SHUTDOWN:; + case WIRE_CLOSING_SIGNED:; + case WIRE_UPDATE_ADD_HTLC:; + case WIRE_UPDATE_FULFILL_HTLC:; + case WIRE_UPDATE_FAIL_HTLC:; + case WIRE_UPDATE_FAIL_MALFORMED_HTLC:; + case WIRE_COMMITMENT_SIGNED:; + case WIRE_REVOKE_AND_ACK:; + case WIRE_UPDATE_FEE:; + case WIRE_CHANNEL_REESTABLISH:; + case WIRE_ANNOUNCEMENT_SIGNATURES:; + case WIRE_CHANNEL_ANNOUNCEMENT:; + case WIRE_NODE_ANNOUNCEMENT:; + case WIRE_CHANNEL_UPDATE:; + case WIRE_QUERY_SHORT_CHANNEL_IDS:; + case WIRE_REPLY_SHORT_CHANNEL_IDS_END:; + case WIRE_QUERY_CHANNEL_RANGE:; + case WIRE_REPLY_CHANNEL_RANGE:; + case WIRE_GOSSIP_TIMESTAMP_FILTER:; + return true; + } + return false; +} + + + + +/* SUBTYPE: CHANNEL_UPDATE_CHECKSUMS */ +void towire_channel_update_checksums(u8 **p, const struct channel_update_checksums *channel_update_checksums) +{ + + towire_u32(p, channel_update_checksums->checksum_node_id_1); + towire_u32(p, channel_update_checksums->checksum_node_id_2); +} +void fromwire_channel_update_checksums(const u8 **cursor, size_t *plen, struct channel_update_checksums *channel_update_checksums) +{ + + channel_update_checksums->checksum_node_id_1 = fromwire_u32(cursor, plen); + channel_update_checksums->checksum_node_id_2 = fromwire_u32(cursor, plen); +} + +/* SUBTYPE: CHANNEL_UPDATE_TIMESTAMPS */ +void towire_channel_update_timestamps(u8 **p, const struct channel_update_timestamps *channel_update_timestamps) +{ + + towire_u32(p, channel_update_timestamps->timestamp_node_id_1); + towire_u32(p, channel_update_timestamps->timestamp_node_id_2); +} +void fromwire_channel_update_timestamps(const u8 **cursor, size_t *plen, struct channel_update_timestamps *channel_update_timestamps) +{ + + channel_update_timestamps->timestamp_node_id_1 = fromwire_u32(cursor, plen); + channel_update_timestamps->timestamp_node_id_2 = fromwire_u32(cursor, plen); +} + + +struct tlv_init_tlvs *tlv_init_tlvs_new(const tal_t *ctx) +{ + /* Initialize everything to NULL. (Quiet, C pedants!) */ + struct tlv_init_tlvs *inst = talz(ctx, struct tlv_init_tlvs); + + /* Initialized the fields to an empty array. */ + inst->fields = tal_arr(inst, struct tlv_field, 0); + return inst; +} + +/* INIT_TLVS MSG: networks */ +static u8 *towire_tlv_init_tlvs_networks(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_init_tlvs *r = vrecord; + u8 *ptr; + + if (!r->networks) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + for (size_t i = 0; i < tal_count(r->networks); i++) + towire_bitcoin_blkid(&ptr, r->networks + i); + return ptr; +} +static void fromwire_tlv_init_tlvs_networks(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_init_tlvs *r = vrecord; + + r->networks = *plen ? tal_arr(r, struct bitcoin_blkid, 0) : NULL; + for (size_t i = 0; *plen != 0; i++) { + struct bitcoin_blkid tmp; + fromwire_bitcoin_blkid(cursor, plen, &tmp); + tal_arr_expand(&r->networks, tmp); + } +} + +static const struct tlv_record_type tlvs_init_tlvs[] = { + { 1, towire_tlv_init_tlvs_networks, fromwire_tlv_init_tlvs_networks }, +}; + +void towire_init_tlvs(u8 **pptr, + const void *record) +{ + size_t num_types = 1; + const struct tlv_record_type *types = tlvs_init_tlvs; + if (!record) + return; + + for (size_t i = 0; i < num_types; i++) { + u8 *val; + if (i != 0) + assert(types[i].type > types[i-1].type); + val = types[i].towire(NULL, record); + if (!val) + continue; + + /* BOLT #1: + * + * The sending node: + ... + * - MUST minimally encode `type` and `length`. + */ + towire_bigsize(pptr, types[i].type); + towire_bigsize(pptr, tal_bytelen(val)); + towire(pptr, val, tal_bytelen(val)); + tal_free(val); + } +} + + +bool fromwire_init_tlvs(const u8 **cursor, size_t *max, struct tlv_init_tlvs *record) +{ + size_t num_types = 1; + const struct tlv_record_type *types = tlvs_init_tlvs; + while (*max > 0) { + struct tlv_field field; + + /* BOLT #1: + * + * A `varint` is a variable-length, unsigned integer encoding + * using the [BigSize](#appendix-a-bigsize-test-vectors) + * format + */ + field.numtype = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("type"); + goto fail; + } + field.length = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("length"); + goto fail; + } + + /* BOLT #1: + * - if `length` exceeds the number of bytes remaining in the + * message: + * - MUST fail to parse the `tlv_stream`. + */ + if (field.length > *max) { + SUPERVERBOSE("value"); + goto fail; + } + field.value = tal_dup_arr(record, u8, *cursor, field.length, 0); + + /* BOLT #1: + * - if `type` is known: + * - MUST decode the next `length` bytes using the known + * encoding for `type`. + */ + field.meta = NULL; + for (size_t i = 0; i < num_types; i++) { + if (types[i].type == field.numtype) + field.meta = &types[i]; + } + + if (field.meta) { + /* Length of message can't exceed 16 bits anyway. */ + size_t tlvlen = field.length; + field.meta->fromwire(cursor, &tlvlen, record); + + if (!*cursor) + goto fail; + + /* BOLT #1: + * - if `length` is not exactly equal to that required + * for the known encoding for `type`: + * - MUST fail to parse the `tlv_stream`. + */ + if (tlvlen != 0) { + SUPERVERBOSE("greater than encoding length"); + goto fail; + } + } else { + /* We didn't read from *cursor through a fromwire, so + * update manually. */ + *cursor += field.length; + } + /* We've read bytes in ->fromwire, so update max */ + *max -= field.length; + tal_arr_expand(&record->fields, field); + } + return true; +fail: + fromwire_fail(cursor, max); + return false; +} + +bool init_tlvs_is_valid(const struct tlv_init_tlvs *record, size_t *err_index) +{ + size_t numfields = tal_count(record->fields); + bool first = true; + u64 prev_type = 0; + for (int i=0; ifields[i]; + if (f->numtype % 2 == 0 && f->meta == NULL) { + /* BOLT #1: + * - otherwise, if `type` is unknown: + * - if `type` is even: + * - MUST fail to parse the `tlv_stream`. + * - otherwise, if `type` is odd: + * - MUST discard the next `length` bytes. + */ + SUPERVERBOSE("unknown even"); + if (err_index != NULL) + *err_index = i; + return false; + } else if (!first && f->numtype <= prev_type) { + /* BOLT #1: + * - if decoded `type`s are not monotonically-increasing: + * - MUST fail to parse the `tlv_stream`. + */ + if (f->numtype == prev_type) + SUPERVERBOSE("duplicate tlv type"); + else + SUPERVERBOSE("invalid ordering"); + if (err_index != NULL) + *err_index = i; + return false; + } + first = false; + prev_type = f->numtype; + } + return true; +} + + +struct tlv_n1 *tlv_n1_new(const tal_t *ctx) +{ + /* Initialize everything to NULL. (Quiet, C pedants!) */ + struct tlv_n1 *inst = talz(ctx, struct tlv_n1); + + /* Initialized the fields to an empty array. */ + inst->fields = tal_arr(inst, struct tlv_field, 0); + return inst; +} + +/* N1 MSG: tlv1 */ +static u8 *towire_tlv_n1_tlv1(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_n1 *r = vrecord; + u8 *ptr; + + if (!r->tlv1) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_tu64(&ptr, *r->tlv1); + return ptr; +} +static void fromwire_tlv_n1_tlv1(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_n1 *r = vrecord; + + r->tlv1 = tal(r, u64); + +*r->tlv1 = fromwire_tu64(cursor, plen); +} +/* N1 MSG: tlv2 */ +static u8 *towire_tlv_n1_tlv2(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_n1 *r = vrecord; + u8 *ptr; + + if (!r->tlv2) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_short_channel_id(&ptr, r->tlv2); + return ptr; +} +static void fromwire_tlv_n1_tlv2(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_n1 *r = vrecord; + + r->tlv2 = tal(r, struct short_channel_id); + +fromwire_short_channel_id(cursor, plen, &*r->tlv2); +} +/* N1 MSG: tlv3 */ +static u8 *towire_tlv_n1_tlv3(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_n1 *r = vrecord; + u8 *ptr; + + if (!r->tlv3) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_pubkey(&ptr, &r->tlv3->node_id); + + towire_amount_msat(&ptr, r->tlv3->amount_msat_1); + + towire_amount_msat(&ptr, r->tlv3->amount_msat_2); + return ptr; +} +static void fromwire_tlv_n1_tlv3(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_n1 *r = vrecord; + + r->tlv3 = tal(r, struct tlv_n1_tlv3); + fromwire_pubkey(cursor, plen, &r->tlv3->node_id); + r->tlv3->amount_msat_1 = fromwire_amount_msat(cursor, plen); + r->tlv3->amount_msat_2 = fromwire_amount_msat(cursor, plen); +} +/* N1 MSG: tlv4 */ +static u8 *towire_tlv_n1_tlv4(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_n1 *r = vrecord; + u8 *ptr; + + if (!r->tlv4) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_u16(&ptr, *r->tlv4); + return ptr; +} +static void fromwire_tlv_n1_tlv4(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_n1 *r = vrecord; + + r->tlv4 = tal(r, u16); + +*r->tlv4 = fromwire_u16(cursor, plen); +} + +const struct tlv_record_type tlvs_n1[] = { + { 1, towire_tlv_n1_tlv1, fromwire_tlv_n1_tlv1 }, + { 2, towire_tlv_n1_tlv2, fromwire_tlv_n1_tlv2 }, + { 3, towire_tlv_n1_tlv3, fromwire_tlv_n1_tlv3 }, + { 254, towire_tlv_n1_tlv4, fromwire_tlv_n1_tlv4 }, +}; + +void towire_n1(u8 **pptr, + const void *record) +{ + size_t num_types = 4; + const struct tlv_record_type *types = tlvs_n1; + if (!record) + return; + + for (size_t i = 0; i < num_types; i++) { + u8 *val; + if (i != 0) + assert(types[i].type > types[i-1].type); + val = types[i].towire(NULL, record); + if (!val) + continue; + + /* BOLT #1: + * + * The sending node: + ... + * - MUST minimally encode `type` and `length`. + */ + towire_bigsize(pptr, types[i].type); + towire_bigsize(pptr, tal_bytelen(val)); + towire(pptr, val, tal_bytelen(val)); + tal_free(val); + } +} + + +bool fromwire_n1(const u8 **cursor, size_t *max, struct tlv_n1 *record) +{ + size_t num_types = 4; + const struct tlv_record_type *types = tlvs_n1; + while (*max > 0) { + struct tlv_field field; + + /* BOLT #1: + * + * A `varint` is a variable-length, unsigned integer encoding + * using the [BigSize](#appendix-a-bigsize-test-vectors) + * format + */ + field.numtype = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("type"); + goto fail; + } + field.length = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("length"); + goto fail; + } + + /* BOLT #1: + * - if `length` exceeds the number of bytes remaining in the + * message: + * - MUST fail to parse the `tlv_stream`. + */ + if (field.length > *max) { + SUPERVERBOSE("value"); + goto fail; + } + field.value = tal_dup_arr(record, u8, *cursor, field.length, 0); + + /* BOLT #1: + * - if `type` is known: + * - MUST decode the next `length` bytes using the known + * encoding for `type`. + */ + field.meta = NULL; + for (size_t i = 0; i < num_types; i++) { + if (types[i].type == field.numtype) + field.meta = &types[i]; + } + + if (field.meta) { + /* Length of message can't exceed 16 bits anyway. */ + size_t tlvlen = field.length; + field.meta->fromwire(cursor, &tlvlen, record); + + if (!*cursor) + goto fail; + + /* BOLT #1: + * - if `length` is not exactly equal to that required + * for the known encoding for `type`: + * - MUST fail to parse the `tlv_stream`. + */ + if (tlvlen != 0) { + SUPERVERBOSE("greater than encoding length"); + goto fail; + } + } else { + /* We didn't read from *cursor through a fromwire, so + * update manually. */ + *cursor += field.length; + } + /* We've read bytes in ->fromwire, so update max */ + *max -= field.length; + tal_arr_expand(&record->fields, field); + } + return true; +fail: + fromwire_fail(cursor, max); + return false; +} + +bool n1_is_valid(const struct tlv_n1 *record, size_t *err_index) +{ + size_t numfields = tal_count(record->fields); + bool first = true; + u64 prev_type = 0; + for (int i=0; ifields[i]; + if (f->numtype % 2 == 0 && f->meta == NULL) { + /* BOLT #1: + * - otherwise, if `type` is unknown: + * - if `type` is even: + * - MUST fail to parse the `tlv_stream`. + * - otherwise, if `type` is odd: + * - MUST discard the next `length` bytes. + */ + SUPERVERBOSE("unknown even"); + if (err_index != NULL) + *err_index = i; + return false; + } else if (!first && f->numtype <= prev_type) { + /* BOLT #1: + * - if decoded `type`s are not monotonically-increasing: + * - MUST fail to parse the `tlv_stream`. + */ + if (f->numtype == prev_type) + SUPERVERBOSE("duplicate tlv type"); + else + SUPERVERBOSE("invalid ordering"); + if (err_index != NULL) + *err_index = i; + return false; + } + first = false; + prev_type = f->numtype; + } + return true; +} + + +struct tlv_n2 *tlv_n2_new(const tal_t *ctx) +{ + /* Initialize everything to NULL. (Quiet, C pedants!) */ + struct tlv_n2 *inst = talz(ctx, struct tlv_n2); + + /* Initialized the fields to an empty array. */ + inst->fields = tal_arr(inst, struct tlv_field, 0); + return inst; +} + +/* N2 MSG: tlv1 */ +static u8 *towire_tlv_n2_tlv1(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_n2 *r = vrecord; + u8 *ptr; + + if (!r->tlv1) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_tu64(&ptr, *r->tlv1); + return ptr; +} +static void fromwire_tlv_n2_tlv1(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_n2 *r = vrecord; + + r->tlv1 = tal(r, u64); + +*r->tlv1 = fromwire_tu64(cursor, plen); +} +/* N2 MSG: tlv2 */ +static u8 *towire_tlv_n2_tlv2(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_n2 *r = vrecord; + u8 *ptr; + + if (!r->tlv2) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_tu32(&ptr, *r->tlv2); + return ptr; +} +static void fromwire_tlv_n2_tlv2(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_n2 *r = vrecord; + + r->tlv2 = tal(r, u32); + +*r->tlv2 = fromwire_tu32(cursor, plen); +} + +const struct tlv_record_type tlvs_n2[] = { + { 0, towire_tlv_n2_tlv1, fromwire_tlv_n2_tlv1 }, + { 11, towire_tlv_n2_tlv2, fromwire_tlv_n2_tlv2 }, +}; + +void towire_n2(u8 **pptr, + const void *record) +{ + size_t num_types = 2; + const struct tlv_record_type *types = tlvs_n2; + if (!record) + return; + + for (size_t i = 0; i < num_types; i++) { + u8 *val; + if (i != 0) + assert(types[i].type > types[i-1].type); + val = types[i].towire(NULL, record); + if (!val) + continue; + + /* BOLT #1: + * + * The sending node: + ... + * - MUST minimally encode `type` and `length`. + */ + towire_bigsize(pptr, types[i].type); + towire_bigsize(pptr, tal_bytelen(val)); + towire(pptr, val, tal_bytelen(val)); + tal_free(val); + } +} + + +bool fromwire_n2(const u8 **cursor, size_t *max, struct tlv_n2 *record) +{ + size_t num_types = 2; + const struct tlv_record_type *types = tlvs_n2; + while (*max > 0) { + struct tlv_field field; + + /* BOLT #1: + * + * A `varint` is a variable-length, unsigned integer encoding + * using the [BigSize](#appendix-a-bigsize-test-vectors) + * format + */ + field.numtype = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("type"); + goto fail; + } + field.length = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("length"); + goto fail; + } + + /* BOLT #1: + * - if `length` exceeds the number of bytes remaining in the + * message: + * - MUST fail to parse the `tlv_stream`. + */ + if (field.length > *max) { + SUPERVERBOSE("value"); + goto fail; + } + field.value = tal_dup_arr(record, u8, *cursor, field.length, 0); + + /* BOLT #1: + * - if `type` is known: + * - MUST decode the next `length` bytes using the known + * encoding for `type`. + */ + field.meta = NULL; + for (size_t i = 0; i < num_types; i++) { + if (types[i].type == field.numtype) + field.meta = &types[i]; + } + + if (field.meta) { + /* Length of message can't exceed 16 bits anyway. */ + size_t tlvlen = field.length; + field.meta->fromwire(cursor, &tlvlen, record); + + if (!*cursor) + goto fail; + + /* BOLT #1: + * - if `length` is not exactly equal to that required + * for the known encoding for `type`: + * - MUST fail to parse the `tlv_stream`. + */ + if (tlvlen != 0) { + SUPERVERBOSE("greater than encoding length"); + goto fail; + } + } else { + /* We didn't read from *cursor through a fromwire, so + * update manually. */ + *cursor += field.length; + } + /* We've read bytes in ->fromwire, so update max */ + *max -= field.length; + tal_arr_expand(&record->fields, field); + } + return true; +fail: + fromwire_fail(cursor, max); + return false; +} + +bool n2_is_valid(const struct tlv_n2 *record, size_t *err_index) +{ + size_t numfields = tal_count(record->fields); + bool first = true; + u64 prev_type = 0; + for (int i=0; ifields[i]; + if (f->numtype % 2 == 0 && f->meta == NULL) { + /* BOLT #1: + * - otherwise, if `type` is unknown: + * - if `type` is even: + * - MUST fail to parse the `tlv_stream`. + * - otherwise, if `type` is odd: + * - MUST discard the next `length` bytes. + */ + SUPERVERBOSE("unknown even"); + if (err_index != NULL) + *err_index = i; + return false; + } else if (!first && f->numtype <= prev_type) { + /* BOLT #1: + * - if decoded `type`s are not monotonically-increasing: + * - MUST fail to parse the `tlv_stream`. + */ + if (f->numtype == prev_type) + SUPERVERBOSE("duplicate tlv type"); + else + SUPERVERBOSE("invalid ordering"); + if (err_index != NULL) + *err_index = i; + return false; + } + first = false; + prev_type = f->numtype; + } + return true; +} + + +struct tlv_open_channel_tlvs *tlv_open_channel_tlvs_new(const tal_t *ctx) +{ + /* Initialize everything to NULL. (Quiet, C pedants!) */ + struct tlv_open_channel_tlvs *inst = talz(ctx, struct tlv_open_channel_tlvs); + + /* Initialized the fields to an empty array. */ + inst->fields = tal_arr(inst, struct tlv_field, 0); + return inst; +} + +/* OPEN_CHANNEL_TLVS MSG: upfront_shutdown_script */ +static u8 *towire_tlv_open_channel_tlvs_upfront_shutdown_script(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_open_channel_tlvs *r = vrecord; + u8 *ptr; + + if (!r->upfront_shutdown_script) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_u8_array(&ptr, r->upfront_shutdown_script, tal_count(r->upfront_shutdown_script)); + return ptr; +} +static void fromwire_tlv_open_channel_tlvs_upfront_shutdown_script(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_open_channel_tlvs *r = vrecord; + + r->upfront_shutdown_script = *plen ? tal_arr(r, u8, *plen) : NULL; +fromwire_u8_array(cursor, plen, r->upfront_shutdown_script, *plen); +} + +static const struct tlv_record_type tlvs_open_channel_tlvs[] = { + { 0, towire_tlv_open_channel_tlvs_upfront_shutdown_script, fromwire_tlv_open_channel_tlvs_upfront_shutdown_script }, +}; + +void towire_open_channel_tlvs(u8 **pptr, + const void *record) +{ + size_t num_types = 1; + const struct tlv_record_type *types = tlvs_open_channel_tlvs; + if (!record) + return; + + for (size_t i = 0; i < num_types; i++) { + u8 *val; + if (i != 0) + assert(types[i].type > types[i-1].type); + val = types[i].towire(NULL, record); + if (!val) + continue; + + /* BOLT #1: + * + * The sending node: + ... + * - MUST minimally encode `type` and `length`. + */ + towire_bigsize(pptr, types[i].type); + towire_bigsize(pptr, tal_bytelen(val)); + towire(pptr, val, tal_bytelen(val)); + tal_free(val); + } +} + + +bool fromwire_open_channel_tlvs(const u8 **cursor, size_t *max, struct tlv_open_channel_tlvs *record) +{ + size_t num_types = 1; + const struct tlv_record_type *types = tlvs_open_channel_tlvs; + while (*max > 0) { + struct tlv_field field; + + /* BOLT #1: + * + * A `varint` is a variable-length, unsigned integer encoding + * using the [BigSize](#appendix-a-bigsize-test-vectors) + * format + */ + field.numtype = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("type"); + goto fail; + } + field.length = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("length"); + goto fail; + } + + /* BOLT #1: + * - if `length` exceeds the number of bytes remaining in the + * message: + * - MUST fail to parse the `tlv_stream`. + */ + if (field.length > *max) { + SUPERVERBOSE("value"); + goto fail; + } + field.value = tal_dup_arr(record, u8, *cursor, field.length, 0); + + /* BOLT #1: + * - if `type` is known: + * - MUST decode the next `length` bytes using the known + * encoding for `type`. + */ + field.meta = NULL; + for (size_t i = 0; i < num_types; i++) { + if (types[i].type == field.numtype) + field.meta = &types[i]; + } + + if (field.meta) { + /* Length of message can't exceed 16 bits anyway. */ + size_t tlvlen = field.length; + field.meta->fromwire(cursor, &tlvlen, record); + + if (!*cursor) + goto fail; + + /* BOLT #1: + * - if `length` is not exactly equal to that required + * for the known encoding for `type`: + * - MUST fail to parse the `tlv_stream`. + */ + if (tlvlen != 0) { + SUPERVERBOSE("greater than encoding length"); + goto fail; + } + } else { + /* We didn't read from *cursor through a fromwire, so + * update manually. */ + *cursor += field.length; + } + /* We've read bytes in ->fromwire, so update max */ + *max -= field.length; + tal_arr_expand(&record->fields, field); + } + return true; +fail: + fromwire_fail(cursor, max); + return false; +} + +bool open_channel_tlvs_is_valid(const struct tlv_open_channel_tlvs *record, size_t *err_index) +{ + size_t numfields = tal_count(record->fields); + bool first = true; + u64 prev_type = 0; + for (int i=0; ifields[i]; + if (f->numtype % 2 == 0 && f->meta == NULL) { + /* BOLT #1: + * - otherwise, if `type` is unknown: + * - if `type` is even: + * - MUST fail to parse the `tlv_stream`. + * - otherwise, if `type` is odd: + * - MUST discard the next `length` bytes. + */ + SUPERVERBOSE("unknown even"); + if (err_index != NULL) + *err_index = i; + return false; + } else if (!first && f->numtype <= prev_type) { + /* BOLT #1: + * - if decoded `type`s are not monotonically-increasing: + * - MUST fail to parse the `tlv_stream`. + */ + if (f->numtype == prev_type) + SUPERVERBOSE("duplicate tlv type"); + else + SUPERVERBOSE("invalid ordering"); + if (err_index != NULL) + *err_index = i; + return false; + } + first = false; + prev_type = f->numtype; + } + return true; +} + + +struct tlv_accept_channel_tlvs *tlv_accept_channel_tlvs_new(const tal_t *ctx) +{ + /* Initialize everything to NULL. (Quiet, C pedants!) */ + struct tlv_accept_channel_tlvs *inst = talz(ctx, struct tlv_accept_channel_tlvs); + + /* Initialized the fields to an empty array. */ + inst->fields = tal_arr(inst, struct tlv_field, 0); + return inst; +} + +/* ACCEPT_CHANNEL_TLVS MSG: upfront_shutdown_script */ +static u8 *towire_tlv_accept_channel_tlvs_upfront_shutdown_script(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_accept_channel_tlvs *r = vrecord; + u8 *ptr; + + if (!r->upfront_shutdown_script) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_u8_array(&ptr, r->upfront_shutdown_script, tal_count(r->upfront_shutdown_script)); + return ptr; +} +static void fromwire_tlv_accept_channel_tlvs_upfront_shutdown_script(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_accept_channel_tlvs *r = vrecord; + + r->upfront_shutdown_script = *plen ? tal_arr(r, u8, *plen) : NULL; +fromwire_u8_array(cursor, plen, r->upfront_shutdown_script, *plen); +} + +static const struct tlv_record_type tlvs_accept_channel_tlvs[] = { + { 0, towire_tlv_accept_channel_tlvs_upfront_shutdown_script, fromwire_tlv_accept_channel_tlvs_upfront_shutdown_script }, +}; + +void towire_accept_channel_tlvs(u8 **pptr, + const void *record) +{ + size_t num_types = 1; + const struct tlv_record_type *types = tlvs_accept_channel_tlvs; + if (!record) + return; + + for (size_t i = 0; i < num_types; i++) { + u8 *val; + if (i != 0) + assert(types[i].type > types[i-1].type); + val = types[i].towire(NULL, record); + if (!val) + continue; + + /* BOLT #1: + * + * The sending node: + ... + * - MUST minimally encode `type` and `length`. + */ + towire_bigsize(pptr, types[i].type); + towire_bigsize(pptr, tal_bytelen(val)); + towire(pptr, val, tal_bytelen(val)); + tal_free(val); + } +} + + +bool fromwire_accept_channel_tlvs(const u8 **cursor, size_t *max, struct tlv_accept_channel_tlvs *record) +{ + size_t num_types = 1; + const struct tlv_record_type *types = tlvs_accept_channel_tlvs; + while (*max > 0) { + struct tlv_field field; + + /* BOLT #1: + * + * A `varint` is a variable-length, unsigned integer encoding + * using the [BigSize](#appendix-a-bigsize-test-vectors) + * format + */ + field.numtype = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("type"); + goto fail; + } + field.length = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("length"); + goto fail; + } + + /* BOLT #1: + * - if `length` exceeds the number of bytes remaining in the + * message: + * - MUST fail to parse the `tlv_stream`. + */ + if (field.length > *max) { + SUPERVERBOSE("value"); + goto fail; + } + field.value = tal_dup_arr(record, u8, *cursor, field.length, 0); + + /* BOLT #1: + * - if `type` is known: + * - MUST decode the next `length` bytes using the known + * encoding for `type`. + */ + field.meta = NULL; + for (size_t i = 0; i < num_types; i++) { + if (types[i].type == field.numtype) + field.meta = &types[i]; + } + + if (field.meta) { + /* Length of message can't exceed 16 bits anyway. */ + size_t tlvlen = field.length; + field.meta->fromwire(cursor, &tlvlen, record); + + if (!*cursor) + goto fail; + + /* BOLT #1: + * - if `length` is not exactly equal to that required + * for the known encoding for `type`: + * - MUST fail to parse the `tlv_stream`. + */ + if (tlvlen != 0) { + SUPERVERBOSE("greater than encoding length"); + goto fail; + } + } else { + /* We didn't read from *cursor through a fromwire, so + * update manually. */ + *cursor += field.length; + } + /* We've read bytes in ->fromwire, so update max */ + *max -= field.length; + tal_arr_expand(&record->fields, field); + } + return true; +fail: + fromwire_fail(cursor, max); + return false; +} + +bool accept_channel_tlvs_is_valid(const struct tlv_accept_channel_tlvs *record, size_t *err_index) +{ + size_t numfields = tal_count(record->fields); + bool first = true; + u64 prev_type = 0; + for (int i=0; ifields[i]; + if (f->numtype % 2 == 0 && f->meta == NULL) { + /* BOLT #1: + * - otherwise, if `type` is unknown: + * - if `type` is even: + * - MUST fail to parse the `tlv_stream`. + * - otherwise, if `type` is odd: + * - MUST discard the next `length` bytes. + */ + SUPERVERBOSE("unknown even"); + if (err_index != NULL) + *err_index = i; + return false; + } else if (!first && f->numtype <= prev_type) { + /* BOLT #1: + * - if decoded `type`s are not monotonically-increasing: + * - MUST fail to parse the `tlv_stream`. + */ + if (f->numtype == prev_type) + SUPERVERBOSE("duplicate tlv type"); + else + SUPERVERBOSE("invalid ordering"); + if (err_index != NULL) + *err_index = i; + return false; + } + first = false; + prev_type = f->numtype; + } + return true; +} + + +struct tlv_query_short_channel_ids_tlvs *tlv_query_short_channel_ids_tlvs_new(const tal_t *ctx) +{ + /* Initialize everything to NULL. (Quiet, C pedants!) */ + struct tlv_query_short_channel_ids_tlvs *inst = talz(ctx, struct tlv_query_short_channel_ids_tlvs); + + /* Initialized the fields to an empty array. */ + inst->fields = tal_arr(inst, struct tlv_field, 0); + return inst; +} + +/* QUERY_SHORT_CHANNEL_IDS_TLVS MSG: query_flags */ +static u8 *towire_tlv_query_short_channel_ids_tlvs_query_flags(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_query_short_channel_ids_tlvs *r = vrecord; + u8 *ptr; + + if (!r->query_flags) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_u8(&ptr, r->query_flags->encoding_type); + + towire_u8_array(&ptr, r->query_flags->encoded_query_flags, tal_count(r->query_flags->encoded_query_flags)); + return ptr; +} +static void fromwire_tlv_query_short_channel_ids_tlvs_query_flags(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_query_short_channel_ids_tlvs *r = vrecord; + + r->query_flags = tal(r, struct tlv_query_short_channel_ids_tlvs_query_flags); + r->query_flags->encoding_type = fromwire_u8(cursor, plen); + r->query_flags->encoded_query_flags = *plen ? tal_arr(r->query_flags, u8, *plen) : NULL; +fromwire_u8_array(cursor, plen, r->query_flags->encoded_query_flags, *plen); +} + +static const struct tlv_record_type tlvs_query_short_channel_ids_tlvs[] = { + { 1, towire_tlv_query_short_channel_ids_tlvs_query_flags, fromwire_tlv_query_short_channel_ids_tlvs_query_flags }, +}; + +void towire_query_short_channel_ids_tlvs(u8 **pptr, + const void *record) +{ + size_t num_types = 1; + const struct tlv_record_type *types = tlvs_query_short_channel_ids_tlvs; + if (!record) + return; + + for (size_t i = 0; i < num_types; i++) { + u8 *val; + if (i != 0) + assert(types[i].type > types[i-1].type); + val = types[i].towire(NULL, record); + if (!val) + continue; + + /* BOLT #1: + * + * The sending node: + ... + * - MUST minimally encode `type` and `length`. + */ + towire_bigsize(pptr, types[i].type); + towire_bigsize(pptr, tal_bytelen(val)); + towire(pptr, val, tal_bytelen(val)); + tal_free(val); + } +} + + +bool fromwire_query_short_channel_ids_tlvs(const u8 **cursor, size_t *max, struct tlv_query_short_channel_ids_tlvs *record) +{ + size_t num_types = 1; + const struct tlv_record_type *types = tlvs_query_short_channel_ids_tlvs; + while (*max > 0) { + struct tlv_field field; + + /* BOLT #1: + * + * A `varint` is a variable-length, unsigned integer encoding + * using the [BigSize](#appendix-a-bigsize-test-vectors) + * format + */ + field.numtype = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("type"); + goto fail; + } + field.length = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("length"); + goto fail; + } + + /* BOLT #1: + * - if `length` exceeds the number of bytes remaining in the + * message: + * - MUST fail to parse the `tlv_stream`. + */ + if (field.length > *max) { + SUPERVERBOSE("value"); + goto fail; + } + field.value = tal_dup_arr(record, u8, *cursor, field.length, 0); + + /* BOLT #1: + * - if `type` is known: + * - MUST decode the next `length` bytes using the known + * encoding for `type`. + */ + field.meta = NULL; + for (size_t i = 0; i < num_types; i++) { + if (types[i].type == field.numtype) + field.meta = &types[i]; + } + + if (field.meta) { + /* Length of message can't exceed 16 bits anyway. */ + size_t tlvlen = field.length; + field.meta->fromwire(cursor, &tlvlen, record); + + if (!*cursor) + goto fail; + + /* BOLT #1: + * - if `length` is not exactly equal to that required + * for the known encoding for `type`: + * - MUST fail to parse the `tlv_stream`. + */ + if (tlvlen != 0) { + SUPERVERBOSE("greater than encoding length"); + goto fail; + } + } else { + /* We didn't read from *cursor through a fromwire, so + * update manually. */ + *cursor += field.length; + } + /* We've read bytes in ->fromwire, so update max */ + *max -= field.length; + tal_arr_expand(&record->fields, field); + } + return true; +fail: + fromwire_fail(cursor, max); + return false; +} + +bool query_short_channel_ids_tlvs_is_valid(const struct tlv_query_short_channel_ids_tlvs *record, size_t *err_index) +{ + size_t numfields = tal_count(record->fields); + bool first = true; + u64 prev_type = 0; + for (int i=0; ifields[i]; + if (f->numtype % 2 == 0 && f->meta == NULL) { + /* BOLT #1: + * - otherwise, if `type` is unknown: + * - if `type` is even: + * - MUST fail to parse the `tlv_stream`. + * - otherwise, if `type` is odd: + * - MUST discard the next `length` bytes. + */ + SUPERVERBOSE("unknown even"); + if (err_index != NULL) + *err_index = i; + return false; + } else if (!first && f->numtype <= prev_type) { + /* BOLT #1: + * - if decoded `type`s are not monotonically-increasing: + * - MUST fail to parse the `tlv_stream`. + */ + if (f->numtype == prev_type) + SUPERVERBOSE("duplicate tlv type"); + else + SUPERVERBOSE("invalid ordering"); + if (err_index != NULL) + *err_index = i; + return false; + } + first = false; + prev_type = f->numtype; + } + return true; +} + + +struct tlv_query_channel_range_tlvs *tlv_query_channel_range_tlvs_new(const tal_t *ctx) +{ + /* Initialize everything to NULL. (Quiet, C pedants!) */ + struct tlv_query_channel_range_tlvs *inst = talz(ctx, struct tlv_query_channel_range_tlvs); + + /* Initialized the fields to an empty array. */ + inst->fields = tal_arr(inst, struct tlv_field, 0); + return inst; +} + +/* QUERY_CHANNEL_RANGE_TLVS MSG: query_option */ +static u8 *towire_tlv_query_channel_range_tlvs_query_option(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_query_channel_range_tlvs *r = vrecord; + u8 *ptr; + + if (!r->query_option) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_bigsize(&ptr, *r->query_option); + return ptr; +} +static void fromwire_tlv_query_channel_range_tlvs_query_option(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_query_channel_range_tlvs *r = vrecord; + + r->query_option = tal(r, bigsize); + +*r->query_option = fromwire_bigsize(cursor, plen); +} + +static const struct tlv_record_type tlvs_query_channel_range_tlvs[] = { + { 1, towire_tlv_query_channel_range_tlvs_query_option, fromwire_tlv_query_channel_range_tlvs_query_option }, +}; + +void towire_query_channel_range_tlvs(u8 **pptr, + const void *record) +{ + size_t num_types = 1; + const struct tlv_record_type *types = tlvs_query_channel_range_tlvs; + if (!record) + return; + + for (size_t i = 0; i < num_types; i++) { + u8 *val; + if (i != 0) + assert(types[i].type > types[i-1].type); + val = types[i].towire(NULL, record); + if (!val) + continue; + + /* BOLT #1: + * + * The sending node: + ... + * - MUST minimally encode `type` and `length`. + */ + towire_bigsize(pptr, types[i].type); + towire_bigsize(pptr, tal_bytelen(val)); + towire(pptr, val, tal_bytelen(val)); + tal_free(val); + } +} + + +bool fromwire_query_channel_range_tlvs(const u8 **cursor, size_t *max, struct tlv_query_channel_range_tlvs *record) +{ + size_t num_types = 1; + const struct tlv_record_type *types = tlvs_query_channel_range_tlvs; + while (*max > 0) { + struct tlv_field field; + + /* BOLT #1: + * + * A `varint` is a variable-length, unsigned integer encoding + * using the [BigSize](#appendix-a-bigsize-test-vectors) + * format + */ + field.numtype = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("type"); + goto fail; + } + field.length = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("length"); + goto fail; + } + + /* BOLT #1: + * - if `length` exceeds the number of bytes remaining in the + * message: + * - MUST fail to parse the `tlv_stream`. + */ + if (field.length > *max) { + SUPERVERBOSE("value"); + goto fail; + } + field.value = tal_dup_arr(record, u8, *cursor, field.length, 0); + + /* BOLT #1: + * - if `type` is known: + * - MUST decode the next `length` bytes using the known + * encoding for `type`. + */ + field.meta = NULL; + for (size_t i = 0; i < num_types; i++) { + if (types[i].type == field.numtype) + field.meta = &types[i]; + } + + if (field.meta) { + /* Length of message can't exceed 16 bits anyway. */ + size_t tlvlen = field.length; + field.meta->fromwire(cursor, &tlvlen, record); + + if (!*cursor) + goto fail; + + /* BOLT #1: + * - if `length` is not exactly equal to that required + * for the known encoding for `type`: + * - MUST fail to parse the `tlv_stream`. + */ + if (tlvlen != 0) { + SUPERVERBOSE("greater than encoding length"); + goto fail; + } + } else { + /* We didn't read from *cursor through a fromwire, so + * update manually. */ + *cursor += field.length; + } + /* We've read bytes in ->fromwire, so update max */ + *max -= field.length; + tal_arr_expand(&record->fields, field); + } + return true; +fail: + fromwire_fail(cursor, max); + return false; +} + +bool query_channel_range_tlvs_is_valid(const struct tlv_query_channel_range_tlvs *record, size_t *err_index) +{ + size_t numfields = tal_count(record->fields); + bool first = true; + u64 prev_type = 0; + for (int i=0; ifields[i]; + if (f->numtype % 2 == 0 && f->meta == NULL) { + /* BOLT #1: + * - otherwise, if `type` is unknown: + * - if `type` is even: + * - MUST fail to parse the `tlv_stream`. + * - otherwise, if `type` is odd: + * - MUST discard the next `length` bytes. + */ + SUPERVERBOSE("unknown even"); + if (err_index != NULL) + *err_index = i; + return false; + } else if (!first && f->numtype <= prev_type) { + /* BOLT #1: + * - if decoded `type`s are not monotonically-increasing: + * - MUST fail to parse the `tlv_stream`. + */ + if (f->numtype == prev_type) + SUPERVERBOSE("duplicate tlv type"); + else + SUPERVERBOSE("invalid ordering"); + if (err_index != NULL) + *err_index = i; + return false; + } + first = false; + prev_type = f->numtype; + } + return true; +} + + +struct tlv_reply_channel_range_tlvs *tlv_reply_channel_range_tlvs_new(const tal_t *ctx) +{ + /* Initialize everything to NULL. (Quiet, C pedants!) */ + struct tlv_reply_channel_range_tlvs *inst = talz(ctx, struct tlv_reply_channel_range_tlvs); + + /* Initialized the fields to an empty array. */ + inst->fields = tal_arr(inst, struct tlv_field, 0); + return inst; +} + +/* REPLY_CHANNEL_RANGE_TLVS MSG: timestamps_tlv */ +static u8 *towire_tlv_reply_channel_range_tlvs_timestamps_tlv(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_reply_channel_range_tlvs *r = vrecord; + u8 *ptr; + + if (!r->timestamps_tlv) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_u8(&ptr, r->timestamps_tlv->encoding_type); + + towire_u8_array(&ptr, r->timestamps_tlv->encoded_timestamps, tal_count(r->timestamps_tlv->encoded_timestamps)); + return ptr; +} +static void fromwire_tlv_reply_channel_range_tlvs_timestamps_tlv(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_reply_channel_range_tlvs *r = vrecord; + + r->timestamps_tlv = tal(r, struct tlv_reply_channel_range_tlvs_timestamps_tlv); + r->timestamps_tlv->encoding_type = fromwire_u8(cursor, plen); + r->timestamps_tlv->encoded_timestamps = *plen ? tal_arr(r->timestamps_tlv, u8, *plen) : NULL; +fromwire_u8_array(cursor, plen, r->timestamps_tlv->encoded_timestamps, *plen); +} +/* REPLY_CHANNEL_RANGE_TLVS MSG: checksums_tlv */ +static u8 *towire_tlv_reply_channel_range_tlvs_checksums_tlv(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_reply_channel_range_tlvs *r = vrecord; + u8 *ptr; + + if (!r->checksums_tlv) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + for (size_t i = 0; i < tal_count(r->checksums_tlv); i++) + towire_channel_update_checksums(&ptr, r->checksums_tlv + i); + return ptr; +} +static void fromwire_tlv_reply_channel_range_tlvs_checksums_tlv(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_reply_channel_range_tlvs *r = vrecord; + + r->checksums_tlv = *plen ? tal_arr(r, struct channel_update_checksums, 0) : NULL; + for (size_t i = 0; *plen != 0; i++) { + struct channel_update_checksums tmp; + fromwire_channel_update_checksums(cursor, plen, &tmp); + tal_arr_expand(&r->checksums_tlv, tmp); + } +} + +static const struct tlv_record_type tlvs_reply_channel_range_tlvs[] = { + { 1, towire_tlv_reply_channel_range_tlvs_timestamps_tlv, fromwire_tlv_reply_channel_range_tlvs_timestamps_tlv }, + { 3, towire_tlv_reply_channel_range_tlvs_checksums_tlv, fromwire_tlv_reply_channel_range_tlvs_checksums_tlv }, +}; + +void towire_reply_channel_range_tlvs(u8 **pptr, + const void *record) +{ + size_t num_types = 2; + const struct tlv_record_type *types = tlvs_reply_channel_range_tlvs; + if (!record) + return; + + for (size_t i = 0; i < num_types; i++) { + u8 *val; + if (i != 0) + assert(types[i].type > types[i-1].type); + val = types[i].towire(NULL, record); + if (!val) + continue; + + /* BOLT #1: + * + * The sending node: + ... + * - MUST minimally encode `type` and `length`. + */ + towire_bigsize(pptr, types[i].type); + towire_bigsize(pptr, tal_bytelen(val)); + towire(pptr, val, tal_bytelen(val)); + tal_free(val); + } +} + + +bool fromwire_reply_channel_range_tlvs(const u8 **cursor, size_t *max, struct tlv_reply_channel_range_tlvs *record) +{ + size_t num_types = 2; + const struct tlv_record_type *types = tlvs_reply_channel_range_tlvs; + while (*max > 0) { + struct tlv_field field; + + /* BOLT #1: + * + * A `varint` is a variable-length, unsigned integer encoding + * using the [BigSize](#appendix-a-bigsize-test-vectors) + * format + */ + field.numtype = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("type"); + goto fail; + } + field.length = fromwire_bigsize(cursor, max); + + /* BOLT #1: + * - if a `type` or `length` is not minimally encoded: + * - MUST fail to parse the `tlv_stream`. + */ + if (!*cursor) { + SUPERVERBOSE("length"); + goto fail; + } + + /* BOLT #1: + * - if `length` exceeds the number of bytes remaining in the + * message: + * - MUST fail to parse the `tlv_stream`. + */ + if (field.length > *max) { + SUPERVERBOSE("value"); + goto fail; + } + field.value = tal_dup_arr(record, u8, *cursor, field.length, 0); + + /* BOLT #1: + * - if `type` is known: + * - MUST decode the next `length` bytes using the known + * encoding for `type`. + */ + field.meta = NULL; + for (size_t i = 0; i < num_types; i++) { + if (types[i].type == field.numtype) + field.meta = &types[i]; + } + + if (field.meta) { + /* Length of message can't exceed 16 bits anyway. */ + size_t tlvlen = field.length; + field.meta->fromwire(cursor, &tlvlen, record); + + if (!*cursor) + goto fail; + + /* BOLT #1: + * - if `length` is not exactly equal to that required + * for the known encoding for `type`: + * - MUST fail to parse the `tlv_stream`. + */ + if (tlvlen != 0) { + SUPERVERBOSE("greater than encoding length"); + goto fail; + } + } else { + /* We didn't read from *cursor through a fromwire, so + * update manually. */ + *cursor += field.length; + } + /* We've read bytes in ->fromwire, so update max */ + *max -= field.length; + tal_arr_expand(&record->fields, field); + } + return true; +fail: + fromwire_fail(cursor, max); + return false; +} + +bool reply_channel_range_tlvs_is_valid(const struct tlv_reply_channel_range_tlvs *record, size_t *err_index) +{ + size_t numfields = tal_count(record->fields); + bool first = true; + u64 prev_type = 0; + for (int i=0; ifields[i]; + if (f->numtype % 2 == 0 && f->meta == NULL) { + /* BOLT #1: + * - otherwise, if `type` is unknown: + * - if `type` is even: + * - MUST fail to parse the `tlv_stream`. + * - otherwise, if `type` is odd: + * - MUST discard the next `length` bytes. + */ + SUPERVERBOSE("unknown even"); + if (err_index != NULL) + *err_index = i; + return false; + } else if (!first && f->numtype <= prev_type) { + /* BOLT #1: + * - if decoded `type`s are not monotonically-increasing: + * - MUST fail to parse the `tlv_stream`. + */ + if (f->numtype == prev_type) + SUPERVERBOSE("duplicate tlv type"); + else + SUPERVERBOSE("invalid ordering"); + if (err_index != NULL) + *err_index = i; + return false; + } + first = false; + prev_type = f->numtype; + } + return true; +} + + +/* WIRE: INIT */ +u8 *towire_init(const tal_t *ctx, const u8 *globalfeatures, const u8 *features, const struct tlv_init_tlvs *tlvs) +{ + u16 gflen = tal_count(globalfeatures); + u16 flen = tal_count(features); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_INIT); + towire_u16(&p, gflen); + towire_u8_array(&p, globalfeatures, gflen); + towire_u16(&p, flen); + towire_u8_array(&p, features, flen); + towire_init_tlvs(&p, tlvs); + + return memcheck(p, tal_count(p)); +} +bool fromwire_init(const tal_t *ctx, const void *p, u8 **globalfeatures, u8 **features, struct tlv_init_tlvs *tlvs) +{ + u16 gflen; + u16 flen; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_INIT) + return false; + gflen = fromwire_u16(&cursor, &plen); + // 2nd case globalfeatures + *globalfeatures = gflen ? tal_arr(ctx, u8, gflen) : NULL; + fromwire_u8_array(&cursor, &plen, *globalfeatures, gflen); + flen = fromwire_u16(&cursor, &plen); + // 2nd case features + *features = flen ? tal_arr(ctx, u8, flen) : NULL; + fromwire_u8_array(&cursor, &plen, *features, flen); + fromwire_init_tlvs(&cursor, &plen, tlvs); + return cursor != NULL; +} + +/* WIRE: ERROR */ +u8 *towire_error(const tal_t *ctx, const struct channel_id *channel_id, const u8 *data) +{ + u16 len = tal_count(data); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ERROR); + towire_channel_id(&p, channel_id); + towire_u16(&p, len); + towire_u8_array(&p, data, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_error(const tal_t *ctx, const void *p, struct channel_id *channel_id, u8 **data) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ERROR) + return false; + fromwire_channel_id(&cursor, &plen, channel_id); + len = fromwire_u16(&cursor, &plen); + // 2nd case data + *data = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *data, len); + return cursor != NULL; +} + +/* WIRE: PING */ +u8 *towire_ping(const tal_t *ctx, u16 num_pong_bytes, const u8 *ignored) +{ + u16 byteslen = tal_count(ignored); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_PING); + towire_u16(&p, num_pong_bytes); + towire_u16(&p, byteslen); + towire_u8_array(&p, ignored, byteslen); + + return memcheck(p, tal_count(p)); +} +bool fromwire_ping(const tal_t *ctx, const void *p, u16 *num_pong_bytes, u8 **ignored) +{ + u16 byteslen; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_PING) + return false; + *num_pong_bytes = fromwire_u16(&cursor, &plen); + byteslen = fromwire_u16(&cursor, &plen); + // 2nd case ignored + *ignored = byteslen ? tal_arr(ctx, u8, byteslen) : NULL; + fromwire_u8_array(&cursor, &plen, *ignored, byteslen); + return cursor != NULL; +} + +/* WIRE: PONG */ +u8 *towire_pong(const tal_t *ctx, const u8 *ignored) +{ + u16 byteslen = tal_count(ignored); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_PONG); + towire_u16(&p, byteslen); + towire_u8_array(&p, ignored, byteslen); + + return memcheck(p, tal_count(p)); +} +bool fromwire_pong(const tal_t *ctx, const void *p, u8 **ignored) +{ + u16 byteslen; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_PONG) + return false; + byteslen = fromwire_u16(&cursor, &plen); + // 2nd case ignored + *ignored = byteslen ? tal_arr(ctx, u8, byteslen) : NULL; + fromwire_u8_array(&cursor, &plen, *ignored, byteslen); + return cursor != NULL; +} + +/* WIRE: OPEN_CHANNEL */ +u8 *towire_open_channel(const tal_t *ctx, const struct bitcoin_blkid *chain_hash, const struct channel_id *temporary_channel_id, struct amount_sat funding_satoshis, struct amount_msat push_msat, struct amount_sat dust_limit_satoshis, struct amount_msat max_htlc_value_in_flight_msat, struct amount_sat channel_reserve_satoshis, struct amount_msat htlc_minimum_msat, u32 feerate_per_kw, u16 to_self_delay, u16 max_accepted_htlcs, const struct pubkey *funding_pubkey, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *first_per_commitment_point, u8 channel_flags, const struct tlv_open_channel_tlvs *tlvs) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_OPEN_CHANNEL); + towire_bitcoin_blkid(&p, chain_hash); + towire_channel_id(&p, temporary_channel_id); + towire_amount_sat(&p, funding_satoshis); + towire_amount_msat(&p, push_msat); + towire_amount_sat(&p, dust_limit_satoshis); + towire_amount_msat(&p, max_htlc_value_in_flight_msat); + towire_amount_sat(&p, channel_reserve_satoshis); + towire_amount_msat(&p, htlc_minimum_msat); + towire_u32(&p, feerate_per_kw); + towire_u16(&p, to_self_delay); + towire_u16(&p, max_accepted_htlcs); + towire_pubkey(&p, funding_pubkey); + towire_pubkey(&p, revocation_basepoint); + towire_pubkey(&p, payment_basepoint); + towire_pubkey(&p, delayed_payment_basepoint); + towire_pubkey(&p, htlc_basepoint); + towire_pubkey(&p, first_per_commitment_point); + towire_u8(&p, channel_flags); + towire_open_channel_tlvs(&p, tlvs); + + return memcheck(p, tal_count(p)); +} +bool fromwire_open_channel(const void *p, struct bitcoin_blkid *chain_hash, struct channel_id *temporary_channel_id, struct amount_sat *funding_satoshis, struct amount_msat *push_msat, struct amount_sat *dust_limit_satoshis, struct amount_msat *max_htlc_value_in_flight_msat, struct amount_sat *channel_reserve_satoshis, struct amount_msat *htlc_minimum_msat, u32 *feerate_per_kw, u16 *to_self_delay, u16 *max_accepted_htlcs, struct pubkey *funding_pubkey, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *first_per_commitment_point, u8 *channel_flags, struct tlv_open_channel_tlvs *tlvs) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_OPEN_CHANNEL) + return false; + fromwire_bitcoin_blkid(&cursor, &plen, chain_hash); + fromwire_channel_id(&cursor, &plen, temporary_channel_id); + *funding_satoshis = fromwire_amount_sat(&cursor, &plen); + *push_msat = fromwire_amount_msat(&cursor, &plen); + *dust_limit_satoshis = fromwire_amount_sat(&cursor, &plen); + *max_htlc_value_in_flight_msat = fromwire_amount_msat(&cursor, &plen); + *channel_reserve_satoshis = fromwire_amount_sat(&cursor, &plen); + *htlc_minimum_msat = fromwire_amount_msat(&cursor, &plen); + *feerate_per_kw = fromwire_u32(&cursor, &plen); + *to_self_delay = fromwire_u16(&cursor, &plen); + *max_accepted_htlcs = fromwire_u16(&cursor, &plen); + fromwire_pubkey(&cursor, &plen, funding_pubkey); + fromwire_pubkey(&cursor, &plen, revocation_basepoint); + fromwire_pubkey(&cursor, &plen, payment_basepoint); + fromwire_pubkey(&cursor, &plen, delayed_payment_basepoint); + fromwire_pubkey(&cursor, &plen, htlc_basepoint); + fromwire_pubkey(&cursor, &plen, first_per_commitment_point); + *channel_flags = fromwire_u8(&cursor, &plen); + fromwire_open_channel_tlvs(&cursor, &plen, tlvs); + return cursor != NULL; +} + +/* WIRE: ACCEPT_CHANNEL */ +u8 *towire_accept_channel(const tal_t *ctx, const struct channel_id *temporary_channel_id, struct amount_sat dust_limit_satoshis, struct amount_msat max_htlc_value_in_flight_msat, struct amount_sat channel_reserve_satoshis, struct amount_msat htlc_minimum_msat, u32 minimum_depth, u16 to_self_delay, u16 max_accepted_htlcs, const struct pubkey *funding_pubkey, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *first_per_commitment_point, const struct tlv_accept_channel_tlvs *tlvs) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ACCEPT_CHANNEL); + towire_channel_id(&p, temporary_channel_id); + towire_amount_sat(&p, dust_limit_satoshis); + towire_amount_msat(&p, max_htlc_value_in_flight_msat); + towire_amount_sat(&p, channel_reserve_satoshis); + towire_amount_msat(&p, htlc_minimum_msat); + towire_u32(&p, minimum_depth); + towire_u16(&p, to_self_delay); + towire_u16(&p, max_accepted_htlcs); + towire_pubkey(&p, funding_pubkey); + towire_pubkey(&p, revocation_basepoint); + towire_pubkey(&p, payment_basepoint); + towire_pubkey(&p, delayed_payment_basepoint); + towire_pubkey(&p, htlc_basepoint); + towire_pubkey(&p, first_per_commitment_point); + towire_accept_channel_tlvs(&p, tlvs); + + return memcheck(p, tal_count(p)); +} +bool fromwire_accept_channel(const void *p, struct channel_id *temporary_channel_id, struct amount_sat *dust_limit_satoshis, struct amount_msat *max_htlc_value_in_flight_msat, struct amount_sat *channel_reserve_satoshis, struct amount_msat *htlc_minimum_msat, u32 *minimum_depth, u16 *to_self_delay, u16 *max_accepted_htlcs, struct pubkey *funding_pubkey, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *first_per_commitment_point, struct tlv_accept_channel_tlvs *tlvs) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ACCEPT_CHANNEL) + return false; + fromwire_channel_id(&cursor, &plen, temporary_channel_id); + *dust_limit_satoshis = fromwire_amount_sat(&cursor, &plen); + *max_htlc_value_in_flight_msat = fromwire_amount_msat(&cursor, &plen); + *channel_reserve_satoshis = fromwire_amount_sat(&cursor, &plen); + *htlc_minimum_msat = fromwire_amount_msat(&cursor, &plen); + *minimum_depth = fromwire_u32(&cursor, &plen); + *to_self_delay = fromwire_u16(&cursor, &plen); + *max_accepted_htlcs = fromwire_u16(&cursor, &plen); + fromwire_pubkey(&cursor, &plen, funding_pubkey); + fromwire_pubkey(&cursor, &plen, revocation_basepoint); + fromwire_pubkey(&cursor, &plen, payment_basepoint); + fromwire_pubkey(&cursor, &plen, delayed_payment_basepoint); + fromwire_pubkey(&cursor, &plen, htlc_basepoint); + fromwire_pubkey(&cursor, &plen, first_per_commitment_point); + fromwire_accept_channel_tlvs(&cursor, &plen, tlvs); + return cursor != NULL; +} + +/* WIRE: FUNDING_CREATED */ +u8 *towire_funding_created(const tal_t *ctx, const struct channel_id *temporary_channel_id, const struct bitcoin_txid *funding_txid, u16 funding_output_index, const secp256k1_ecdsa_signature *signature) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_FUNDING_CREATED); + towire_channel_id(&p, temporary_channel_id); + towire_bitcoin_txid(&p, funding_txid); + towire_u16(&p, funding_output_index); + towire_secp256k1_ecdsa_signature(&p, signature); + + return memcheck(p, tal_count(p)); +} +bool fromwire_funding_created(const void *p, struct channel_id *temporary_channel_id, struct bitcoin_txid *funding_txid, u16 *funding_output_index, secp256k1_ecdsa_signature *signature) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_FUNDING_CREATED) + return false; + fromwire_channel_id(&cursor, &plen, temporary_channel_id); + fromwire_bitcoin_txid(&cursor, &plen, funding_txid); + *funding_output_index = fromwire_u16(&cursor, &plen); + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, signature); + return cursor != NULL; +} + +/* WIRE: FUNDING_SIGNED */ +u8 *towire_funding_signed(const tal_t *ctx, const struct channel_id *channel_id, const secp256k1_ecdsa_signature *signature) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_FUNDING_SIGNED); + towire_channel_id(&p, channel_id); + towire_secp256k1_ecdsa_signature(&p, signature); + + return memcheck(p, tal_count(p)); +} +bool fromwire_funding_signed(const void *p, struct channel_id *channel_id, secp256k1_ecdsa_signature *signature) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_FUNDING_SIGNED) + return false; + fromwire_channel_id(&cursor, &plen, channel_id); + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, signature); + return cursor != NULL; +} + +/* WIRE: FUNDING_LOCKED */ +u8 *towire_funding_locked(const tal_t *ctx, const struct channel_id *channel_id, const struct pubkey *next_per_commitment_point) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_FUNDING_LOCKED); + towire_channel_id(&p, channel_id); + towire_pubkey(&p, next_per_commitment_point); + + return memcheck(p, tal_count(p)); +} +bool fromwire_funding_locked(const void *p, struct channel_id *channel_id, struct pubkey *next_per_commitment_point) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_FUNDING_LOCKED) + return false; + fromwire_channel_id(&cursor, &plen, channel_id); + fromwire_pubkey(&cursor, &plen, next_per_commitment_point); + return cursor != NULL; +} + +/* WIRE: SHUTDOWN */ +u8 *towire_shutdown(const tal_t *ctx, const struct channel_id *channel_id, const u8 *scriptpubkey) +{ + u16 len = tal_count(scriptpubkey); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_SHUTDOWN); + towire_channel_id(&p, channel_id); + towire_u16(&p, len); + towire_u8_array(&p, scriptpubkey, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_shutdown(const tal_t *ctx, const void *p, struct channel_id *channel_id, u8 **scriptpubkey) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_SHUTDOWN) + return false; + fromwire_channel_id(&cursor, &plen, channel_id); + len = fromwire_u16(&cursor, &plen); + // 2nd case scriptpubkey + *scriptpubkey = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *scriptpubkey, len); + return cursor != NULL; +} + +/* WIRE: CLOSING_SIGNED */ +u8 *towire_closing_signed(const tal_t *ctx, const struct channel_id *channel_id, struct amount_sat fee_satoshis, const secp256k1_ecdsa_signature *signature) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CLOSING_SIGNED); + towire_channel_id(&p, channel_id); + towire_amount_sat(&p, fee_satoshis); + towire_secp256k1_ecdsa_signature(&p, signature); + + return memcheck(p, tal_count(p)); +} +bool fromwire_closing_signed(const void *p, struct channel_id *channel_id, struct amount_sat *fee_satoshis, secp256k1_ecdsa_signature *signature) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CLOSING_SIGNED) + return false; + fromwire_channel_id(&cursor, &plen, channel_id); + *fee_satoshis = fromwire_amount_sat(&cursor, &plen); + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, signature); + return cursor != NULL; +} + +/* WIRE: UPDATE_ADD_HTLC */ +u8 *towire_update_add_htlc(const tal_t *ctx, const struct channel_id *channel_id, u64 id, struct amount_msat amount_msat, const struct sha256 *payment_hash, u32 cltv_expiry, const u8 onion_routing_packet[1366]) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_UPDATE_ADD_HTLC); + towire_channel_id(&p, channel_id); + towire_u64(&p, id); + towire_amount_msat(&p, amount_msat); + towire_sha256(&p, payment_hash); + towire_u32(&p, cltv_expiry); + towire_u8_array(&p, onion_routing_packet, 1366); + + return memcheck(p, tal_count(p)); +} +bool fromwire_update_add_htlc(const void *p, struct channel_id *channel_id, u64 *id, struct amount_msat *amount_msat, struct sha256 *payment_hash, u32 *cltv_expiry, u8 onion_routing_packet[1366]) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_UPDATE_ADD_HTLC) + return false; + fromwire_channel_id(&cursor, &plen, channel_id); + *id = fromwire_u64(&cursor, &plen); + *amount_msat = fromwire_amount_msat(&cursor, &plen); + fromwire_sha256(&cursor, &plen, payment_hash); + *cltv_expiry = fromwire_u32(&cursor, &plen); + fromwire_u8_array(&cursor, &plen, onion_routing_packet, 1366); + return cursor != NULL; +} + +/* WIRE: UPDATE_FULFILL_HTLC */ +u8 *towire_update_fulfill_htlc(const tal_t *ctx, const struct channel_id *channel_id, u64 id, const struct preimage *payment_preimage) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_UPDATE_FULFILL_HTLC); + towire_channel_id(&p, channel_id); + towire_u64(&p, id); + towire_preimage(&p, payment_preimage); + + return memcheck(p, tal_count(p)); +} +bool fromwire_update_fulfill_htlc(const void *p, struct channel_id *channel_id, u64 *id, struct preimage *payment_preimage) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_UPDATE_FULFILL_HTLC) + return false; + fromwire_channel_id(&cursor, &plen, channel_id); + *id = fromwire_u64(&cursor, &plen); + fromwire_preimage(&cursor, &plen, payment_preimage); + return cursor != NULL; +} + +/* WIRE: UPDATE_FAIL_HTLC */ +u8 *towire_update_fail_htlc(const tal_t *ctx, const struct channel_id *channel_id, u64 id, const u8 *reason) +{ + u16 len = tal_count(reason); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_UPDATE_FAIL_HTLC); + towire_channel_id(&p, channel_id); + towire_u64(&p, id); + towire_u16(&p, len); + towire_u8_array(&p, reason, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_update_fail_htlc(const tal_t *ctx, const void *p, struct channel_id *channel_id, u64 *id, u8 **reason) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_UPDATE_FAIL_HTLC) + return false; + fromwire_channel_id(&cursor, &plen, channel_id); + *id = fromwire_u64(&cursor, &plen); + len = fromwire_u16(&cursor, &plen); + // 2nd case reason + *reason = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *reason, len); + return cursor != NULL; +} + +/* WIRE: UPDATE_FAIL_MALFORMED_HTLC */ +u8 *towire_update_fail_malformed_htlc(const tal_t *ctx, const struct channel_id *channel_id, u64 id, const struct sha256 *sha256_of_onion, u16 failure_code) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_UPDATE_FAIL_MALFORMED_HTLC); + towire_channel_id(&p, channel_id); + towire_u64(&p, id); + towire_sha256(&p, sha256_of_onion); + towire_u16(&p, failure_code); + + return memcheck(p, tal_count(p)); +} +bool fromwire_update_fail_malformed_htlc(const void *p, struct channel_id *channel_id, u64 *id, struct sha256 *sha256_of_onion, u16 *failure_code) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_UPDATE_FAIL_MALFORMED_HTLC) + return false; + fromwire_channel_id(&cursor, &plen, channel_id); + *id = fromwire_u64(&cursor, &plen); + fromwire_sha256(&cursor, &plen, sha256_of_onion); + *failure_code = fromwire_u16(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: COMMITMENT_SIGNED */ +u8 *towire_commitment_signed(const tal_t *ctx, const struct channel_id *channel_id, const secp256k1_ecdsa_signature *signature, const secp256k1_ecdsa_signature *htlc_signature) +{ + u16 num_htlcs = tal_count(htlc_signature); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_COMMITMENT_SIGNED); + towire_channel_id(&p, channel_id); + towire_secp256k1_ecdsa_signature(&p, signature); + towire_u16(&p, num_htlcs); + for (size_t i = 0; i < num_htlcs; i++) + towire_secp256k1_ecdsa_signature(&p, htlc_signature + i); + + return memcheck(p, tal_count(p)); +} +bool fromwire_commitment_signed(const tal_t *ctx, const void *p, struct channel_id *channel_id, secp256k1_ecdsa_signature *signature, secp256k1_ecdsa_signature **htlc_signature) +{ + u16 num_htlcs; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_COMMITMENT_SIGNED) + return false; + fromwire_channel_id(&cursor, &plen, channel_id); + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, signature); + num_htlcs = fromwire_u16(&cursor, &plen); + // 2nd case htlc_signature + *htlc_signature = num_htlcs ? tal_arr(ctx, secp256k1_ecdsa_signature, num_htlcs) : NULL; + for (size_t i = 0; i < num_htlcs; i++) + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, *htlc_signature + i); + return cursor != NULL; +} + +/* WIRE: REVOKE_AND_ACK */ +u8 *towire_revoke_and_ack(const tal_t *ctx, const struct channel_id *channel_id, const struct secret *per_commitment_secret, const struct pubkey *next_per_commitment_point) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_REVOKE_AND_ACK); + towire_channel_id(&p, channel_id); + towire_secret(&p, per_commitment_secret); + towire_pubkey(&p, next_per_commitment_point); + + return memcheck(p, tal_count(p)); +} +bool fromwire_revoke_and_ack(const void *p, struct channel_id *channel_id, struct secret *per_commitment_secret, struct pubkey *next_per_commitment_point) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_REVOKE_AND_ACK) + return false; + fromwire_channel_id(&cursor, &plen, channel_id); + fromwire_secret(&cursor, &plen, per_commitment_secret); + fromwire_pubkey(&cursor, &plen, next_per_commitment_point); + return cursor != NULL; +} + +/* WIRE: UPDATE_FEE */ +u8 *towire_update_fee(const tal_t *ctx, const struct channel_id *channel_id, u32 feerate_per_kw) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_UPDATE_FEE); + towire_channel_id(&p, channel_id); + towire_u32(&p, feerate_per_kw); + + return memcheck(p, tal_count(p)); +} +bool fromwire_update_fee(const void *p, struct channel_id *channel_id, u32 *feerate_per_kw) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_UPDATE_FEE) + return false; + fromwire_channel_id(&cursor, &plen, channel_id); + *feerate_per_kw = fromwire_u32(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CHANNEL_REESTABLISH */ +u8 *towire_channel_reestablish(const tal_t *ctx, const struct channel_id *channel_id, u64 next_commitment_number, u64 next_revocation_number, const struct secret *your_last_per_commitment_secret, const struct pubkey *my_current_per_commitment_point) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNEL_REESTABLISH); + towire_channel_id(&p, channel_id); + towire_u64(&p, next_commitment_number); + towire_u64(&p, next_revocation_number); + towire_secret(&p, your_last_per_commitment_secret); + towire_pubkey(&p, my_current_per_commitment_point); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channel_reestablish(const void *p, struct channel_id *channel_id, u64 *next_commitment_number, u64 *next_revocation_number, struct secret *your_last_per_commitment_secret, struct pubkey *my_current_per_commitment_point) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNEL_REESTABLISH) + return false; + fromwire_channel_id(&cursor, &plen, channel_id); + *next_commitment_number = fromwire_u64(&cursor, &plen); + *next_revocation_number = fromwire_u64(&cursor, &plen); + fromwire_secret(&cursor, &plen, your_last_per_commitment_secret); + fromwire_pubkey(&cursor, &plen, my_current_per_commitment_point); + return cursor != NULL; +} + +/* WIRE: ANNOUNCEMENT_SIGNATURES */ +u8 *towire_announcement_signatures(const tal_t *ctx, const struct channel_id *channel_id, const struct short_channel_id *short_channel_id, const secp256k1_ecdsa_signature *node_signature, const secp256k1_ecdsa_signature *bitcoin_signature) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ANNOUNCEMENT_SIGNATURES); + towire_channel_id(&p, channel_id); + towire_short_channel_id(&p, short_channel_id); + towire_secp256k1_ecdsa_signature(&p, node_signature); + towire_secp256k1_ecdsa_signature(&p, bitcoin_signature); + + return memcheck(p, tal_count(p)); +} +bool fromwire_announcement_signatures(const void *p, struct channel_id *channel_id, struct short_channel_id *short_channel_id, secp256k1_ecdsa_signature *node_signature, secp256k1_ecdsa_signature *bitcoin_signature) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ANNOUNCEMENT_SIGNATURES) + return false; + fromwire_channel_id(&cursor, &plen, channel_id); + fromwire_short_channel_id(&cursor, &plen, short_channel_id); + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, node_signature); + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, bitcoin_signature); + return cursor != NULL; +} + +/* WIRE: CHANNEL_ANNOUNCEMENT */ +u8 *towire_channel_announcement(const tal_t *ctx, const secp256k1_ecdsa_signature *node_signature_1, const secp256k1_ecdsa_signature *node_signature_2, const secp256k1_ecdsa_signature *bitcoin_signature_1, const secp256k1_ecdsa_signature *bitcoin_signature_2, const u8 *features, const struct bitcoin_blkid *chain_hash, const struct short_channel_id *short_channel_id, const struct node_id *node_id_1, const struct node_id *node_id_2, const struct pubkey *bitcoin_key_1, const struct pubkey *bitcoin_key_2) +{ + u16 len = tal_count(features); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNEL_ANNOUNCEMENT); + towire_secp256k1_ecdsa_signature(&p, node_signature_1); + towire_secp256k1_ecdsa_signature(&p, node_signature_2); + towire_secp256k1_ecdsa_signature(&p, bitcoin_signature_1); + towire_secp256k1_ecdsa_signature(&p, bitcoin_signature_2); + towire_u16(&p, len); + towire_u8_array(&p, features, len); + towire_bitcoin_blkid(&p, chain_hash); + towire_short_channel_id(&p, short_channel_id); + towire_node_id(&p, node_id_1); + towire_node_id(&p, node_id_2); + towire_pubkey(&p, bitcoin_key_1); + towire_pubkey(&p, bitcoin_key_2); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channel_announcement(const tal_t *ctx, const void *p, secp256k1_ecdsa_signature *node_signature_1, secp256k1_ecdsa_signature *node_signature_2, secp256k1_ecdsa_signature *bitcoin_signature_1, secp256k1_ecdsa_signature *bitcoin_signature_2, u8 **features, struct bitcoin_blkid *chain_hash, struct short_channel_id *short_channel_id, struct node_id *node_id_1, struct node_id *node_id_2, struct pubkey *bitcoin_key_1, struct pubkey *bitcoin_key_2) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNEL_ANNOUNCEMENT) + return false; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, node_signature_1); + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, node_signature_2); + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, bitcoin_signature_1); + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, bitcoin_signature_2); + len = fromwire_u16(&cursor, &plen); + // 2nd case features + *features = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *features, len); + fromwire_bitcoin_blkid(&cursor, &plen, chain_hash); + fromwire_short_channel_id(&cursor, &plen, short_channel_id); + fromwire_node_id(&cursor, &plen, node_id_1); + fromwire_node_id(&cursor, &plen, node_id_2); + fromwire_pubkey(&cursor, &plen, bitcoin_key_1); + fromwire_pubkey(&cursor, &plen, bitcoin_key_2); + return cursor != NULL; +} + +/* WIRE: NODE_ANNOUNCEMENT */ +u8 *towire_node_announcement(const tal_t *ctx, const secp256k1_ecdsa_signature *signature, const u8 *features, u32 timestamp, const struct node_id *node_id, const u8 rgb_color[3], const u8 alias[32], const u8 *addresses) +{ + u16 flen = tal_count(features); + u16 addrlen = tal_count(addresses); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_NODE_ANNOUNCEMENT); + towire_secp256k1_ecdsa_signature(&p, signature); + towire_u16(&p, flen); + towire_u8_array(&p, features, flen); + towire_u32(&p, timestamp); + towire_node_id(&p, node_id); + towire_u8_array(&p, rgb_color, 3); + towire_u8_array(&p, alias, 32); + towire_u16(&p, addrlen); + towire_u8_array(&p, addresses, addrlen); + + return memcheck(p, tal_count(p)); +} +bool fromwire_node_announcement(const tal_t *ctx, const void *p, secp256k1_ecdsa_signature *signature, u8 **features, u32 *timestamp, struct node_id *node_id, u8 rgb_color[3], u8 alias[32], u8 **addresses) +{ + u16 flen; + u16 addrlen; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_NODE_ANNOUNCEMENT) + return false; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, signature); + flen = fromwire_u16(&cursor, &plen); + // 2nd case features + *features = flen ? tal_arr(ctx, u8, flen) : NULL; + fromwire_u8_array(&cursor, &plen, *features, flen); + *timestamp = fromwire_u32(&cursor, &plen); + fromwire_node_id(&cursor, &plen, node_id); + fromwire_u8_array(&cursor, &plen, rgb_color, 3); + fromwire_u8_array(&cursor, &plen, alias, 32); + addrlen = fromwire_u16(&cursor, &plen); + // 2nd case addresses + *addresses = addrlen ? tal_arr(ctx, u8, addrlen) : NULL; + fromwire_u8_array(&cursor, &plen, *addresses, addrlen); + return cursor != NULL; +} + +/* WIRE: CHANNEL_UPDATE */ +u8 *towire_channel_update(const tal_t *ctx, const secp256k1_ecdsa_signature *signature, const struct bitcoin_blkid *chain_hash, const struct short_channel_id *short_channel_id, u32 timestamp, u8 message_flags, u8 channel_flags, u16 cltv_expiry_delta, struct amount_msat htlc_minimum_msat, u32 fee_base_msat, u32 fee_proportional_millionths) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNEL_UPDATE); + towire_secp256k1_ecdsa_signature(&p, signature); + towire_bitcoin_blkid(&p, chain_hash); + towire_short_channel_id(&p, short_channel_id); + towire_u32(&p, timestamp); + towire_u8(&p, message_flags); + towire_u8(&p, channel_flags); + towire_u16(&p, cltv_expiry_delta); + towire_amount_msat(&p, htlc_minimum_msat); + towire_u32(&p, fee_base_msat); + towire_u32(&p, fee_proportional_millionths); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channel_update(const void *p, secp256k1_ecdsa_signature *signature, struct bitcoin_blkid *chain_hash, struct short_channel_id *short_channel_id, u32 *timestamp, u8 *message_flags, u8 *channel_flags, u16 *cltv_expiry_delta, struct amount_msat *htlc_minimum_msat, u32 *fee_base_msat, u32 *fee_proportional_millionths) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNEL_UPDATE) + return false; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, signature); + fromwire_bitcoin_blkid(&cursor, &plen, chain_hash); + fromwire_short_channel_id(&cursor, &plen, short_channel_id); + *timestamp = fromwire_u32(&cursor, &plen); + *message_flags = fromwire_u8(&cursor, &plen); + *channel_flags = fromwire_u8(&cursor, &plen); + *cltv_expiry_delta = fromwire_u16(&cursor, &plen); + *htlc_minimum_msat = fromwire_amount_msat(&cursor, &plen); + *fee_base_msat = fromwire_u32(&cursor, &plen); + *fee_proportional_millionths = fromwire_u32(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: QUERY_SHORT_CHANNEL_IDS */ +u8 *towire_query_short_channel_ids(const tal_t *ctx, const struct bitcoin_blkid *chain_hash, const u8 *encoded_short_ids, const struct tlv_query_short_channel_ids_tlvs *tlvs) +{ + u16 len = tal_count(encoded_short_ids); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_QUERY_SHORT_CHANNEL_IDS); + towire_bitcoin_blkid(&p, chain_hash); + towire_u16(&p, len); + towire_u8_array(&p, encoded_short_ids, len); + towire_query_short_channel_ids_tlvs(&p, tlvs); + + return memcheck(p, tal_count(p)); +} +bool fromwire_query_short_channel_ids(const tal_t *ctx, const void *p, struct bitcoin_blkid *chain_hash, u8 **encoded_short_ids, struct tlv_query_short_channel_ids_tlvs *tlvs) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_QUERY_SHORT_CHANNEL_IDS) + return false; + fromwire_bitcoin_blkid(&cursor, &plen, chain_hash); + len = fromwire_u16(&cursor, &plen); + // 2nd case encoded_short_ids + *encoded_short_ids = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *encoded_short_ids, len); + fromwire_query_short_channel_ids_tlvs(&cursor, &plen, tlvs); + return cursor != NULL; +} + +/* WIRE: REPLY_SHORT_CHANNEL_IDS_END */ +u8 *towire_reply_short_channel_ids_end(const tal_t *ctx, const struct bitcoin_blkid *chain_hash, u8 full_information) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_REPLY_SHORT_CHANNEL_IDS_END); + towire_bitcoin_blkid(&p, chain_hash); + towire_u8(&p, full_information); + + return memcheck(p, tal_count(p)); +} +bool fromwire_reply_short_channel_ids_end(const void *p, struct bitcoin_blkid *chain_hash, u8 *full_information) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_REPLY_SHORT_CHANNEL_IDS_END) + return false; + fromwire_bitcoin_blkid(&cursor, &plen, chain_hash); + *full_information = fromwire_u8(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: QUERY_CHANNEL_RANGE */ +u8 *towire_query_channel_range(const tal_t *ctx, const struct bitcoin_blkid *chain_hash, u32 first_blocknum, u32 number_of_blocks, const struct tlv_query_channel_range_tlvs *tlvs) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_QUERY_CHANNEL_RANGE); + towire_bitcoin_blkid(&p, chain_hash); + towire_u32(&p, first_blocknum); + towire_u32(&p, number_of_blocks); + towire_query_channel_range_tlvs(&p, tlvs); + + return memcheck(p, tal_count(p)); +} +bool fromwire_query_channel_range(const void *p, struct bitcoin_blkid *chain_hash, u32 *first_blocknum, u32 *number_of_blocks, struct tlv_query_channel_range_tlvs *tlvs) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_QUERY_CHANNEL_RANGE) + return false; + fromwire_bitcoin_blkid(&cursor, &plen, chain_hash); + *first_blocknum = fromwire_u32(&cursor, &plen); + *number_of_blocks = fromwire_u32(&cursor, &plen); + fromwire_query_channel_range_tlvs(&cursor, &plen, tlvs); + return cursor != NULL; +} + +/* WIRE: REPLY_CHANNEL_RANGE */ +u8 *towire_reply_channel_range(const tal_t *ctx, const struct bitcoin_blkid *chain_hash, u32 first_blocknum, u32 number_of_blocks, u8 full_information, const u8 *encoded_short_ids, const struct tlv_reply_channel_range_tlvs *tlvs) +{ + u16 len = tal_count(encoded_short_ids); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_REPLY_CHANNEL_RANGE); + towire_bitcoin_blkid(&p, chain_hash); + towire_u32(&p, first_blocknum); + towire_u32(&p, number_of_blocks); + towire_u8(&p, full_information); + towire_u16(&p, len); + towire_u8_array(&p, encoded_short_ids, len); + towire_reply_channel_range_tlvs(&p, tlvs); + + return memcheck(p, tal_count(p)); +} +bool fromwire_reply_channel_range(const tal_t *ctx, const void *p, struct bitcoin_blkid *chain_hash, u32 *first_blocknum, u32 *number_of_blocks, u8 *full_information, u8 **encoded_short_ids, struct tlv_reply_channel_range_tlvs *tlvs) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_REPLY_CHANNEL_RANGE) + return false; + fromwire_bitcoin_blkid(&cursor, &plen, chain_hash); + *first_blocknum = fromwire_u32(&cursor, &plen); + *number_of_blocks = fromwire_u32(&cursor, &plen); + *full_information = fromwire_u8(&cursor, &plen); + len = fromwire_u16(&cursor, &plen); + // 2nd case encoded_short_ids + *encoded_short_ids = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *encoded_short_ids, len); + fromwire_reply_channel_range_tlvs(&cursor, &plen, tlvs); + return cursor != NULL; +} + +/* WIRE: GOSSIP_TIMESTAMP_FILTER */ +u8 *towire_gossip_timestamp_filter(const tal_t *ctx, const struct bitcoin_blkid *chain_hash, u32 first_timestamp, u32 timestamp_range) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIP_TIMESTAMP_FILTER); + towire_bitcoin_blkid(&p, chain_hash); + towire_u32(&p, first_timestamp); + towire_u32(&p, timestamp_range); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossip_timestamp_filter(const void *p, struct bitcoin_blkid *chain_hash, u32 *first_timestamp, u32 *timestamp_range) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIP_TIMESTAMP_FILTER) + return false; + fromwire_bitcoin_blkid(&cursor, &plen, chain_hash); + *first_timestamp = fromwire_u32(&cursor, &plen); + *timestamp_range = fromwire_u32(&cursor, &plen); + return cursor != NULL; +} + +/* WIRE: CHANNEL_UPDATE_OPTION_CHANNEL_HTLC_MAX */ +u8 *towire_channel_update_option_channel_htlc_max(const tal_t *ctx, const secp256k1_ecdsa_signature *signature, const struct bitcoin_blkid *chain_hash, const struct short_channel_id *short_channel_id, u32 timestamp, u8 message_flags, u8 channel_flags, u16 cltv_expiry_delta, struct amount_msat htlc_minimum_msat, u32 fee_base_msat, u32 fee_proportional_millionths, struct amount_msat htlc_maximum_msat) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_CHANNEL_UPDATE); + towire_secp256k1_ecdsa_signature(&p, signature); + towire_bitcoin_blkid(&p, chain_hash); + towire_short_channel_id(&p, short_channel_id); + towire_u32(&p, timestamp); + towire_u8(&p, message_flags); + towire_u8(&p, channel_flags); + towire_u16(&p, cltv_expiry_delta); + towire_amount_msat(&p, htlc_minimum_msat); + towire_u32(&p, fee_base_msat); + towire_u32(&p, fee_proportional_millionths); + towire_amount_msat(&p, htlc_maximum_msat); + + return memcheck(p, tal_count(p)); +} +bool fromwire_channel_update_option_channel_htlc_max(const void *p, secp256k1_ecdsa_signature *signature, struct bitcoin_blkid *chain_hash, struct short_channel_id *short_channel_id, u32 *timestamp, u8 *message_flags, u8 *channel_flags, u16 *cltv_expiry_delta, struct amount_msat *htlc_minimum_msat, u32 *fee_base_msat, u32 *fee_proportional_millionths, struct amount_msat *htlc_maximum_msat) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_CHANNEL_UPDATE) + return false; + fromwire_secp256k1_ecdsa_signature(&cursor, &plen, signature); + fromwire_bitcoin_blkid(&cursor, &plen, chain_hash); + fromwire_short_channel_id(&cursor, &plen, short_channel_id); + *timestamp = fromwire_u32(&cursor, &plen); + *message_flags = fromwire_u8(&cursor, &plen); + *channel_flags = fromwire_u8(&cursor, &plen); + *cltv_expiry_delta = fromwire_u16(&cursor, &plen); + *htlc_minimum_msat = fromwire_amount_msat(&cursor, &plen); + *fee_base_msat = fromwire_u32(&cursor, &plen); + *fee_proportional_millionths = fromwire_u32(&cursor, &plen); + *htlc_maximum_msat = fromwire_amount_msat(&cursor, &plen); + return cursor != NULL; +} + +// SHA256STAMP:exp-0-12bb4b7e8e380207af3b51bfc2b65997753bc3d37465eed70409a21998b50238 diff --git a/wire/peer_wiregen.h b/wire/peer_wiregen.h new file mode 100644 index 000000000..a2ba0136e --- /dev/null +++ b/wire/peer_wiregen.h @@ -0,0 +1,599 @@ +/* This file was generated by generate-wire.py */ +/* Do not modify this file! Modify the _csv file it was generated from. */ +/* Original template can be found at tools/gen/header_template */ + +#ifndef LIGHTNING_WIRE_PEER_WIREGEN_H +#define LIGHTNING_WIRE_PEER_WIREGEN_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum peer_wire { + WIRE_INIT = 16, + WIRE_ERROR = 17, + WIRE_PING = 18, + WIRE_PONG = 19, + WIRE_OPEN_CHANNEL = 32, + WIRE_ACCEPT_CHANNEL = 33, + WIRE_FUNDING_CREATED = 34, + WIRE_FUNDING_SIGNED = 35, + WIRE_FUNDING_LOCKED = 36, + WIRE_SHUTDOWN = 38, + WIRE_CLOSING_SIGNED = 39, + WIRE_UPDATE_ADD_HTLC = 128, + WIRE_UPDATE_FULFILL_HTLC = 130, + WIRE_UPDATE_FAIL_HTLC = 131, + WIRE_UPDATE_FAIL_MALFORMED_HTLC = 135, + WIRE_COMMITMENT_SIGNED = 132, + WIRE_REVOKE_AND_ACK = 133, + WIRE_UPDATE_FEE = 134, + WIRE_CHANNEL_REESTABLISH = 136, + WIRE_ANNOUNCEMENT_SIGNATURES = 259, + WIRE_CHANNEL_ANNOUNCEMENT = 256, + WIRE_NODE_ANNOUNCEMENT = 257, + WIRE_CHANNEL_UPDATE = 258, + WIRE_QUERY_SHORT_CHANNEL_IDS = 261, + WIRE_REPLY_SHORT_CHANNEL_IDS_END = 262, + WIRE_QUERY_CHANNEL_RANGE = 263, + WIRE_REPLY_CHANNEL_RANGE = 264, + WIRE_GOSSIP_TIMESTAMP_FILTER = 265, +}; + +const char *peer_wire_name(int e); + +/** + * Determine whether a given message type is defined as a message. + * + * Returns true if the message type is part of the message definitions we have + * generated parsers for, false if it is a custom message that cannot be + * handled internally. + */ +bool peer_wire_is_defined(u16 type); + +struct channel_update_checksums { + u32 checksum_node_id_1; + u32 checksum_node_id_2; +}; +struct channel_update_timestamps { + u32 timestamp_node_id_1; + u32 timestamp_node_id_2; +}; +struct tlv_n1_tlv3 { + struct pubkey node_id; + struct amount_msat amount_msat_1; + struct amount_msat amount_msat_2; +}; +struct tlv_query_short_channel_ids_tlvs_query_flags { + u8 encoding_type; + u8 *encoded_query_flags; +}; +struct tlv_reply_channel_range_tlvs_timestamps_tlv { + u8 encoding_type; + u8 *encoded_timestamps; +}; +struct tlv_init_tlvs { + /* Raw fields including unknown ones. */ + struct tlv_field *fields; + + /* TODO The following explicit fields could just point into the + * tlv_field entries above to save on memory. */ + struct bitcoin_blkid *networks; +}; +struct tlv_n1 { + /* Raw fields including unknown ones. */ + struct tlv_field *fields; + + /* TODO The following explicit fields could just point into the + * tlv_field entries above to save on memory. */ + u64 *tlv1; + struct short_channel_id *tlv2; + struct tlv_n1_tlv3 *tlv3; + u16 *tlv4; +}; +struct tlv_n2 { + /* Raw fields including unknown ones. */ + struct tlv_field *fields; + + /* TODO The following explicit fields could just point into the + * tlv_field entries above to save on memory. */ + u64 *tlv1; + u32 *tlv2; +}; +struct tlv_open_channel_tlvs { + /* Raw fields including unknown ones. */ + struct tlv_field *fields; + + /* TODO The following explicit fields could just point into the + * tlv_field entries above to save on memory. */ + u8 *upfront_shutdown_script; +}; +struct tlv_accept_channel_tlvs { + /* Raw fields including unknown ones. */ + struct tlv_field *fields; + + /* TODO The following explicit fields could just point into the + * tlv_field entries above to save on memory. */ + u8 *upfront_shutdown_script; +}; +struct tlv_query_short_channel_ids_tlvs { + /* Raw fields including unknown ones. */ + struct tlv_field *fields; + + /* TODO The following explicit fields could just point into the + * tlv_field entries above to save on memory. */ + struct tlv_query_short_channel_ids_tlvs_query_flags *query_flags; +}; +struct tlv_query_channel_range_tlvs { + /* Raw fields including unknown ones. */ + struct tlv_field *fields; + + /* TODO The following explicit fields could just point into the + * tlv_field entries above to save on memory. */ + bigsize *query_option; +}; +struct tlv_reply_channel_range_tlvs { + /* Raw fields including unknown ones. */ + struct tlv_field *fields; + + /* TODO The following explicit fields could just point into the + * tlv_field entries above to save on memory. */ + struct tlv_reply_channel_range_tlvs_timestamps_tlv *timestamps_tlv; + struct channel_update_checksums *checksums_tlv; +}; + +struct tlv_init_tlvs *tlv_init_tlvs_new(const tal_t *ctx); + +/** + * Deserialize a TLV stream for the init_tlvs namespace. + * + * This function will parse any TLV stream, as long as the type, length and + * value fields are formatted correctly. Fields that are not known in the + * current namespace are stored in the `fields` member. Validity can be + * checked using init_tlvs_is_valid. + */ +bool fromwire_init_tlvs(const u8 **cursor, size_t *max, + struct tlv_init_tlvs * record); + +/** + * Serialize a TLV stream for the init_tlvs namespace. + * + * This function only considers known fields from the init_tlvs namespace, + * and will ignore any fields that may be stored in the `fields` member. This + * ensures that the resulting stream is valid according to + * `init_tlvs_is_valid`. + */ +void towire_init_tlvs(u8 **pptr, const void *record); + +/** + * Check that the TLV stream is valid. + * + * Enforces the followin validity rules: + * - Types must be in monotonic non-repeating order + * - We must understand all even types + * + * Returns false if an error was detected, otherwise returns true. If err_index + * is non-null and we detect an error it is set to the index of the first error + * detected. + */ +bool init_tlvs_is_valid(const struct tlv_init_tlvs *record, + size_t *err_index); + +struct tlv_n1 *tlv_n1_new(const tal_t *ctx); + +/** + * Deserialize a TLV stream for the n1 namespace. + * + * This function will parse any TLV stream, as long as the type, length and + * value fields are formatted correctly. Fields that are not known in the + * current namespace are stored in the `fields` member. Validity can be + * checked using n1_is_valid. + */ +bool fromwire_n1(const u8 **cursor, size_t *max, + struct tlv_n1 * record); + +/** + * Serialize a TLV stream for the n1 namespace. + * + * This function only considers known fields from the n1 namespace, + * and will ignore any fields that may be stored in the `fields` member. This + * ensures that the resulting stream is valid according to + * `n1_is_valid`. + */ +void towire_n1(u8 **pptr, const void *record); + +/** + * Check that the TLV stream is valid. + * + * Enforces the followin validity rules: + * - Types must be in monotonic non-repeating order + * - We must understand all even types + * + * Returns false if an error was detected, otherwise returns true. If err_index + * is non-null and we detect an error it is set to the index of the first error + * detected. + */ +bool n1_is_valid(const struct tlv_n1 *record, + size_t *err_index); + +#define TLVS_N1_ARRAY_SIZE 4 +extern const struct tlv_record_type tlvs_n1[]; + + + +/* Define an enum with the constants */ +enum n1_types { + TLV_N1_TLV1 = 1, + TLV_N1_TLV2 = 2, + TLV_N1_TLV3 = 3, + TLV_N1_TLV4 = 254, +}; + +struct tlv_n2 *tlv_n2_new(const tal_t *ctx); + +/** + * Deserialize a TLV stream for the n2 namespace. + * + * This function will parse any TLV stream, as long as the type, length and + * value fields are formatted correctly. Fields that are not known in the + * current namespace are stored in the `fields` member. Validity can be + * checked using n2_is_valid. + */ +bool fromwire_n2(const u8 **cursor, size_t *max, + struct tlv_n2 * record); + +/** + * Serialize a TLV stream for the n2 namespace. + * + * This function only considers known fields from the n2 namespace, + * and will ignore any fields that may be stored in the `fields` member. This + * ensures that the resulting stream is valid according to + * `n2_is_valid`. + */ +void towire_n2(u8 **pptr, const void *record); + +/** + * Check that the TLV stream is valid. + * + * Enforces the followin validity rules: + * - Types must be in monotonic non-repeating order + * - We must understand all even types + * + * Returns false if an error was detected, otherwise returns true. If err_index + * is non-null and we detect an error it is set to the index of the first error + * detected. + */ +bool n2_is_valid(const struct tlv_n2 *record, + size_t *err_index); + +#define TLVS_N2_ARRAY_SIZE 2 +extern const struct tlv_record_type tlvs_n2[]; + + + +/* Define an enum with the constants */ +enum n2_types { + TLV_N2_TLV1 = 0, + TLV_N2_TLV2 = 11, +}; + +struct tlv_open_channel_tlvs *tlv_open_channel_tlvs_new(const tal_t *ctx); + +/** + * Deserialize a TLV stream for the open_channel_tlvs namespace. + * + * This function will parse any TLV stream, as long as the type, length and + * value fields are formatted correctly. Fields that are not known in the + * current namespace are stored in the `fields` member. Validity can be + * checked using open_channel_tlvs_is_valid. + */ +bool fromwire_open_channel_tlvs(const u8 **cursor, size_t *max, + struct tlv_open_channel_tlvs * record); + +/** + * Serialize a TLV stream for the open_channel_tlvs namespace. + * + * This function only considers known fields from the open_channel_tlvs namespace, + * and will ignore any fields that may be stored in the `fields` member. This + * ensures that the resulting stream is valid according to + * `open_channel_tlvs_is_valid`. + */ +void towire_open_channel_tlvs(u8 **pptr, const void *record); + +/** + * Check that the TLV stream is valid. + * + * Enforces the followin validity rules: + * - Types must be in monotonic non-repeating order + * - We must understand all even types + * + * Returns false if an error was detected, otherwise returns true. If err_index + * is non-null and we detect an error it is set to the index of the first error + * detected. + */ +bool open_channel_tlvs_is_valid(const struct tlv_open_channel_tlvs *record, + size_t *err_index); + +struct tlv_accept_channel_tlvs *tlv_accept_channel_tlvs_new(const tal_t *ctx); + +/** + * Deserialize a TLV stream for the accept_channel_tlvs namespace. + * + * This function will parse any TLV stream, as long as the type, length and + * value fields are formatted correctly. Fields that are not known in the + * current namespace are stored in the `fields` member. Validity can be + * checked using accept_channel_tlvs_is_valid. + */ +bool fromwire_accept_channel_tlvs(const u8 **cursor, size_t *max, + struct tlv_accept_channel_tlvs * record); + +/** + * Serialize a TLV stream for the accept_channel_tlvs namespace. + * + * This function only considers known fields from the accept_channel_tlvs namespace, + * and will ignore any fields that may be stored in the `fields` member. This + * ensures that the resulting stream is valid according to + * `accept_channel_tlvs_is_valid`. + */ +void towire_accept_channel_tlvs(u8 **pptr, const void *record); + +/** + * Check that the TLV stream is valid. + * + * Enforces the followin validity rules: + * - Types must be in monotonic non-repeating order + * - We must understand all even types + * + * Returns false if an error was detected, otherwise returns true. If err_index + * is non-null and we detect an error it is set to the index of the first error + * detected. + */ +bool accept_channel_tlvs_is_valid(const struct tlv_accept_channel_tlvs *record, + size_t *err_index); + +struct tlv_query_short_channel_ids_tlvs *tlv_query_short_channel_ids_tlvs_new(const tal_t *ctx); + +/** + * Deserialize a TLV stream for the query_short_channel_ids_tlvs namespace. + * + * This function will parse any TLV stream, as long as the type, length and + * value fields are formatted correctly. Fields that are not known in the + * current namespace are stored in the `fields` member. Validity can be + * checked using query_short_channel_ids_tlvs_is_valid. + */ +bool fromwire_query_short_channel_ids_tlvs(const u8 **cursor, size_t *max, + struct tlv_query_short_channel_ids_tlvs * record); + +/** + * Serialize a TLV stream for the query_short_channel_ids_tlvs namespace. + * + * This function only considers known fields from the query_short_channel_ids_tlvs namespace, + * and will ignore any fields that may be stored in the `fields` member. This + * ensures that the resulting stream is valid according to + * `query_short_channel_ids_tlvs_is_valid`. + */ +void towire_query_short_channel_ids_tlvs(u8 **pptr, const void *record); + +/** + * Check that the TLV stream is valid. + * + * Enforces the followin validity rules: + * - Types must be in monotonic non-repeating order + * - We must understand all even types + * + * Returns false if an error was detected, otherwise returns true. If err_index + * is non-null and we detect an error it is set to the index of the first error + * detected. + */ +bool query_short_channel_ids_tlvs_is_valid(const struct tlv_query_short_channel_ids_tlvs *record, + size_t *err_index); + +struct tlv_query_channel_range_tlvs *tlv_query_channel_range_tlvs_new(const tal_t *ctx); + +/** + * Deserialize a TLV stream for the query_channel_range_tlvs namespace. + * + * This function will parse any TLV stream, as long as the type, length and + * value fields are formatted correctly. Fields that are not known in the + * current namespace are stored in the `fields` member. Validity can be + * checked using query_channel_range_tlvs_is_valid. + */ +bool fromwire_query_channel_range_tlvs(const u8 **cursor, size_t *max, + struct tlv_query_channel_range_tlvs * record); + +/** + * Serialize a TLV stream for the query_channel_range_tlvs namespace. + * + * This function only considers known fields from the query_channel_range_tlvs namespace, + * and will ignore any fields that may be stored in the `fields` member. This + * ensures that the resulting stream is valid according to + * `query_channel_range_tlvs_is_valid`. + */ +void towire_query_channel_range_tlvs(u8 **pptr, const void *record); + +/** + * Check that the TLV stream is valid. + * + * Enforces the followin validity rules: + * - Types must be in monotonic non-repeating order + * - We must understand all even types + * + * Returns false if an error was detected, otherwise returns true. If err_index + * is non-null and we detect an error it is set to the index of the first error + * detected. + */ +bool query_channel_range_tlvs_is_valid(const struct tlv_query_channel_range_tlvs *record, + size_t *err_index); + +struct tlv_reply_channel_range_tlvs *tlv_reply_channel_range_tlvs_new(const tal_t *ctx); + +/** + * Deserialize a TLV stream for the reply_channel_range_tlvs namespace. + * + * This function will parse any TLV stream, as long as the type, length and + * value fields are formatted correctly. Fields that are not known in the + * current namespace are stored in the `fields` member. Validity can be + * checked using reply_channel_range_tlvs_is_valid. + */ +bool fromwire_reply_channel_range_tlvs(const u8 **cursor, size_t *max, + struct tlv_reply_channel_range_tlvs * record); + +/** + * Serialize a TLV stream for the reply_channel_range_tlvs namespace. + * + * This function only considers known fields from the reply_channel_range_tlvs namespace, + * and will ignore any fields that may be stored in the `fields` member. This + * ensures that the resulting stream is valid according to + * `reply_channel_range_tlvs_is_valid`. + */ +void towire_reply_channel_range_tlvs(u8 **pptr, const void *record); + +/** + * Check that the TLV stream is valid. + * + * Enforces the followin validity rules: + * - Types must be in monotonic non-repeating order + * - We must understand all even types + * + * Returns false if an error was detected, otherwise returns true. If err_index + * is non-null and we detect an error it is set to the index of the first error + * detected. + */ +bool reply_channel_range_tlvs_is_valid(const struct tlv_reply_channel_range_tlvs *record, + size_t *err_index); + +/* SUBTYPE: CHANNEL_UPDATE_CHECKSUMS */ +void towire_channel_update_checksums(u8 **p, const struct channel_update_checksums *channel_update_checksums); +void fromwire_channel_update_checksums(const u8 **cursor, size_t *plen, struct channel_update_checksums *channel_update_checksums); + +/* SUBTYPE: CHANNEL_UPDATE_TIMESTAMPS */ +void towire_channel_update_timestamps(u8 **p, const struct channel_update_timestamps *channel_update_timestamps); +void fromwire_channel_update_timestamps(const u8 **cursor, size_t *plen, struct channel_update_timestamps *channel_update_timestamps); + +/* WIRE: INIT */ +u8 *towire_init(const tal_t *ctx, const u8 *globalfeatures, const u8 *features, const struct tlv_init_tlvs *tlvs); +bool fromwire_init(const tal_t *ctx, const void *p, u8 **globalfeatures, u8 **features, struct tlv_init_tlvs *tlvs); + +/* WIRE: ERROR */ +u8 *towire_error(const tal_t *ctx, const struct channel_id *channel_id, const u8 *data); +bool fromwire_error(const tal_t *ctx, const void *p, struct channel_id *channel_id, u8 **data); + +/* WIRE: PING */ +u8 *towire_ping(const tal_t *ctx, u16 num_pong_bytes, const u8 *ignored); +bool fromwire_ping(const tal_t *ctx, const void *p, u16 *num_pong_bytes, u8 **ignored); + +/* WIRE: PONG */ +u8 *towire_pong(const tal_t *ctx, const u8 *ignored); +bool fromwire_pong(const tal_t *ctx, const void *p, u8 **ignored); + +/* WIRE: OPEN_CHANNEL */ +u8 *towire_open_channel(const tal_t *ctx, const struct bitcoin_blkid *chain_hash, const struct channel_id *temporary_channel_id, struct amount_sat funding_satoshis, struct amount_msat push_msat, struct amount_sat dust_limit_satoshis, struct amount_msat max_htlc_value_in_flight_msat, struct amount_sat channel_reserve_satoshis, struct amount_msat htlc_minimum_msat, u32 feerate_per_kw, u16 to_self_delay, u16 max_accepted_htlcs, const struct pubkey *funding_pubkey, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *first_per_commitment_point, u8 channel_flags, const struct tlv_open_channel_tlvs *tlvs); +bool fromwire_open_channel(const void *p, struct bitcoin_blkid *chain_hash, struct channel_id *temporary_channel_id, struct amount_sat *funding_satoshis, struct amount_msat *push_msat, struct amount_sat *dust_limit_satoshis, struct amount_msat *max_htlc_value_in_flight_msat, struct amount_sat *channel_reserve_satoshis, struct amount_msat *htlc_minimum_msat, u32 *feerate_per_kw, u16 *to_self_delay, u16 *max_accepted_htlcs, struct pubkey *funding_pubkey, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *first_per_commitment_point, u8 *channel_flags, struct tlv_open_channel_tlvs *tlvs); + +/* WIRE: ACCEPT_CHANNEL */ +u8 *towire_accept_channel(const tal_t *ctx, const struct channel_id *temporary_channel_id, struct amount_sat dust_limit_satoshis, struct amount_msat max_htlc_value_in_flight_msat, struct amount_sat channel_reserve_satoshis, struct amount_msat htlc_minimum_msat, u32 minimum_depth, u16 to_self_delay, u16 max_accepted_htlcs, const struct pubkey *funding_pubkey, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *first_per_commitment_point, const struct tlv_accept_channel_tlvs *tlvs); +bool fromwire_accept_channel(const void *p, struct channel_id *temporary_channel_id, struct amount_sat *dust_limit_satoshis, struct amount_msat *max_htlc_value_in_flight_msat, struct amount_sat *channel_reserve_satoshis, struct amount_msat *htlc_minimum_msat, u32 *minimum_depth, u16 *to_self_delay, u16 *max_accepted_htlcs, struct pubkey *funding_pubkey, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *first_per_commitment_point, struct tlv_accept_channel_tlvs *tlvs); + +/* WIRE: FUNDING_CREATED */ +u8 *towire_funding_created(const tal_t *ctx, const struct channel_id *temporary_channel_id, const struct bitcoin_txid *funding_txid, u16 funding_output_index, const secp256k1_ecdsa_signature *signature); +bool fromwire_funding_created(const void *p, struct channel_id *temporary_channel_id, struct bitcoin_txid *funding_txid, u16 *funding_output_index, secp256k1_ecdsa_signature *signature); + +/* WIRE: FUNDING_SIGNED */ +u8 *towire_funding_signed(const tal_t *ctx, const struct channel_id *channel_id, const secp256k1_ecdsa_signature *signature); +bool fromwire_funding_signed(const void *p, struct channel_id *channel_id, secp256k1_ecdsa_signature *signature); + +/* WIRE: FUNDING_LOCKED */ +u8 *towire_funding_locked(const tal_t *ctx, const struct channel_id *channel_id, const struct pubkey *next_per_commitment_point); +bool fromwire_funding_locked(const void *p, struct channel_id *channel_id, struct pubkey *next_per_commitment_point); + +/* WIRE: SHUTDOWN */ +u8 *towire_shutdown(const tal_t *ctx, const struct channel_id *channel_id, const u8 *scriptpubkey); +bool fromwire_shutdown(const tal_t *ctx, const void *p, struct channel_id *channel_id, u8 **scriptpubkey); + +/* WIRE: CLOSING_SIGNED */ +u8 *towire_closing_signed(const tal_t *ctx, const struct channel_id *channel_id, struct amount_sat fee_satoshis, const secp256k1_ecdsa_signature *signature); +bool fromwire_closing_signed(const void *p, struct channel_id *channel_id, struct amount_sat *fee_satoshis, secp256k1_ecdsa_signature *signature); + +/* WIRE: UPDATE_ADD_HTLC */ +u8 *towire_update_add_htlc(const tal_t *ctx, const struct channel_id *channel_id, u64 id, struct amount_msat amount_msat, const struct sha256 *payment_hash, u32 cltv_expiry, const u8 onion_routing_packet[1366]); +bool fromwire_update_add_htlc(const void *p, struct channel_id *channel_id, u64 *id, struct amount_msat *amount_msat, struct sha256 *payment_hash, u32 *cltv_expiry, u8 onion_routing_packet[1366]); + +/* WIRE: UPDATE_FULFILL_HTLC */ +u8 *towire_update_fulfill_htlc(const tal_t *ctx, const struct channel_id *channel_id, u64 id, const struct preimage *payment_preimage); +bool fromwire_update_fulfill_htlc(const void *p, struct channel_id *channel_id, u64 *id, struct preimage *payment_preimage); + +/* WIRE: UPDATE_FAIL_HTLC */ +u8 *towire_update_fail_htlc(const tal_t *ctx, const struct channel_id *channel_id, u64 id, const u8 *reason); +bool fromwire_update_fail_htlc(const tal_t *ctx, const void *p, struct channel_id *channel_id, u64 *id, u8 **reason); + +/* WIRE: UPDATE_FAIL_MALFORMED_HTLC */ +u8 *towire_update_fail_malformed_htlc(const tal_t *ctx, const struct channel_id *channel_id, u64 id, const struct sha256 *sha256_of_onion, u16 failure_code); +bool fromwire_update_fail_malformed_htlc(const void *p, struct channel_id *channel_id, u64 *id, struct sha256 *sha256_of_onion, u16 *failure_code); + +/* WIRE: COMMITMENT_SIGNED */ +u8 *towire_commitment_signed(const tal_t *ctx, const struct channel_id *channel_id, const secp256k1_ecdsa_signature *signature, const secp256k1_ecdsa_signature *htlc_signature); +bool fromwire_commitment_signed(const tal_t *ctx, const void *p, struct channel_id *channel_id, secp256k1_ecdsa_signature *signature, secp256k1_ecdsa_signature **htlc_signature); + +/* WIRE: REVOKE_AND_ACK */ +u8 *towire_revoke_and_ack(const tal_t *ctx, const struct channel_id *channel_id, const struct secret *per_commitment_secret, const struct pubkey *next_per_commitment_point); +bool fromwire_revoke_and_ack(const void *p, struct channel_id *channel_id, struct secret *per_commitment_secret, struct pubkey *next_per_commitment_point); + +/* WIRE: UPDATE_FEE */ +u8 *towire_update_fee(const tal_t *ctx, const struct channel_id *channel_id, u32 feerate_per_kw); +bool fromwire_update_fee(const void *p, struct channel_id *channel_id, u32 *feerate_per_kw); + +/* WIRE: CHANNEL_REESTABLISH */ +u8 *towire_channel_reestablish(const tal_t *ctx, const struct channel_id *channel_id, u64 next_commitment_number, u64 next_revocation_number, const struct secret *your_last_per_commitment_secret, const struct pubkey *my_current_per_commitment_point); +bool fromwire_channel_reestablish(const void *p, struct channel_id *channel_id, u64 *next_commitment_number, u64 *next_revocation_number, struct secret *your_last_per_commitment_secret, struct pubkey *my_current_per_commitment_point); + +/* WIRE: ANNOUNCEMENT_SIGNATURES */ +u8 *towire_announcement_signatures(const tal_t *ctx, const struct channel_id *channel_id, const struct short_channel_id *short_channel_id, const secp256k1_ecdsa_signature *node_signature, const secp256k1_ecdsa_signature *bitcoin_signature); +bool fromwire_announcement_signatures(const void *p, struct channel_id *channel_id, struct short_channel_id *short_channel_id, secp256k1_ecdsa_signature *node_signature, secp256k1_ecdsa_signature *bitcoin_signature); + +/* WIRE: CHANNEL_ANNOUNCEMENT */ +u8 *towire_channel_announcement(const tal_t *ctx, const secp256k1_ecdsa_signature *node_signature_1, const secp256k1_ecdsa_signature *node_signature_2, const secp256k1_ecdsa_signature *bitcoin_signature_1, const secp256k1_ecdsa_signature *bitcoin_signature_2, const u8 *features, const struct bitcoin_blkid *chain_hash, const struct short_channel_id *short_channel_id, const struct node_id *node_id_1, const struct node_id *node_id_2, const struct pubkey *bitcoin_key_1, const struct pubkey *bitcoin_key_2); +bool fromwire_channel_announcement(const tal_t *ctx, const void *p, secp256k1_ecdsa_signature *node_signature_1, secp256k1_ecdsa_signature *node_signature_2, secp256k1_ecdsa_signature *bitcoin_signature_1, secp256k1_ecdsa_signature *bitcoin_signature_2, u8 **features, struct bitcoin_blkid *chain_hash, struct short_channel_id *short_channel_id, struct node_id *node_id_1, struct node_id *node_id_2, struct pubkey *bitcoin_key_1, struct pubkey *bitcoin_key_2); + +/* WIRE: NODE_ANNOUNCEMENT */ +u8 *towire_node_announcement(const tal_t *ctx, const secp256k1_ecdsa_signature *signature, const u8 *features, u32 timestamp, const struct node_id *node_id, const u8 rgb_color[3], const u8 alias[32], const u8 *addresses); +bool fromwire_node_announcement(const tal_t *ctx, const void *p, secp256k1_ecdsa_signature *signature, u8 **features, u32 *timestamp, struct node_id *node_id, u8 rgb_color[3], u8 alias[32], u8 **addresses); + +/* WIRE: CHANNEL_UPDATE */ +u8 *towire_channel_update(const tal_t *ctx, const secp256k1_ecdsa_signature *signature, const struct bitcoin_blkid *chain_hash, const struct short_channel_id *short_channel_id, u32 timestamp, u8 message_flags, u8 channel_flags, u16 cltv_expiry_delta, struct amount_msat htlc_minimum_msat, u32 fee_base_msat, u32 fee_proportional_millionths); +bool fromwire_channel_update(const void *p, secp256k1_ecdsa_signature *signature, struct bitcoin_blkid *chain_hash, struct short_channel_id *short_channel_id, u32 *timestamp, u8 *message_flags, u8 *channel_flags, u16 *cltv_expiry_delta, struct amount_msat *htlc_minimum_msat, u32 *fee_base_msat, u32 *fee_proportional_millionths); + +/* WIRE: QUERY_SHORT_CHANNEL_IDS */ +u8 *towire_query_short_channel_ids(const tal_t *ctx, const struct bitcoin_blkid *chain_hash, const u8 *encoded_short_ids, const struct tlv_query_short_channel_ids_tlvs *tlvs); +bool fromwire_query_short_channel_ids(const tal_t *ctx, const void *p, struct bitcoin_blkid *chain_hash, u8 **encoded_short_ids, struct tlv_query_short_channel_ids_tlvs *tlvs); + +/* WIRE: REPLY_SHORT_CHANNEL_IDS_END */ +u8 *towire_reply_short_channel_ids_end(const tal_t *ctx, const struct bitcoin_blkid *chain_hash, u8 full_information); +bool fromwire_reply_short_channel_ids_end(const void *p, struct bitcoin_blkid *chain_hash, u8 *full_information); + +/* WIRE: QUERY_CHANNEL_RANGE */ +u8 *towire_query_channel_range(const tal_t *ctx, const struct bitcoin_blkid *chain_hash, u32 first_blocknum, u32 number_of_blocks, const struct tlv_query_channel_range_tlvs *tlvs); +bool fromwire_query_channel_range(const void *p, struct bitcoin_blkid *chain_hash, u32 *first_blocknum, u32 *number_of_blocks, struct tlv_query_channel_range_tlvs *tlvs); + +/* WIRE: REPLY_CHANNEL_RANGE */ +u8 *towire_reply_channel_range(const tal_t *ctx, const struct bitcoin_blkid *chain_hash, u32 first_blocknum, u32 number_of_blocks, u8 full_information, const u8 *encoded_short_ids, const struct tlv_reply_channel_range_tlvs *tlvs); +bool fromwire_reply_channel_range(const tal_t *ctx, const void *p, struct bitcoin_blkid *chain_hash, u32 *first_blocknum, u32 *number_of_blocks, u8 *full_information, u8 **encoded_short_ids, struct tlv_reply_channel_range_tlvs *tlvs); + +/* WIRE: GOSSIP_TIMESTAMP_FILTER */ +u8 *towire_gossip_timestamp_filter(const tal_t *ctx, const struct bitcoin_blkid *chain_hash, u32 first_timestamp, u32 timestamp_range); +bool fromwire_gossip_timestamp_filter(const void *p, struct bitcoin_blkid *chain_hash, u32 *first_timestamp, u32 *timestamp_range); + +/* WIRE: CHANNEL_UPDATE_OPTION_CHANNEL_HTLC_MAX */ +u8 *towire_channel_update_option_channel_htlc_max(const tal_t *ctx, const secp256k1_ecdsa_signature *signature, const struct bitcoin_blkid *chain_hash, const struct short_channel_id *short_channel_id, u32 timestamp, u8 message_flags, u8 channel_flags, u16 cltv_expiry_delta, struct amount_msat htlc_minimum_msat, u32 fee_base_msat, u32 fee_proportional_millionths, struct amount_msat htlc_maximum_msat); +bool fromwire_channel_update_option_channel_htlc_max(const void *p, secp256k1_ecdsa_signature *signature, struct bitcoin_blkid *chain_hash, struct short_channel_id *short_channel_id, u32 *timestamp, u8 *message_flags, u8 *channel_flags, u16 *cltv_expiry_delta, struct amount_msat *htlc_minimum_msat, u32 *fee_base_msat, u32 *fee_proportional_millionths, struct amount_msat *htlc_maximum_msat); + + +#endif /* LIGHTNING_WIRE_PEER_WIREGEN_H */ + +// SHA256STAMP:exp-0-12bb4b7e8e380207af3b51bfc2b65997753bc3d37465eed70409a21998b50238