#include <bitcoin/chainparams.h>
#include <common/cryptomsg.h>
#include <common/channel_config.h>
#include <common/channel_id.h>
#include <common/channel_type.h>
#include <common/derive_basepoints.h>
#include <common/features.h>

msgtype,openingd_init,6000
# Which network are we configured for?
msgdata,openingd_init,chainparams,chainparams,
msgdata,openingd_init,our_features,feature_set,
msgdata,openingd_init,their_init_features_len,u16,
msgdata,openingd_init,their_init_features,u8,their_init_features_len
# Base configuration we'll offer (channel reserve will vary with amount)
msgdata,openingd_init,our_config,channel_config,
# Minimum/maximum configuration values we'll accept
msgdata,openingd_init,max_to_self_delay,u32,
msgdata,openingd_init,min_effective_htlc_capacity_msat,amount_msat,
msgdata,openingd_init,our_basepoints,basepoints,
msgdata,openingd_init,our_funding_pubkey,pubkey,
# Constraints in case the other end tries to open a channel.
msgdata,openingd_init,minimum_depth,u32,
msgdata,openingd_init,min_feerate,u32,
msgdata,openingd_init,max_feerate,u32,
msgdata,openingd_init,dev_temporary_channel_id,?byte,32
# Do we allow `fundchannel` or the `openchannel` hook to set sub-dust
# reserves? This is explicitly required by the spec for safety
# reasons, but some implementations and users keep asking for it.
msgdata,openingd_init,allowdustreserve,bool,

# Openingd->master: they offered channel, should we continue?
msgtype,openingd_got_offer,6005
msgdata,openingd_got_offer,funding_satoshis,amount_sat,
msgdata,openingd_got_offer,push_msat,amount_msat,
msgdata,openingd_got_offer,dust_limit_satoshis,amount_sat,
msgdata,openingd_got_offer,max_htlc_value_in_flight_msat,amount_msat,
msgdata,openingd_got_offer,channel_reserve_satoshis,amount_sat,
msgdata,openingd_got_offer,htlc_minimum_msat,amount_msat,
msgdata,openingd_got_offer,feerate_per_kw,u32,
msgdata,openingd_got_offer,to_self_delay,u16,
msgdata,openingd_got_offer,max_accepted_htlcs,u16,
msgdata,openingd_got_offer,channel_flags,u8,
msgdata,openingd_got_offer,shutdown_len,u16,
msgdata,openingd_got_offer,shutdown_scriptpubkey,u8,shutdown_len

# master->openingd: optional rejection message
msgtype,openingd_got_offer_reply,6105
msgdata,openingd_got_offer_reply,rejection,?wirestring,
msgdata,openingd_got_offer_reply,shutdown_len,u16,
msgdata,openingd_got_offer_reply,our_shutdown_scriptpubkey,?u8,shutdown_len
msgdata,openingd_got_offer_reply,our_shutdown_wallet_index,?u32,
msgdata,openingd_got_offer_reply,reserve,?amount_sat,

#include <common/penalty_base.h>
# Openingd->master: we've successfully offered channel.
# This gives their sig, means we can broadcast tx: we're done.
msgtype,openingd_funder_reply,6101
msgdata,openingd_funder_reply,their_config,channel_config,
msgdata,openingd_funder_reply,first_commit,bitcoin_tx,
msgdata,openingd_funder_reply,pbase,?penalty_base,
msgdata,openingd_funder_reply,first_commit_sig,bitcoin_signature,
msgdata,openingd_funder_reply,revocation_basepoint,pubkey,
msgdata,openingd_funder_reply,payment_basepoint,pubkey,
msgdata,openingd_funder_reply,htlc_basepoint,pubkey,
msgdata,openingd_funder_reply,delayed_payment_basepoint,pubkey,
msgdata,openingd_funder_reply,their_per_commit_point,pubkey,
msgdata,openingd_funder_reply,minimum_depth,u32,
msgdata,openingd_funder_reply,remote_fundingkey,pubkey,
msgdata,openingd_funder_reply,funding,bitcoin_outpoint,
msgdata,openingd_funder_reply,feerate_per_kw,u32,
msgdata,openingd_funder_reply,our_channel_reserve_satoshis,amount_sat,
msgdata,openingd_funder_reply,shutdown_len,u16,
msgdata,openingd_funder_reply,shutdown_scriptpubkey,u8,shutdown_len
msgdata,openingd_funder_reply,channel_type,channel_type,

