announcement_signatures.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package lnwire
  2. import (
  3. "bytes"
  4. "io"
  5. )
  6. // AnnounceSignatures is a direct message between two endpoints of a
  7. // channel and serves as an opt-in mechanism to allow the announcement of
  8. // the channel to the rest of the network. It contains the necessary
  9. // signatures by the sender to construct the channel announcement message.
  10. type AnnounceSignatures struct {
  11. // ChannelID is the unique description of the funding transaction.
  12. // Channel id is better for users and debugging and short channel id is
  13. // used for quick test on existence of the particular utxo inside the
  14. // block chain, because it contains information about block.
  15. ChannelID ChannelID
  16. // ShortChannelID is the unique description of the funding
  17. // transaction. It is constructed with the most significant 3 bytes
  18. // as the block height, the next 3 bytes indicating the transaction
  19. // index within the block, and the least significant two bytes
  20. // indicating the output index which pays to the channel.
  21. ShortChannelID ShortChannelID
  22. // NodeSignature is the signature which contains the signed announce
  23. // channel message, by this signature we proof that we possess of the
  24. // node pub key and creating the reference node_key -> bitcoin_key.
  25. NodeSignature Sig
  26. // BitcoinSignature is the signature which contains the signed node
  27. // public key, by this signature we proof that we possess of the
  28. // bitcoin key and and creating the reverse reference bitcoin_key ->
  29. // node_key.
  30. BitcoinSignature Sig
  31. // ExtraOpaqueData is the set of data that was appended to this
  32. // message, some of which we may not actually know how to iterate or
  33. // parse. By holding onto this data, we ensure that we're able to
  34. // properly validate the set of signatures that cover these new fields,
  35. // and ensure we're able to make upgrades to the network in a forwards
  36. // compatible manner.
  37. ExtraOpaqueData ExtraOpaqueData
  38. }
  39. // A compile time check to ensure AnnounceSignatures implements the
  40. // lnwire.Message interface.
  41. var _ Message = (*AnnounceSignatures)(nil)
  42. // Decode deserializes a serialized AnnounceSignatures stored in the passed
  43. // io.Reader observing the specified protocol version.
  44. //
  45. // This is part of the lnwire.Message interface.
  46. func (a *AnnounceSignatures) Decode(r io.Reader, pver uint32) error {
  47. return ReadElements(r,
  48. &a.ChannelID,
  49. &a.ShortChannelID,
  50. &a.NodeSignature,
  51. &a.BitcoinSignature,
  52. &a.ExtraOpaqueData,
  53. )
  54. }
  55. // Encode serializes the target AnnounceSignatures into the passed io.Writer
  56. // observing the protocol version specified.
  57. //
  58. // This is part of the lnwire.Message interface.
  59. func (a *AnnounceSignatures) Encode(w *bytes.Buffer, pver uint32) error {
  60. if err := WriteChannelID(w, a.ChannelID); err != nil {
  61. return err
  62. }
  63. if err := WriteShortChannelID(w, a.ShortChannelID); err != nil {
  64. return err
  65. }
  66. if err := WriteSig(w, a.NodeSignature); err != nil {
  67. return err
  68. }
  69. if err := WriteSig(w, a.BitcoinSignature); err != nil {
  70. return err
  71. }
  72. return WriteBytes(w, a.ExtraOpaqueData)
  73. }
  74. // MsgType returns the integer uniquely identifying this message type on the
  75. // wire.
  76. //
  77. // This is part of the lnwire.Message interface.
  78. func (a *AnnounceSignatures) MsgType() MessageType {
  79. return MsgAnnounceSignatures
  80. }