github.com/decred/dcrlnd@v0.7.6/channeldb/migration/lnwire21/announcement_signatures.go (about) 1 package lnwire 2 3 import ( 4 "io" 5 "io/ioutil" 6 ) 7 8 // AnnounceSignatures is a direct message between two endpoints of a 9 // channel and serves as an opt-in mechanism to allow the announcement of 10 // the channel to the rest of the network. It contains the necessary 11 // signatures by the sender to construct the channel announcement message. 12 type AnnounceSignatures struct { 13 // ChannelID is the unique description of the funding transaction. 14 // Channel id is better for users and debugging and short channel id is 15 // used for quick test on existence of the particular utxo inside the 16 // block chain, because it contains information about block. 17 ChannelID ChannelID 18 19 // ShortChannelID is the unique description of the funding 20 // transaction. It is constructed with the most significant 3 bytes 21 // as the block height, the next 3 bytes indicating the transaction 22 // index within the block, and the least significant two bytes 23 // indicating the output index which pays to the channel. 24 ShortChannelID ShortChannelID 25 26 // NodeSignature is the signature which contains the signed announce 27 // channel message, by this signature we proof that we possess of the 28 // node pub key and creating the reference node_key -> decred_key. 29 NodeSignature Sig 30 31 // DecredSignature is the signature which contains the signed node 32 // public key, by this signature we proof that we possess of the 33 // bitcoin key and and creating the reverse reference decred_key -> 34 // node_key. 35 DecredSignature Sig 36 37 // ExtraOpaqueData is the set of data that was appended to this 38 // message, some of which we may not actually know how to iterate or 39 // parse. By holding onto this data, we ensure that we're able to 40 // properly validate the set of signatures that cover these new fields, 41 // and ensure we're able to make upgrades to the network in a forwards 42 // compatible manner. 43 ExtraOpaqueData []byte 44 } 45 46 // A compile time check to ensure AnnounceSignatures implements the 47 // lnwire.Message interface. 48 var _ Message = (*AnnounceSignatures)(nil) 49 50 // Decode deserializes a serialized AnnounceSignatures stored in the passed 51 // io.Reader observing the specified protocol version. 52 // 53 // This is part of the lnwire.Message interface. 54 func (a *AnnounceSignatures) Decode(r io.Reader, pver uint32) error { 55 err := ReadElements(r, 56 &a.ChannelID, 57 &a.ShortChannelID, 58 &a.NodeSignature, 59 &a.DecredSignature, 60 ) 61 if err != nil { 62 return err 63 } 64 65 // Now that we've read out all the fields that we explicitly know of, 66 // we'll collect the remainder into the ExtraOpaqueData field. If there 67 // aren't any bytes, then we'll snip off the slice to avoid carrying 68 // around excess capacity. 69 a.ExtraOpaqueData, err = ioutil.ReadAll(r) 70 if err != nil { 71 return err 72 } 73 if len(a.ExtraOpaqueData) == 0 { 74 a.ExtraOpaqueData = nil 75 } 76 77 return nil 78 } 79 80 // Encode serializes the target AnnounceSignatures into the passed io.Writer 81 // observing the protocol version specified. 82 // 83 // This is part of the lnwire.Message interface. 84 func (a *AnnounceSignatures) Encode(w io.Writer, pver uint32) error { 85 return WriteElements(w, 86 a.ChannelID, 87 a.ShortChannelID, 88 a.NodeSignature, 89 a.DecredSignature, 90 a.ExtraOpaqueData, 91 ) 92 } 93 94 // MsgType returns the integer uniquely identifying this message type on the 95 // wire. 96 // 97 // This is part of the lnwire.Message interface. 98 func (a *AnnounceSignatures) MsgType() MessageType { 99 return MsgAnnounceSignatures 100 } 101 102 // MaxPayloadLength returns the maximum allowed payload size for this message 103 // observing the specified protocol version. 104 // 105 // This is part of the lnwire.Message interface. 106 func (a *AnnounceSignatures) MaxPayloadLength(pver uint32) uint32 { 107 return 65533 108 }