mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-28 09:45:25 +02:00
lnwire: add PartialSig to FundingCreated
This commit is contained in:
parent
ee279fbde3
commit
292b8db8f0
@ -5,6 +5,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FundingCreated is sent from Alice (the initiator) to Bob (the responder),
|
// FundingCreated is sent from Alice (the initiator) to Bob (the responder),
|
||||||
@ -26,6 +27,13 @@ type FundingCreated struct {
|
|||||||
// transaction.
|
// transaction.
|
||||||
CommitSig Sig
|
CommitSig Sig
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
// ExtraData is the set of data that was appended to this message to
|
// ExtraData is the set of data that was appended to this message to
|
||||||
// fill out the full maximum transport message size. These fields can
|
// fill out the full maximum transport message size. These fields can
|
||||||
// be used to specify optional data such as custom TLV fields.
|
// be used to specify optional data such as custom TLV fields.
|
||||||
@ -42,6 +50,15 @@ var _ Message = (*FundingCreated)(nil)
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (f *FundingCreated) Encode(w *bytes.Buffer, pver uint32) error {
|
func (f *FundingCreated) Encode(w *bytes.Buffer, pver uint32) error {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
if err := WriteBytes(w, f.PendingChannelID[:]); err != nil {
|
if err := WriteBytes(w, f.PendingChannelID[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -63,10 +80,36 @@ func (f *FundingCreated) Encode(w *bytes.Buffer, pver uint32) error {
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (f *FundingCreated) Decode(r io.Reader, pver uint32) error {
|
func (f *FundingCreated) Decode(r io.Reader, pver uint32) error {
|
||||||
return ReadElements(
|
err := ReadElements(
|
||||||
r, f.PendingChannelID[:], &f.FundingPoint, &f.CommitSig,
|
r, f.PendingChannelID[:], &f.FundingPoint, &f.CommitSig,
|
||||||
&f.ExtraData,
|
|
||||||
)
|
)
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgType returns the uint32 code which uniquely identifies this message as a
|
// MsgType returns the uint32 code which uniquely identifies this message as a
|
||||||
|
Loading…
x
Reference in New Issue
Block a user