#include <common/cryptomsg.h>
#include <common/channel_config.h>

# Begin!  (passes gossipd-client fd)
channel_init,1000
channel_init,,chain_hash,struct bitcoin_blkid
channel_init,,funding_txid,struct bitcoin_txid
channel_init,,funding_txout,u16
channel_init,,funding_satoshi,u64
channel_init,,our_config,struct channel_config
channel_init,,their_config,struct channel_config
# FIXME: Fix generate-wire.py to allow NUM_SIDES*u32 here.
channel_init,,feerate_per_kw,2*u32
channel_init,,feerate_min,u32
channel_init,,feerate_max,u32
channel_init,,first_commit_sig,secp256k1_ecdsa_signature
channel_init,,crypto_state,struct crypto_state
channel_init,,remote_fundingkey,struct pubkey
channel_init,,remote_revocation_basepoint,struct pubkey
channel_init,,remote_payment_basepoint,struct pubkey
channel_init,,remote_htlc_basepoint,struct pubkey
channel_init,,remote_delayed_payment_basepoint,struct pubkey
channel_init,,remote_per_commit,struct pubkey
channel_init,,old_remote_per_commit,struct pubkey
channel_init,,funder,enum side
channel_init,,fee_base,u32
channel_init,,fee_proportional,u32
channel_init,,local_msatoshi,u64
channel_init,,seed,struct privkey
channel_init,,local_node_id,struct pubkey
channel_init,,remote_node_id,struct pubkey
channel_init,,commit_msec,u32
channel_init,,cltv_delta,u16
channel_init,,last_was_revoke,bool
channel_init,,num_last_sent_commit,u16
channel_init,,last_sent_commit,num_last_sent_commit*struct changed_htlc
channel_init,,next_index_local,u64
channel_init,,next_index_remote,u64
channel_init,,revocations_received,u64
channel_init,,next_htlc_id,u64
channel_init,,num_htlcs,u16
channel_init,,htlcs,num_htlcs*struct added_htlc
channel_init,,htlc_states,num_htlcs*enum htlc_state
channel_init,,num_fulfilled,u16
channel_init,,fulfilled,num_fulfilled*struct fulfilled_htlc
channel_init,,fulfilled_sides,num_fulfilled*enum side
channel_init,,num_failed,u16
channel_init,,failed,num_failed*struct failed_htlc
channel_init,,failed_sides,num_failed*enum side
channel_init,,local_funding_locked,bool
channel_init,,remote_funding_locked,bool
channel_init,,funding_short_id,struct short_channel_id
channel_init,,reestablish,bool
channel_init,,send_shutdown,bool
channel_init,,remote_shutdown_received,bool
channel_init,,final_scriptpubkey_len,u16
channel_init,,final_scriptpubkey,final_scriptpubkey_len*u8
channel_init,,flags,u8
channel_init,,init_peer_pkt_len,u16
channel_init,,init_peer_pkt,init_peer_pkt_len*u8
channel_init,,reached_announce_depth,bool

# Tx is deep enough, go!
channel_funding_locked,1002
channel_funding_locked,,short_channel_id,struct short_channel_id

# Tell the channel that we may announce the channel's existence
channel_funding_announce_depth,1003

# Tell channel to offer this htlc
channel_offer_htlc,1004
channel_offer_htlc,,amount_msat,u64
channel_offer_htlc,,cltv_expiry,u32
channel_offer_htlc,,payment_hash,struct sha256
channel_offer_htlc,,onion_routing_packet,1366*u8

# Reply; synchronous since IDs have to increment.
channel_offer_htlc_reply,1104
channel_offer_htlc_reply,,id,u64
# Zero failure code means success.
channel_offer_htlc_reply,,failure_code,u16
channel_offer_htlc_reply,,failurestrlen,u16
channel_offer_htlc_reply,,failurestr,failurestrlen*u8

# Main daemon found out the preimage for an HTLC
#include <bitcoin/preimage.h>
channel_fulfill_htlc,1005
channel_fulfill_htlc,,id,u64
channel_fulfill_htlc,,payment_preimage,struct preimage

