2016-12-07 18:46:22 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2016-12-22 23:24:48 +03:00
|
|
|
"io"
|
|
|
|
|
2016-12-07 18:46:22 +03:00
|
|
|
"github.com/roasbeef/btcd/btcec"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ChannelAnnouncement message is used to announce the existence of a channel
|
|
|
|
// between two peers in the overlay, which is propagated by the discovery
|
|
|
|
// service over broadcast handler.
|
|
|
|
type ChannelAnnouncement struct {
|
|
|
|
// This signatures are used by nodes in order to create cross
|
|
|
|
// references between node's channel and node. Requiring both nodes
|
|
|
|
// to sign indicates they are both willing to route other payments via
|
|
|
|
// this node.
|
2017-03-27 18:22:37 +03:00
|
|
|
NodeSig1 *btcec.Signature
|
|
|
|
NodeSig2 *btcec.Signature
|
2016-12-07 18:46:22 +03:00
|
|
|
|
|
|
|
// This signatures are used by nodes in order to create cross
|
|
|
|
// references between node's channel and node. Requiring the bitcoin
|
|
|
|
// signatures proves they control the channel.
|
2017-03-27 18:22:37 +03:00
|
|
|
BitcoinSig1 *btcec.Signature
|
|
|
|
BitcoinSig2 *btcec.Signature
|
|
|
|
|
|
|
|
// ShortChannelID is the unique description of the funding transaction.
|
|
|
|
ShortChannelID ShortChannelID
|
2016-12-07 18:46:22 +03:00
|
|
|
|
|
|
|
// The public keys of the two nodes who are operating the channel, such
|
2017-03-27 18:22:37 +03:00
|
|
|
// that is NodeID1 the numerically-lesser than NodeID2 (ascending
|
|
|
|
// numerical order).
|
|
|
|
NodeID1 *btcec.PublicKey
|
|
|
|
NodeID2 *btcec.PublicKey
|
2016-12-07 18:46:22 +03:00
|
|
|
|
|
|
|
// Public keys which corresponds to the keys which was declared in
|
|
|
|
// multisig funding transaction output.
|
2017-03-27 18:22:37 +03:00
|
|
|
BitcoinKey1 *btcec.PublicKey
|
|
|
|
BitcoinKey2 *btcec.PublicKey
|
2016-12-07 18:46:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time check to ensure ChannelAnnouncement implements the
|
|
|
|
// lnwire.Message interface.
|
|
|
|
var _ Message = (*ChannelAnnouncement)(nil)
|
|
|
|
|
|
|
|
// Decode deserializes a serialized ChannelAnnouncement stored in the passed
|
|
|
|
// io.Reader observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-02-23 22:56:47 +03:00
|
|
|
func (a *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error {
|
2017-02-23 21:59:50 +03:00
|
|
|
return readElements(r,
|
2017-03-27 18:22:37 +03:00
|
|
|
&a.NodeSig1,
|
|
|
|
&a.NodeSig2,
|
|
|
|
&a.ShortChannelID,
|
|
|
|
&a.BitcoinSig1,
|
|
|
|
&a.BitcoinSig2,
|
|
|
|
&a.NodeID1,
|
|
|
|
&a.NodeID2,
|
|
|
|
&a.BitcoinKey1,
|
|
|
|
&a.BitcoinKey2,
|
2016-12-07 18:46:22 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode serializes the target ChannelAnnouncement into the passed io.Writer
|
|
|
|
// observing the protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-02-23 22:56:47 +03:00
|
|
|
func (a *ChannelAnnouncement) Encode(w io.Writer, pver uint32) error {
|
2017-02-23 21:59:50 +03:00
|
|
|
return writeElements(w,
|
2017-03-27 18:22:37 +03:00
|
|
|
a.NodeSig1,
|
|
|
|
a.NodeSig2,
|
|
|
|
a.ShortChannelID,
|
|
|
|
a.BitcoinSig1,
|
|
|
|
a.BitcoinSig2,
|
|
|
|
a.NodeID1,
|
|
|
|
a.NodeID2,
|
|
|
|
a.BitcoinKey1,
|
|
|
|
a.BitcoinKey2,
|
2016-12-07 18:46:22 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-04-20 01:57:43 +03:00
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
2016-12-07 18:46:22 +03:00
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-20 01:57:43 +03:00
|
|
|
func (a *ChannelAnnouncement) MsgType() MessageType {
|
|
|
|
return MsgChannelAnnouncement
|
2016-12-07 18:46:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// MaxPayloadLength returns the maximum allowed payload size for this message
|
|
|
|
// observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-02-23 22:56:47 +03:00
|
|
|
func (a *ChannelAnnouncement) MaxPayloadLength(pver uint32) uint32 {
|
2016-12-07 18:46:22 +03:00
|
|
|
var length uint32
|
|
|
|
|
2017-03-27 18:22:37 +03:00
|
|
|
// NodeSig1 - 64 bytes
|
2016-12-07 18:46:22 +03:00
|
|
|
length += 64
|
|
|
|
|
2017-03-27 18:22:37 +03:00
|
|
|
// NodeSig2 - 64 bytes
|
2016-12-07 18:46:22 +03:00
|
|
|
length += 64
|
|
|
|
|
2017-03-27 18:22:37 +03:00
|
|
|
// ShortChannelID - 8 bytes
|
2016-12-07 18:46:22 +03:00
|
|
|
length += 8
|
|
|
|
|
2017-03-27 18:22:37 +03:00
|
|
|
// BitcoinSig1 - 64 bytes
|
2016-12-07 18:46:22 +03:00
|
|
|
length += 64
|
|
|
|
|
2017-03-27 18:22:37 +03:00
|
|
|
// BitcoinSig2 - 64 bytes
|
2016-12-07 18:46:22 +03:00
|
|
|
length += 64
|
|
|
|
|
2017-03-27 18:22:37 +03:00
|
|
|
// NodeID1 - 33 bytes
|
2016-12-07 18:46:22 +03:00
|
|
|
length += 33
|
|
|
|
|
2017-03-27 18:22:37 +03:00
|
|
|
// NodeID2 - 33 bytes
|
2016-12-07 18:46:22 +03:00
|
|
|
length += 33
|
|
|
|
|
2017-03-27 18:22:37 +03:00
|
|
|
// BitcoinKey1 - 33 bytes
|
2016-12-07 18:46:22 +03:00
|
|
|
length += 33
|
|
|
|
|
2017-03-27 18:22:37 +03:00
|
|
|
// BitcoinKey2 - 33 bytes
|
2016-12-07 18:46:22 +03:00
|
|
|
length += 33
|
|
|
|
|
|
|
|
return length
|
|
|
|
}
|
|
|
|
|
|
|
|
// DataToSign is used to retrieve part of the announcement message which
|
|
|
|
// should be signed.
|
2017-02-23 22:56:47 +03:00
|
|
|
func (a *ChannelAnnouncement) DataToSign() ([]byte, error) {
|
2016-12-07 18:46:22 +03:00
|
|
|
// We should not include the signatures itself.
|
|
|
|
var w bytes.Buffer
|
|
|
|
err := writeElements(&w,
|
2017-03-27 18:22:37 +03:00
|
|
|
a.ShortChannelID,
|
|
|
|
a.NodeID1,
|
|
|
|
a.NodeID2,
|
|
|
|
a.BitcoinKey1,
|
|
|
|
a.BitcoinKey2,
|
2016-12-07 18:46:22 +03:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return w.Bytes(), nil
|
|
|
|
}
|