github.com/decred/dcrlnd@v0.7.6/lnwire/shutdown.go (about) 1 package lnwire 2 3 import ( 4 "bytes" 5 "io" 6 ) 7 8 // Shutdown is sent by either side in order to initiate the cooperative closure 9 // of a channel. This message is sparse as both sides implicitly have the 10 // information necessary to construct a transaction that will send the settled 11 // funds of both parties to the final delivery addresses negotiated during the 12 // funding workflow. 13 type Shutdown struct { 14 // ChannelID serves to identify which channel is to be closed. 15 ChannelID ChannelID 16 17 // Address is the script to which the channel funds will be paid. 18 Address DeliveryAddress 19 20 // ExtraData is the set of data that was appended to this message to 21 // fill out the full maximum transport message size. These fields can 22 // be used to specify optional data such as custom TLV fields. 23 ExtraData ExtraOpaqueData 24 } 25 26 // NewShutdown creates a new Shutdown message. 27 func NewShutdown(cid ChannelID, addr DeliveryAddress) *Shutdown { 28 return &Shutdown{ 29 ChannelID: cid, 30 Address: addr, 31 } 32 } 33 34 // A compile-time check to ensure Shutdown implements the lnwire.Message 35 // interface. 36 var _ Message = (*Shutdown)(nil) 37 38 // Decode deserializes a serialized Shutdown stored in the passed io.Reader 39 // observing the specified protocol version. 40 // 41 // This is part of the lnwire.Message interface. 42 func (s *Shutdown) Decode(r io.Reader, pver uint32) error { 43 return ReadElements(r, &s.ChannelID, &s.Address, &s.ExtraData) 44 } 45 46 // Encode serializes the target Shutdown into the passed io.Writer observing 47 // the protocol version specified. 48 // 49 // This is part of the lnwire.Message interface. 50 func (s *Shutdown) Encode(w *bytes.Buffer, pver uint32) error { 51 if err := WriteChannelID(w, s.ChannelID); err != nil { 52 return err 53 } 54 55 if err := WriteDeliveryAddress(w, s.Address); err != nil { 56 return err 57 } 58 59 return WriteBytes(w, s.ExtraData) 60 } 61 62 // MsgType returns the integer uniquely identifying this message type on the 63 // wire. 64 // 65 // This is part of the lnwire.Message interface. 66 func (s *Shutdown) MsgType() MessageType { 67 return MsgShutdown 68 }