2017-01-31 05:45:28 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2018-06-05 04:34:16 +03:00
|
|
|
"github.com/btcsuite/btcd/btcec"
|
2017-01-31 05:45:28 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// FundingLocked is the message that both parties to a new channel creation
|
2017-04-17 01:22:20 +03: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 05:45:28 +03:00
|
|
|
type FundingLocked struct {
|
2017-04-17 01:22:20 +03: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 05:45:28 +03:00
|
|
|
|
2017-04-17 01:22:20 +03:00
|
|
|
// NextPerCommitmentPoint is the secret that can be used to revoke the
|
|
|
|
// next commitment transaction for the channel.
|
2017-01-31 05:45:28 +03:00
|
|
|
NextPerCommitmentPoint *btcec.PublicKey
|
|
|
|
}
|
|
|
|
|
2017-04-17 01:22:20 +03: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 05:45:28 +03:00
|
|
|
return &FundingLocked{
|
2017-04-17 01:22:20 +03:00
|
|
|
ChanID: cid,
|
2017-01-31 05:45:28 +03:00
|
|
|
NextPerCommitmentPoint: npcp,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-17 01:22:20 +03:00
|
|
|
// A compile time check to ensure FundingLocked implements the lnwire.Message
|
|
|
|
// interface.
|
2017-01-31 05:45:28 +03:00
|
|
|
var _ Message = (*FundingLocked)(nil)
|
|
|
|
|
2017-04-17 01:22:20 +03:00
|
|
|
// Decode deserializes the serialized FundingLocked message stored in the
|
|
|
|
// passed io.Reader into the target FundingLocked using the deserialization
|
2017-01-31 05:45:28 +03: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 {
|
2017-03-09 07:44:32 +03:00
|
|
|
return readElements(r,
|
2017-04-17 01:22:20 +03:00
|
|
|
&c.ChanID,
|
2017-01-31 05:45:28 +03:00
|
|
|
&c.NextPerCommitmentPoint)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
func (c *FundingLocked) Encode(w io.Writer, pver uint32) error {
|
2017-03-09 07:44:32 +03:00
|
|
|
return writeElements(w,
|
2017-04-17 01:22:20 +03:00
|
|
|
c.ChanID,
|
2017-01-31 05:45:28 +03:00
|
|
|
c.NextPerCommitmentPoint)
|
|
|
|
}
|
|
|
|
|
2017-04-20 01:57:43 +03:00
|
|
|
// MsgType returns the uint32 code which uniquely identifies this message as a
|
2017-01-31 05:45:28 +03:00
|
|
|
// FundingLocked message on the wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-20 01:57:43 +03:00
|
|
|
func (c *FundingLocked) MsgType() MessageType {
|
|
|
|
return MsgFundingLocked
|
2017-01-31 05:45:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// MaxPayloadLength returns the maximum allowed payload length for a
|
|
|
|
// FundingLocked message. This is calculated by summing the max length of all
|
|
|
|
// the fields within a FundingLocked message.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *FundingLocked) MaxPayloadLength(uint32) uint32 {
|
|
|
|
var length uint32
|
|
|
|
|
2017-04-17 01:22:20 +03:00
|
|
|
// ChanID - 32 bytes
|
|
|
|
length += 32
|
2017-01-31 05:45:28 +03:00
|
|
|
|
|
|
|
// NextPerCommitmentPoint - 33 bytes
|
|
|
|
length += 33
|
|
|
|
|
2017-04-17 01:22:20 +03:00
|
|
|
// 65 bytes
|
2017-01-31 05:45:28 +03:00
|
|
|
return length
|
|
|
|
}
|