2016-05-18 07:28:42 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2016-05-23 08:29:32 +03:00
|
|
|
|
|
|
|
"github.com/roasbeef/btcd/btcec"
|
2016-05-18 07:28:42 +03:00
|
|
|
)
|
|
|
|
|
2016-05-23 08:29:32 +03:00
|
|
|
// 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.
|
2016-05-18 07:28:42 +03:00
|
|
|
ChannelID uint64
|
|
|
|
|
2016-05-31 01:45:44 +03:00
|
|
|
// CommitSignature is Bobs's signature for Alice's version of the
|
2016-05-23 08:29:32 +03:00
|
|
|
// commitment transaction.
|
2016-05-31 01:45:44 +03:00
|
|
|
CommitSignature *btcec.Signature
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewSingleFundingSignComplete creates a new empty SingleFundingSignComplete
|
|
|
|
// message.
|
|
|
|
func NewSingleFundingSignComplete(chanID uint64,
|
|
|
|
sig *btcec.Signature) *SingleFundingSignComplete {
|
|
|
|
|
|
|
|
return &SingleFundingSignComplete{
|
|
|
|
ChannelID: chanID,
|
|
|
|
CommitSignature: sig,
|
|
|
|
}
|
2016-05-18 07:28:42 +03:00
|
|
|
}
|
|
|
|
|
2016-05-23 08:29:32 +03:00
|
|
|
// 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 {
|
2016-05-18 07:28:42 +03:00
|
|
|
// ChannelID (8)
|
2016-05-23 08:29:32 +03:00
|
|
|
// CommitmentSignature (73)
|
2016-05-18 07:28:42 +03:00
|
|
|
err := readElements(r,
|
|
|
|
&c.ChannelID,
|
2016-05-31 01:45:44 +03:00
|
|
|
&c.CommitSignature)
|
2016-05-18 07:28:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-23 08:29:32 +03:00
|
|
|
// 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 {
|
2016-05-18 07:28:42 +03:00
|
|
|
err := writeElements(w,
|
|
|
|
c.ChannelID,
|
2016-05-31 01:45:44 +03:00
|
|
|
c.CommitSignature)
|
2016-05-18 07:28:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-23 08:29:32 +03:00
|
|
|
// 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
|
2016-05-18 07:28:42 +03:00
|
|
|
}
|
|
|
|
|
2016-05-23 08:29:32 +03:00
|
|
|
// 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
|
2016-05-18 07:28:42 +03:00
|
|
|
}
|
|
|
|
|
2016-05-23 08:29:32 +03:00
|
|
|
// Validate examines each populated field within the SingleFundingComplete for
|
|
|
|
// field sanity.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (s *SingleFundingSignComplete) Validate() error {
|
2016-05-31 01:45:44 +03:00
|
|
|
if s.CommitSignature == nil {
|
2016-05-23 08:29:32 +03:00
|
|
|
return fmt.Errorf("commitment signature must be non-nil")
|
|
|
|
}
|
|
|
|
|
2016-05-18 07:28:42 +03:00
|
|
|
// We're good!
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-23 08:29:32 +03:00
|
|
|
// String returns the string representation of the SingleFundingSignComplete.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *SingleFundingSignComplete) String() string {
|
2016-05-18 07:28:42 +03:00
|
|
|
return fmt.Sprintf("\n--- Begin FundingSignComplete ---\n") +
|
|
|
|
fmt.Sprintf("ChannelID:\t\t%d\n", c.ChannelID) +
|
2016-05-31 01:45:44 +03:00
|
|
|
fmt.Sprintf("CommitSignature\t\t%s\n", c.CommitSignature) +
|
2016-05-18 07:28:42 +03:00
|
|
|
fmt.Sprintf("--- End FundingSignComplete ---\n")
|
|
|
|
}
|