github.com/decred/dcrlnd@v0.7.6/channeldb/migration/lnwire21/closing_signed.go (about)

     1  package lnwire
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/decred/dcrd/dcrutil/v4"
     7  )
     8  
     9  // ClosingSigned is sent by both parties to a channel once the channel is clear
    10  // of HTLCs, and is primarily concerned with negotiating fees for the close
    11  // transaction. Each party provides a signature for a transaction with a fee
    12  // that they believe is fair. The process terminates when both sides agree on
    13  // the same fee, or when one side force closes the channel.
    14  //
    15  // NOTE: The responder is able to send a signature without any additional
    16  // messages as all transactions are assembled observing BIP 69 which defines a
    17  // canonical ordering for input/outputs. Therefore, both sides are able to
    18  // arrive at an identical closure transaction as they know the order of the
    19  // inputs/outputs.
    20  type ClosingSigned struct {
    21  	// ChannelID serves to identify which channel is to be closed.
    22  	ChannelID ChannelID
    23  
    24  	// FeeAtoms is the total fee in atoms that the party to the
    25  	// channel would like to propose for the close transaction.
    26  	FeeAtoms dcrutil.Amount
    27  
    28  	// Signature is for the proposed channel close transaction.
    29  	Signature Sig
    30  }
    31  
    32  // NewClosingSigned creates a new empty ClosingSigned message.
    33  func NewClosingSigned(cid ChannelID, fa dcrutil.Amount,
    34  	sig Sig) *ClosingSigned {
    35  
    36  	return &ClosingSigned{
    37  		ChannelID: cid,
    38  		FeeAtoms:  fa,
    39  		Signature: sig,
    40  	}
    41  }
    42  
    43  // A compile time check to ensure ClosingSigned implements the lnwire.Message
    44  // interface.
    45  var _ Message = (*ClosingSigned)(nil)
    46  
    47  // Decode deserializes a serialized ClosingSigned message stored in the passed
    48  // io.Reader observing the specified protocol version.
    49  //
    50  // This is part of the lnwire.Message interface.
    51  func (c *ClosingSigned) Decode(r io.Reader, pver uint32) error {
    52  	return ReadElements(r, &c.ChannelID, &c.FeeAtoms, &c.Signature)
    53  }
    54  
    55  // Encode serializes the target ClosingSigned into the passed io.Writer
    56  // observing the protocol version specified.
    57  //
    58  // This is part of the lnwire.Message interface.
    59  func (c *ClosingSigned) Encode(w io.Writer, pver uint32) error {
    60  	return WriteElements(w, c.ChannelID, c.FeeAtoms, c.Signature)
    61  }
    62  
    63  // MsgType returns the integer uniquely identifying this message type on the
    64  // wire.
    65  //
    66  // This is part of the lnwire.Message interface.
    67  func (c *ClosingSigned) MsgType() MessageType {
    68  	return MsgClosingSigned
    69  }
    70  
    71  // MaxPayloadLength returns the maximum allowed payload size for a
    72  // ClosingSigned complete message observing the specified protocol version.
    73  //
    74  // This is part of the lnwire.Message interface.
    75  func (c *ClosingSigned) MaxPayloadLength(uint32) uint32 {
    76  	var length uint32
    77  
    78  	// ChannelID - 32 bytes
    79  	length += 32
    80  
    81  	// FeeAtoms - 8 bytes
    82  	length += 8
    83  
    84  	// Signature - 64 bytes
    85  	length += 64
    86  
    87  	return length
    88  }