2017-01-31 03:45:28 +01:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
2021-06-17 08:17:30 +02:00
|
|
|
"bytes"
|
2017-01-31 03:45:28 +01:00
|
|
|
"io"
|
|
|
|
|
2022-02-23 14:48:00 +01:00
|
|
|
"github.com/btcsuite/btcd/btcec/v2"
|
2017-01-31 03:45:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// FundingLocked is the message that both parties to a new channel creation
|
2017-04-17 00:22:20 +02:00
|
|
|
// send once they have observed the funding transaction being confirmed on the
|
|
|
|
// blockchain. FundingLocked contains the signatures necessary for the channel
|
|
|
|
// participants to advertise the existence of the channel to the rest of the
|
|
|
|
// network.
|
2017-01-31 03:45:28 +01:00
|
|
|
type FundingLocked struct {
|
2017-04-17 00:22:20 +02:00
|
|
|
// ChanID is the outpoint of the channel's funding transaction. This
|
|
|
|
// can be used to query for the channel in the database.
|
|
|
|
ChanID ChannelID
|
2017-01-31 03:45:28 +01:00
|
|
|
|
2017-04-17 00:22:20 +02:00
|
|
|
// NextPerCommitmentPoint is the secret that can be used to revoke the
|
|
|
|
// next commitment transaction for the channel.
|
2017-01-31 03:45:28 +01:00
|
|
|
NextPerCommitmentPoint *btcec.PublicKey
|
2020-01-28 02:25:36 +01:00
|
|
|
|
|
|
|
// ExtraData is the set of data that was appended to this message to
|
|
|
|
// fill out the full maximum transport message size. These fields can
|
|
|
|
// be used to specify optional data such as custom TLV fields.
|
|
|
|
ExtraData ExtraOpaqueData
|
2017-01-31 03:45:28 +01:00
|
|
|
}
|
|
|
|
|
2017-04-17 00:22:20 +02:00
|
|
|
// NewFundingLocked creates a new FundingLocked message, populating it with the
|
|
|
|
// necessary IDs and revocation secret.
|
|
|
|
func NewFundingLocked(cid ChannelID, npcp *btcec.PublicKey) *FundingLocked {
|
2017-01-31 03:45:28 +01:00
|
|
|
return &FundingLocked{
|
2017-04-17 00:22:20 +02:00
|
|
|
ChanID: cid,
|
2017-01-31 03:45:28 +01:00
|
|
|
NextPerCommitmentPoint: npcp,
|
2020-01-28 02:25:36 +01:00
|
|
|
ExtraData: make([]byte, 0),
|
2017-01-31 03:45:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-17 00:22:20 +02:00
|
|
|
// A compile time check to ensure FundingLocked implements the lnwire.Message
|
|
|
|
// interface.
|
2017-01-31 03:45:28 +01:00
|
|
|
var _ Message = (*FundingLocked)(nil)
|
|
|
|
|
2017-04-17 00:22:20 +02:00
|
|
|
// Decode deserializes the serialized FundingLocked message stored in the
|
|
|
|
// passed io.Reader into the target FundingLocked using the deserialization
|
2017-01-31 03:45:28 +01:00
|
|
|
// rules defined by the passed protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *FundingLocked) Decode(r io.Reader, pver uint32) error {
|
2018-12-10 03:27:41 +01:00
|
|
|
return ReadElements(r,
|
2017-04-17 00:22:20 +02:00
|
|
|
&c.ChanID,
|
2020-01-28 02:25:36 +01:00
|
|
|
&c.NextPerCommitmentPoint,
|
|
|
|
&c.ExtraData,
|
|
|
|
)
|
2017-01-31 03:45:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Encode serializes the target FundingLocked message into the passed io.Writer
|
|
|
|
// implementation. Serialization will observe the rules defined by the passed
|
|
|
|
// protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2021-06-17 08:17:30 +02:00
|
|
|
func (c *FundingLocked) Encode(w *bytes.Buffer, pver uint32) error {
|
2021-06-18 09:03:43 +02:00
|
|
|
if err := WriteChannelID(w, c.ChanID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WritePublicKey(w, c.NextPerCommitmentPoint); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return WriteBytes(w, c.ExtraData)
|
2017-01-31 03:45:28 +01:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:57:43 +02:00
|
|
|
// MsgType returns the uint32 code which uniquely identifies this message as a
|
2017-01-31 03:45:28 +01:00
|
|
|
// FundingLocked message on the wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-20 00:57:43 +02:00
|
|
|
func (c *FundingLocked) MsgType() MessageType {
|
|
|
|
return MsgFundingLocked
|
2017-01-31 03:45:28 +01:00
|
|
|
}
|