2017-03-09 02:32:11 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2018-06-05 04:34:16 +03:00
|
|
|
"github.com/btcsuite/btcutil"
|
2017-03-09 02:32:11 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// ClosingSigned is sent by both parties to a channel once the channel is clear
|
|
|
|
// of HTLCs, and is primarily concerned with negotiating fees for the close
|
|
|
|
// transaction. Each party provides a signature for a transaction with a fee
|
|
|
|
// that they believe is fair. The process terminates when both sides agree on
|
|
|
|
// the same fee, or when one side force closes the channel.
|
|
|
|
//
|
|
|
|
// NOTE: The responder is able to send a signature without any additional
|
|
|
|
// messages as all transactions are assembled observing BIP 69 which defines a
|
2017-12-18 05:40:05 +03:00
|
|
|
// canonical ordering for input/outputs. Therefore, both sides are able to
|
2017-03-09 02:32:11 +03:00
|
|
|
// arrive at an identical closure transaction as they know the order of the
|
|
|
|
// inputs/outputs.
|
|
|
|
type ClosingSigned struct {
|
|
|
|
// ChannelID serves to identify which channel is to be closed.
|
|
|
|
ChannelID ChannelID
|
|
|
|
|
2017-11-23 09:27:26 +03:00
|
|
|
// FeeSatoshis is the total fee in satoshis that the party to the
|
|
|
|
// channel would like to propose for the close transaction.
|
|
|
|
FeeSatoshis btcutil.Amount
|
2017-03-09 02:32:11 +03:00
|
|
|
|
|
|
|
// Signature is for the proposed channel close transaction.
|
2018-01-31 06:41:52 +03:00
|
|
|
Signature Sig
|
2020-01-28 04:25:36 +03:00
|
|
|
|
|
|
|
// ExtraData is the set of data that was appended to this message to
|
|
|
|
// fill out the full maximum transport message size. These fields can
|
|
|
|
// be used to specify optional data such as custom TLV fields.
|
|
|
|
ExtraData ExtraOpaqueData
|
2017-03-09 02:32:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewClosingSigned creates a new empty ClosingSigned message.
|
2017-11-23 09:27:26 +03:00
|
|
|
func NewClosingSigned(cid ChannelID, fs btcutil.Amount,
|
2018-01-31 06:41:52 +03:00
|
|
|
sig Sig) *ClosingSigned {
|
2017-03-09 02:32:11 +03:00
|
|
|
|
|
|
|
return &ClosingSigned{
|
|
|
|
ChannelID: cid,
|
|
|
|
FeeSatoshis: fs,
|
|
|
|
Signature: sig,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time check to ensure ClosingSigned implements the lnwire.Message
|
|
|
|
// interface.
|
|
|
|
var _ Message = (*ClosingSigned)(nil)
|
|
|
|
|
|
|
|
// Decode deserializes a serialized ClosingSigned message stored in the passed
|
|
|
|
// io.Reader observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *ClosingSigned) Decode(r io.Reader, pver uint32) error {
|
2020-01-28 04:25:36 +03:00
|
|
|
return ReadElements(
|
|
|
|
r, &c.ChannelID, &c.FeeSatoshis, &c.Signature, &c.ExtraData,
|
|
|
|
)
|
2017-03-09 02:32:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Encode serializes the target ClosingSigned into the passed io.Writer
|
|
|
|
// observing the protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *ClosingSigned) Encode(w io.Writer, pver uint32) error {
|
2020-01-28 04:25:36 +03:00
|
|
|
return WriteElements(
|
|
|
|
w, c.ChannelID, c.FeeSatoshis, c.Signature, c.ExtraData,
|
|
|
|
)
|
2017-03-09 02:32:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *ClosingSigned) MsgType() MessageType {
|
|
|
|
return MsgClosingSigned
|
|
|
|
}
|