github.com/decred/dcrlnd@v0.7.6/channeldb/migration/lnwire21/shutdown.go (about) 1 package lnwire 2 3 import ( 4 "io" 5 ) 6 7 // Shutdown is sent by either side in order to initiate the cooperative closure 8 // of a channel. This message is sparse as both sides implicitly have the 9 // information necessary to construct a transaction that will send the settled 10 // funds of both parties to the final delivery addresses negotiated during the 11 // funding workflow. 12 type Shutdown struct { 13 // ChannelID serves to identify which channel is to be closed. 14 ChannelID ChannelID 15 16 // Address is the script to which the channel funds will be paid. 17 Address DeliveryAddress 18 } 19 20 // DeliveryAddress is used to communicate the address to which funds from a 21 // closed channel should be sent. The address can be a p2wsh, p2pkh, p2sh or 22 // p2wpkh. 23 type DeliveryAddress []byte 24 25 // deliveryAddressMaxSize is the maximum expected size in bytes of a 26 // DeliveryAddress based on the types of scripts we know. 27 // Following are the known scripts and their sizes in bytes. 28 // - pay to witness script hash: 34 29 // - pay to pubkey hash: 25 30 // - pay to script hash: 22 31 // - pay to witness pubkey hash: 22. 32 const deliveryAddressMaxSize = 34 33 34 // NewShutdown creates a new Shutdown message. 35 func NewShutdown(cid ChannelID, addr DeliveryAddress) *Shutdown { 36 return &Shutdown{ 37 ChannelID: cid, 38 Address: addr, 39 } 40 } 41 42 // A compile-time check to ensure Shutdown implements the lnwire.Message 43 // interface. 44 var _ Message = (*Shutdown)(nil) 45 46 // Decode deserializes a serialized Shutdown stored in the passed io.Reader 47 // observing the specified protocol version. 48 // 49 // This is part of the lnwire.Message interface. 50 func (s *Shutdown) Decode(r io.Reader, pver uint32) error { 51 return ReadElements(r, &s.ChannelID, &s.Address) 52 } 53 54 // Encode serializes the target Shutdown into the passed io.Writer observing 55 // the protocol version specified. 56 // 57 // This is part of the lnwire.Message interface. 58 func (s *Shutdown) Encode(w io.Writer, pver uint32) error { 59 return WriteElements(w, s.ChannelID, s.Address) 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 } 69 70 // MaxPayloadLength returns the maximum allowed payload size for this message 71 // observing the specified protocol version. 72 // 73 // This is part of the lnwire.Message interface. 74 func (s *Shutdown) MaxPayloadLength(pver uint32) uint32 { 75 var length uint32 76 77 // ChannelID - 32bytes 78 length += 32 79 80 // Len - 2 bytes 81 length += 2 82 83 // ScriptPubKey - maximum delivery address size. 84 length += deliveryAddressMaxSize 85 86 return length 87 }