2017-03-27 17:07:18 +02:00
|
|
|
package lnwire
|
|
|
|
|
2018-09-01 04:33:05 +02:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
)
|
2017-03-27 17:07:18 +02:00
|
|
|
|
2020-11-25 22:12:29 +01:00
|
|
|
// AnnounceSignatures is a direct message between two endpoints of a
|
2017-03-27 17:07:18 +02:00
|
|
|
// channel and serves as an opt-in mechanism to allow the announcement of
|
|
|
|
// the channel to the rest of the network. It contains the necessary
|
|
|
|
// signatures by the sender to construct the channel announcement message.
|
|
|
|
type AnnounceSignatures struct {
|
|
|
|
// ChannelID is the unique description of the funding transaction.
|
|
|
|
// Channel id is better for users and debugging and short channel id is
|
|
|
|
// used for quick test on existence of the particular utxo inside the
|
|
|
|
// block chain, because it contains information about block.
|
2017-04-17 00:22:20 +02:00
|
|
|
ChannelID ChannelID
|
2017-03-27 17:07:18 +02:00
|
|
|
|
|
|
|
// ShortChannelID is the unique description of the funding
|
|
|
|
// transaction. It is constructed with the most significant 3 bytes
|
|
|
|
// as the block height, the next 3 bytes indicating the transaction
|
|
|
|
// index within the block, and the least significant two bytes
|
|
|
|
// indicating the output index which pays to the channel.
|
2017-03-27 17:22:37 +02:00
|
|
|
ShortChannelID ShortChannelID
|
2017-03-27 17:07:18 +02:00
|
|
|
|
|
|
|
// NodeSignature is the signature which contains the signed announce
|
2017-12-18 03:40:05 +01:00
|
|
|
// channel message, by this signature we proof that we possess of the
|
2017-03-27 17:07:18 +02:00
|
|
|
// node pub key and creating the reference node_key -> bitcoin_key.
|
2018-01-31 04:41:52 +01:00
|
|
|
NodeSignature Sig
|
2017-03-27 17:07:18 +02:00
|
|
|
|
|
|
|
// BitcoinSignature is the signature which contains the signed node
|
2017-12-18 03:40:05 +01:00
|
|
|
// public key, by this signature we proof that we possess of the
|
2017-03-27 17:07:18 +02:00
|
|
|
// bitcoin key and and creating the reverse reference bitcoin_key ->
|
|
|
|
// node_key.
|
2018-01-31 04:41:52 +01:00
|
|
|
BitcoinSignature Sig
|
2018-09-01 04:33:05 +02:00
|
|
|
|
|
|
|
// ExtraOpaqueData is the set of data that was appended to this
|
|
|
|
// message, some of which we may not actually know how to iterate or
|
|
|
|
// parse. By holding onto this data, we ensure that we're able to
|
|
|
|
// properly validate the set of signatures that cover these new fields,
|
|
|
|
// and ensure we're able to make upgrades to the network in a forwards
|
|
|
|
// compatible manner.
|
|
|
|
ExtraOpaqueData []byte
|
2017-03-27 17:07:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time check to ensure AnnounceSignatures implements the
|
|
|
|
// lnwire.Message interface.
|
|
|
|
var _ Message = (*AnnounceSignatures)(nil)
|
|
|
|
|
|
|
|
// Decode deserializes a serialized AnnounceSignatures stored in the passed
|
|
|
|
// io.Reader observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (a *AnnounceSignatures) Decode(r io.Reader, pver uint32) error {
|
2018-12-10 03:27:41 +01:00
|
|
|
err := ReadElements(r,
|
2017-03-27 17:07:18 +02:00
|
|
|
&a.ChannelID,
|
|
|
|
&a.ShortChannelID,
|
|
|
|
&a.NodeSignature,
|
|
|
|
&a.BitcoinSignature,
|
|
|
|
)
|
2018-09-01 04:33:05 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now that we've read out all the fields that we explicitly know of,
|
|
|
|
// we'll collect the remainder into the ExtraOpaqueData field. If there
|
|
|
|
// aren't any bytes, then we'll snip off the slice to avoid carrying
|
|
|
|
// around excess capacity.
|
|
|
|
a.ExtraOpaqueData, err = ioutil.ReadAll(r)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(a.ExtraOpaqueData) == 0 {
|
|
|
|
a.ExtraOpaqueData = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2017-03-27 17:07:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Encode serializes the target AnnounceSignatures into the passed io.Writer
|
|
|
|
// observing the protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (a *AnnounceSignatures) Encode(w io.Writer, pver uint32) error {
|
2018-12-10 03:27:41 +01:00
|
|
|
return WriteElements(w,
|
2017-03-27 17:07:18 +02:00
|
|
|
a.ChannelID,
|
|
|
|
a.ShortChannelID,
|
|
|
|
a.NodeSignature,
|
|
|
|
a.BitcoinSignature,
|
2018-09-01 04:33:05 +02:00
|
|
|
a.ExtraOpaqueData,
|
2017-03-27 17:07:18 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:57:43 +02:00
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
2017-03-27 17:07:18 +02:00
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-20 00:57:43 +02:00
|
|
|
func (a *AnnounceSignatures) MsgType() MessageType {
|
|
|
|
return MsgAnnounceSignatures
|
2017-03-27 17:07:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// MaxPayloadLength returns the maximum allowed payload size for this message
|
|
|
|
// observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (a *AnnounceSignatures) MaxPayloadLength(pver uint32) uint32 {
|
2018-09-01 04:33:05 +02:00
|
|
|
return 65533
|
2017-03-27 17:07:18 +02:00
|
|
|
}
|