mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
lnwire: add SingleFundingSignComplete msg to workflow
This commit adds the SingleFundingSignComplete message to the single funder transaction workflow. This marks the second to last message sent in the workflow. The message transports Bob’s signature for the commitment transaction, allowing Alice to broadcast the funding transaction as she can now refund her inputs.
This commit is contained in:
parent
59a65518c1
commit
f799ff3b66
@ -2,24 +2,36 @@ package lnwire
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"io"
|
||||
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
)
|
||||
|
||||
//Both parties send this message and then it is activated
|
||||
type FundingSignComplete struct {
|
||||
// SingleFundingSignComplete is the message Bob sends to Alice which delivers
|
||||
// a signature for Alice's version of the commitment transaction. After thie
|
||||
// message is received and processed by Alice, she is free to broadcast the
|
||||
// funding transaction.
|
||||
type SingleFundingSignComplete struct {
|
||||
// ChannelID serves to uniquely identify the future channel created by
|
||||
// the initiated single funder workflow.
|
||||
ChannelID uint64
|
||||
|
||||
TxID *wire.ShaHash
|
||||
// CommitmentSignature is Bobs's signature for Alice's version of the
|
||||
// commitment transaction.
|
||||
CommitmentSignature *btcec.Signature
|
||||
}
|
||||
|
||||
func (c *FundingSignComplete) Decode(r io.Reader, pver uint32) error {
|
||||
// Decode deserializes the serialized SingleFundingSignComplete stored in the
|
||||
// passed io.Reader into the target SingleFundingComplete using the
|
||||
// deserialization rules defined by the passed protocol version.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *SingleFundingSignComplete) Decode(r io.Reader, pver uint32) error {
|
||||
// ChannelID (8)
|
||||
// TxID (32)
|
||||
// CommitmentSignature (73)
|
||||
err := readElements(r,
|
||||
&c.ChannelID,
|
||||
&c.TxID)
|
||||
&c.CommitmentSignature)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -27,17 +39,21 @@ func (c *FundingSignComplete) Decode(r io.Reader, pver uint32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Creates a new FundingSignComplete
|
||||
func NewFundingSignComplete() *FundingSignComplete {
|
||||
return &FundingSignComplete{}
|
||||
// NewSingleFundingSignComplete creates a new empty SingleFundingSignComplete
|
||||
// message.
|
||||
func NewSingleFundingSignComplete() *SingleFundingSignComplete {
|
||||
return &SingleFundingSignComplete{}
|
||||
}
|
||||
|
||||
// Serializes the item from the FundingSignComplete struct
|
||||
// Writes the data to w
|
||||
func (c *FundingSignComplete) Encode(w io.Writer, pver uint32) error {
|
||||
// Encode serializes the target SingleFundingSignComplete 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.
|
||||
func (c *SingleFundingSignComplete) Encode(w io.Writer, pver uint32) error {
|
||||
err := writeElements(w,
|
||||
c.ChannelID,
|
||||
c.TxID)
|
||||
c.CommitmentSignature)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -45,24 +61,43 @@ func (c *FundingSignComplete) Encode(w io.Writer, pver uint32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *FundingSignComplete) Command() uint32 {
|
||||
return CmdFundingSignComplete
|
||||
// Command returns the uint32 code which uniquely identifies this message as a
|
||||
// SingleFundingSignComplete on the wire.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *SingleFundingSignComplete) Command() uint32 {
|
||||
return CmdSingleFundingSignComplete
|
||||
}
|
||||
|
||||
func (c *FundingSignComplete) MaxPayloadLength(uint32) uint32 {
|
||||
// 8 (base size) + 32 + (73maxSigSize*127maxInputs)
|
||||
return 40
|
||||
// MaxPayloadLength returns the maximum allowed payload length for a
|
||||
// SingleFundingComplete. This is calculated by summing the max length of all
|
||||
// the fields within a SingleFundingResponse. The final breakdown
|
||||
// is: 8 + 73 = 81
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *SingleFundingSignComplete) MaxPayloadLength(uint32) uint32 {
|
||||
return 81
|
||||
}
|
||||
|
||||
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
|
||||
func (c *FundingSignComplete) Validate() error {
|
||||
// Validate examines each populated field within the SingleFundingComplete for
|
||||
// field sanity.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (s *SingleFundingSignComplete) Validate() error {
|
||||
if s.CommitmentSignature == nil {
|
||||
return fmt.Errorf("commitment signature must be non-nil")
|
||||
}
|
||||
|
||||
// We're good!
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *FundingSignComplete) String() string {
|
||||
// String returns the string representation of the SingleFundingSignComplete.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *SingleFundingSignComplete) String() string {
|
||||
return fmt.Sprintf("\n--- Begin FundingSignComplete ---\n") +
|
||||
fmt.Sprintf("ChannelID:\t\t%d\n", c.ChannelID) +
|
||||
fmt.Sprintf("TxID\t\t%s\n", c.TxID.String()) +
|
||||
fmt.Sprintf("CommitmentSignature\t\t%s\n", c.CommitmentSignature) +
|
||||
fmt.Sprintf("--- End FundingSignComplete ---\n")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user