2017-07-29 01:24:34 +02:00
|
|
|
package lnwire
|
|
|
|
|
2021-06-17 08:17:30 +02:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
2023-01-17 04:40:03 +01:00
|
|
|
|
|
|
|
"github.com/lightningnetwork/lnd/tlv"
|
2021-06-17 08:17:30 +02:00
|
|
|
)
|
2017-07-29 01:24:34 +02:00
|
|
|
|
|
|
|
// FundingSigned is sent from Bob (the responder) to Alice (the initiator)
|
|
|
|
// after receiving the funding outpoint and her signature for Bob's version of
|
|
|
|
// the commitment transaction.
|
|
|
|
type FundingSigned struct {
|
|
|
|
// ChannelPoint is the particular active channel that this
|
|
|
|
// FundingSigned is bound to.
|
|
|
|
ChanID ChannelID
|
|
|
|
|
|
|
|
// CommitSig is Bob's signature for Alice's version of the commitment
|
|
|
|
// transaction.
|
2018-01-31 04:41:52 +01:00
|
|
|
CommitSig Sig
|
2020-01-28 02:25:36 +01:00
|
|
|
|
2023-01-17 04:40:03 +01:00
|
|
|
// PartialSig is used to transmit a musig2 extended partial signature
|
|
|
|
// that also carries along the public nonce of the signer.
|
|
|
|
//
|
|
|
|
// NOTE: This field is only populated if a musig2 taproot channel is
|
|
|
|
// being signed for. In this case, the above Sig type MUST be blank.
|
|
|
|
PartialSig *PartialSigWithNonce
|
|
|
|
|
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-07-29 01:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time check to ensure FundingSigned implements the lnwire.Message
|
|
|
|
// interface.
|
|
|
|
var _ Message = (*FundingSigned)(nil)
|
|
|
|
|
|
|
|
// Encode serializes the target FundingSigned 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 (f *FundingSigned) Encode(w *bytes.Buffer, pver uint32) error {
|
2023-01-17 04:40:03 +01:00
|
|
|
recordProducers := make([]tlv.RecordProducer, 0, 1)
|
|
|
|
if f.PartialSig != nil {
|
|
|
|
recordProducers = append(recordProducers, f.PartialSig)
|
|
|
|
}
|
|
|
|
err := EncodeMessageExtraData(&f.ExtraData, recordProducers...)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-06-18 09:03:43 +02:00
|
|
|
if err := WriteChannelID(w, f.ChanID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteSig(w, f.CommitSig); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return WriteBytes(w, f.ExtraData)
|
2017-07-29 01:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Decode deserializes the serialized FundingSigned stored in the passed
|
|
|
|
// io.Reader into the target FundingSigned using the deserialization rules
|
|
|
|
// defined by the passed protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (f *FundingSigned) Decode(r io.Reader, pver uint32) error {
|
2023-01-17 04:40:03 +01:00
|
|
|
err := ReadElements(r, &f.ChanID, &f.CommitSig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var tlvRecords ExtraOpaqueData
|
|
|
|
if err := ReadElements(r, &tlvRecords); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
partialSig PartialSigWithNonce
|
|
|
|
)
|
|
|
|
typeMap, err := tlvRecords.ExtractRecords(&partialSig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the corresponding TLV types if they were included in the stream.
|
|
|
|
if val, ok := typeMap[PartialSigWithNonceRecordType]; ok && val == nil {
|
|
|
|
f.PartialSig = &partialSig
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(tlvRecords) != 0 {
|
|
|
|
f.ExtraData = tlvRecords
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2017-07-29 01:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// MsgType returns the uint32 code which uniquely identifies this message as a
|
|
|
|
// FundingSigned on the wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (f *FundingSigned) MsgType() MessageType {
|
|
|
|
return MsgFundingSigned
|
|
|
|
}
|