# master->openingd: start channel establishment for a funding tx
msgtype,openingd_funder_start,6002
msgdata,openingd_funder_start,funding_satoshis,amount_sat,
msgdata,openingd_funder_start,push_msat,amount_msat,
msgdata,openingd_funder_start,len_upfront,u16,
msgdata,openingd_funder_start,upfront_shutdown_script,u8,len_upfront
msgdata,openingd_funder_start,upfront_shutdown_wallet_index,?u32,
msgdata,openingd_funder_start,feerate_per_kw,u32,
msgdata,openingd_funder_start,anchor_feerate_per_kw,u32,
msgdata,openingd_funder_start,temporary_channel_id,channel_id,
msgdata,openingd_funder_start,channel_flags,u8,
msgdata,openingd_funder_start,reserve,?amount_sat,

# openingd->master: send back output script for 2-of-2 funding output
msgtype,openingd_funder_start_reply,6102
msgdata,openingd_funder_start_reply,script_len,u8,
msgdata,openingd_funder_start_reply,scriptpubkey,u8,script_len
msgdata,openingd_funder_start_reply,upfront_shutdown_negotiated,bool,
msgdata,openingd_funder_start_reply,channel_type,channel_type,

# 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` ??
msgtype,openingd_funder_complete,6012
msgdata,openingd_funder_complete,funding_txid,bitcoin_txid,
msgdata,openingd_funder_complete,funding_txout,u16,
msgdata,openingd_funder_complete,channel_type,channel_type,

#master->openingd: cancel channel establishment for a funding
msgtype,openingd_funder_cancel,6013

# Openingd->master: we failed to negotiation channel
msgtype,openingd_failed,6004
msgdata,openingd_failed,reason,wirestring,

# Openingd->master: they offered channel.
# This gives their txid and info, means we can send funding_signed: we're done.
msgtype,openingd_fundee,6003
msgdata,openingd_fundee,their_config,channel_config,
msgdata,openingd_fundee,first_commit,bitcoin_tx,
msgdata,openingd_fundee,pbase,?penalty_base,
msgdata,openingd_fundee,first_commit_sig,bitcoin_signature,
msgdata,openingd_fundee,revocation_basepoint,pubkey,
msgdata,openingd_fundee,payment_basepoint,pubkey,
msgdata,openingd_fundee,htlc_basepoint,pubkey,
msgdata,openingd_fundee,delayed_payment_basepoint,pubkey,
msgdata,openingd_fundee,their_per_commit_point,pubkey,
msgdata,openingd_fundee,remote_fundingkey,pubkey,
msgdata,openingd_fundee,funding,bitcoin_outpoint,
msgdata,openingd_fundee,funding_satoshis,amount_sat,
msgdata,openingd_fundee,push_msat,amount_msat,
msgdata,openingd_fundee,channel_flags,u8,
msgdata,openingd_fundee,feerate_per_kw,u32,
# The funding signed message: send this and we're committed.
msgdata,openingd_fundee,msglen,u16,
msgdata,openingd_fundee,funding_signed_msg,u8,msglen
msgdata,openingd_fundee,our_channel_reserve_satoshis,amount_sat,
msgdata,openingd_fundee,local_shutdown_len,u16,
msgdata,openingd_fundee,local_shutdown_scriptpubkey,u8,local_shutdown_len
msgdata,openingd_fundee,remote_shutdown_len,u16,
msgdata,openingd_fundee,remote_shutdown_scriptpubkey,u8,remote_shutdown_len
msgdata,openingd_fundee,channel_type,channel_type,

# master -> openingd: do you have a memleak?
msgtype,openingd_dev_memleak,6033

msgtype,openingd_dev_memleak_reply,6133
msgdata,openingd_dev_memleak_reply,leak,bool,
