mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 09:48:19 +01:00
lnwire: add PartialSig to FundingSigned
This commit is contained in:
parent
292b8db8f0
commit
79c473cc46
1 changed files with 46 additions and 1 deletions
|
@ -3,6 +3,8 @@ package lnwire
|
|||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
)
|
||||
|
||||
// FundingSigned is sent from Bob (the responder) to Alice (the initiator)
|
||||
|
@ -17,6 +19,13 @@ type FundingSigned struct {
|
|||
// transaction.
|
||||
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
|
||||
// fill out the full maximum transport message size. These fields can
|
||||
// be used to specify optional data such as custom TLV fields.
|
||||
|
@ -33,6 +42,15 @@ var _ Message = (*FundingSigned)(nil)
|
|||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (f *FundingSigned) 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 := WriteChannelID(w, f.ChanID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -50,7 +68,34 @@ func (f *FundingSigned) Encode(w *bytes.Buffer, pver uint32) error {
|
|||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (f *FundingSigned) Decode(r io.Reader, pver uint32) error {
|
||||
return ReadElements(r, &f.ChanID, &f.CommitSig, &f.ExtraData)
|
||||
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
|
||||
}
|
||||
|
||||
// MsgType returns the uint32 code which uniquely identifies this message as a
|
||||
|
|
Loading…
Add table
Reference in a new issue