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