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:
Olaoluwa Osuntokun 2016-05-22 22:29:32 -07:00
parent 59a65518c1
commit f799ff3b66
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -2,24 +2,36 @@ package lnwire
import ( import (
"fmt" "fmt"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/wire"
"io" "io"
"github.com/roasbeef/btcd/btcec"
) )
//Both parties send this message and then it is activated // SingleFundingSignComplete is the message Bob sends to Alice which delivers
type FundingSignComplete struct { // 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 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) // ChannelID (8)
// TxID (32) // CommitmentSignature (73)
err := readElements(r, err := readElements(r,
&c.ChannelID, &c.ChannelID,
&c.TxID) &c.CommitmentSignature)
if err != nil { if err != nil {
return err return err
} }
@ -27,17 +39,21 @@ func (c *FundingSignComplete) Decode(r io.Reader, pver uint32) error {
return nil return nil
} }
// Creates a new FundingSignComplete // NewSingleFundingSignComplete creates a new empty SingleFundingSignComplete
func NewFundingSignComplete() *FundingSignComplete { // message.
return &FundingSignComplete{} func NewSingleFundingSignComplete() *SingleFundingSignComplete {
return &SingleFundingSignComplete{}
} }
// Serializes the item from the FundingSignComplete struct // Encode serializes the target SingleFundingSignComplete into the passed
// Writes the data to w // io.Writer implementation. Serialization will observe the rules defined by
func (c *FundingSignComplete) Encode(w io.Writer, pver uint32) error { // 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, err := writeElements(w,
c.ChannelID, c.ChannelID,
c.TxID) c.CommitmentSignature)
if err != nil { if err != nil {
return err return err
} }
@ -45,24 +61,43 @@ func (c *FundingSignComplete) Encode(w io.Writer, pver uint32) error {
return nil return nil
} }
func (c *FundingSignComplete) Command() uint32 { // Command returns the uint32 code which uniquely identifies this message as a
return CmdFundingSignComplete // 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 { // MaxPayloadLength returns the maximum allowed payload length for a
// 8 (base size) + 32 + (73maxSigSize*127maxInputs) // SingleFundingComplete. This is calculated by summing the max length of all
return 40 // 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) // Validate examines each populated field within the SingleFundingComplete for
func (c *FundingSignComplete) Validate() error { // 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! // We're good!
return nil 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") + return fmt.Sprintf("\n--- Begin FundingSignComplete ---\n") +
fmt.Sprintf("ChannelID:\t\t%d\n", c.ChannelID) + 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") fmt.Sprintf("--- End FundingSignComplete ---\n")
} }