github.com/decred/dcrlnd@v0.7.6/channeldb/migration/lnwire21/funding_locked.go (about)

     1  package lnwire
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/decred/dcrd/dcrec/secp256k1/v4"
     7  )
     8  
     9  // FundingLocked is the message that both parties to a new channel creation
    10  // send once they have observed the funding transaction being confirmed on the
    11  // blockchain. FundingLocked contains the signatures necessary for the channel
    12  // participants to advertise the existence of the channel to the rest of the
    13  // network.
    14  type FundingLocked struct {
    15  	// ChanID is the outpoint of the channel's funding transaction. This
    16  	// can be used to query for the channel in the database.
    17  	ChanID ChannelID
    18  
    19  	// NextPerCommitmentPoint is the secret that can be used to revoke the
    20  	// next commitment transaction for the channel.
    21  	NextPerCommitmentPoint *secp256k1.PublicKey
    22  }
    23  
    24  // NewFundingLocked creates a new FundingLocked message, populating it with the
    25  // necessary IDs and revocation secret.
    26  func NewFundingLocked(cid ChannelID, npcp *secp256k1.PublicKey) *FundingLocked {
    27  	return &FundingLocked{
    28  		ChanID:                 cid,
    29  		NextPerCommitmentPoint: npcp,
    30  	}
    31  }
    32  
    33  // A compile time check to ensure FundingLocked implements the lnwire.Message
    34  // interface.
    35  var _ Message = (*FundingLocked)(nil)
    36  
    37  // Decode deserializes the serialized FundingLocked message stored in the
    38  // passed io.Reader into the target FundingLocked using the deserialization
    39  // rules defined by the passed protocol version.
    40  //
    41  // This is part of the lnwire.Message interface.
    42  func (c *FundingLocked) Decode(r io.Reader, pver uint32) error {
    43  	return ReadElements(r,
    44  		&c.ChanID,
    45  		&c.NextPerCommitmentPoint)
    46  }
    47  
    48  // Encode serializes the target FundingLocked message into the passed io.Writer
    49  // implementation. Serialization will observe the rules defined by the passed
    50  // protocol version.
    51  //
    52  // This is part of the lnwire.Message interface.
    53  func (c *FundingLocked) Encode(w io.Writer, pver uint32) error {
    54  	return WriteElements(w,
    55  		c.ChanID,
    56  		c.NextPerCommitmentPoint)
    57  }
    58  
    59  // MsgType returns the uint32 code which uniquely identifies this message as a
    60  // FundingLocked message on the wire.
    61  //
    62  // This is part of the lnwire.Message interface.
    63  func (c *FundingLocked) MsgType() MessageType {
    64  	return MsgFundingLocked
    65  }
    66  
    67  // MaxPayloadLength returns the maximum allowed payload length for a
    68  // FundingLocked message. This is calculated by summing the max length of all
    69  // the fields within a FundingLocked message.
    70  //
    71  // This is part of the lnwire.Message interface.
    72  func (c *FundingLocked) MaxPayloadLength(uint32) uint32 {
    73  	var length uint32
    74  
    75  	// ChanID - 32 bytes
    76  	length += 32
    77  
    78  	// NextPerCommitmentPoint - 33 bytes
    79  	length += 33
    80  
    81  	// 65 bytes
    82  	return length
    83  }