# Main daemon says HTLC failed
channel_fail_htlc,1006
channel_fail_htlc,,id,u64
# If this is non-zero length, you need to wrap this and pass it on.
channel_fail_htlc,,len,u16
channel_fail_htlc,,error_pkt,len*u8
# If it errcode is != 0, it's a local error, otherwise we're passing through.
channel_fail_htlc,,errcode,u16
# If errcode & UPDATE, this says which outgoing channel failed.
channel_fail_htlc,,which_channel,struct short_channel_id

# Ping/pong test.
channel_ping,1011
channel_ping,,num_pong_bytes,u16
channel_ping,,len,u16

channel_ping_reply,1111
channel_ping_reply,,totlen,u16

# When we receive funding_locked.
channel_got_funding_locked,1019
channel_got_funding_locked,,next_per_commit_point,struct pubkey

# When we send a commitment_signed message, tell master.
channel_sending_commitsig,1020
channel_sending_commitsig,,commitnum,u64
channel_sending_commitsig,,feerate,u32
# SENT_ADD_COMMIT, SENT_REMOVE_ACK_COMMIT, SENT_ADD_ACK_COMMIT, SENT_REMOVE_COMMIT
channel_sending_commitsig,,num_changed,u16
channel_sending_commitsig,,changed,num_changed*struct changed_htlc
channel_sending_commitsig,,commit_sig,secp256k1_ecdsa_signature
channel_sending_commitsig,,num_htlc_sigs,u16
channel_sending_commitsig,,htlc_sigs,num_htlc_sigs*secp256k1_ecdsa_signature

# Wait for reply, to make sure it's on disk before we send commit.
channel_sending_commitsig_reply,1120

# When we have a commitment_signed message, tell master to remember.
channel_got_commitsig,1021
channel_got_commitsig,,commitnum,u64
channel_got_commitsig,,feerate,u32
channel_got_commitsig,,signature,secp256k1_ecdsa_signature
channel_got_commitsig,,num_htlcs,u16
channel_got_commitsig,,htlc_signature,num_htlcs*secp256k1_ecdsa_signature
# RCVD_ADD_COMMIT: we're now committed to their new offered HTLCs.
channel_got_commitsig,,num_added,u16
channel_got_commitsig,,added,num_added*struct added_htlc
channel_got_commitsig,,shared_secret,num_added*struct secret
# RCVD_REMOVE_COMMIT: we're now no longer committed to these HTLCs.
channel_got_commitsig,,num_fulfilled,u16
channel_got_commitsig,,fulfilled,num_fulfilled*struct fulfilled_htlc
channel_got_commitsig,,num_failed,u16
channel_got_commitsig,,failed,num_failed*struct failed_htlc
# RCVD_ADD_ACK_COMMIT, RCVD_REMOVE_ACK_COMMIT
channel_got_commitsig,,num_changed,u16
channel_got_commitsig,,changed,num_changed*struct changed_htlc
channel_got_commitsig,,tx,struct bitcoin_tx

# Wait for reply, to make sure it's on disk before we send revocation.
channel_got_commitsig_reply,1121

#include <common/htlc_wire.h>

channel_got_revoke,1022
channel_got_revoke,,revokenum,u64
channel_got_revoke,,per_commitment_secret,struct sha256
channel_got_revoke,,next_per_commit_point,struct pubkey
# RCVD_ADD_ACK_REVOCATION, RCVD_REMOVE_ACK_REVOCATION, RCVD_ADD_REVOCATION, RCVD_REMOVE_REVOCATION
channel_got_revoke,,num_changed,u16
channel_got_revoke,,changed,num_changed*struct changed_htlc
# Wait for reply, to make sure it's on disk before we continue
# (eg. if we sent another commitment_signed, that would implicitly ack).
channel_got_revoke_reply,1122

# Tell peer to shut down channel.
channel_send_shutdown,1023

# Peer told us that channel is shutting down
channel_got_shutdown,1024
channel_got_shutdown,,scriptpubkey_len,u16
channel_got_shutdown,,scriptpubkey,scriptpubkey_len*u8

# Shutdown is complete, ready for closing negotiation. + peer_fd & gossip_fd.
channel_shutdown_complete,1025
channel_shutdown_complete,,crypto_state,struct crypto_state

# Re-enable commit timer.
channel_dev_reenable_commit,1026
channel_dev_reenable_commit_reply,1126

channel_feerates,1027
channel_feerates,,feerate,u32
channel_feerates,,min_feerate,u32
channel_feerates,,max_feerate,u32
