github.com/decred/dcrlnd@v0.7.6/lnwire/funding_locked.go (about)

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