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
|
2016-10-15 16:18:38 +03:00
|
|
|
// a signature for Alice's version of the commitment transaction. After this
|
2016-05-23 08:29:32 +03:00
|
|
|
// message is received and processed by Alice, she is free to broadcast the
|
|
|
|
// funding transaction.
|
|
|
|
type SingleFundingSignComplete struct {
|
2017-04-17 01:22:20 +03:00
|
|
|
// PendingChannelID serves to uniquely identify the future channel
|
|
|
|
// created by the initiated single funder workflow.
|
|
|
|
PendingChannelID [32]byte
|
2016-05-18 07:28:42 +03:00
|
|
|
|
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.
|
2017-04-17 01:22:20 +03:00
|
|
|
func NewSingleFundingSignComplete(chanID [32]byte,
|
2016-05-31 01:45:44 +03:00
|
|
|
sig *btcec.Signature) *SingleFundingSignComplete {
|
|
|
|
|
|
|
|
return &SingleFundingSignComplete{
|
2017-04-17 01:22:20 +03:00
|
|
|
PendingChannelID: chanID,
|
|
|
|
CommitSignature: sig,
|
2016-05-31 01:45:44 +03:00
|
|
|
}
|
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 {
|
2017-02-23 21:59:50 +03:00
|
|
|
return readElements(r,
|
2017-04-17 01:22:20 +03:00
|
|
|
c.PendingChannelID[:],
|
2016-05-31 01:45:44 +03:00
|
|
|
&c.CommitSignature)
|
2016-05-18 07:28:42 +03:00
|
|
|
}
|
|
|
|
|
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 {
|
2017-02-23 21:59:50 +03:00
|
|
|
return writeElements(w,
|
2017-04-17 01:22:20 +03:00
|
|
|
c.PendingChannelID[:],
|
2016-05-31 01:45:44 +03:00
|
|
|
c.CommitSignature)
|
2016-05-18 07:28:42 +03:00
|
|
|
}
|
|
|
|
|
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
|
2017-04-17 01:22:20 +03:00
|
|
|
// SingleFundingSignComplete. This is calculated by summing the max length of
|
|
|
|
// all the fields within a SingleFundingSignComplete.
|
2016-05-23 08:29:32 +03:00
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *SingleFundingSignComplete) MaxPayloadLength(uint32) uint32 {
|
2017-04-17 01:22:20 +03:00
|
|
|
// 32 + 64
|
|
|
|
return 96
|
2016-05-18 07:28:42 +03:00
|
|
|
}
|
|
|
|
|
2017-01-31 08:45:02 +03:00
|
|
|
// Validate examines each populated field within the SingleFundingSignComplete
|
|
|
|
// for field sanity.
|
2016-05-23 08:29:32 +03:00
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-02-23 22:56:47 +03:00
|
|
|
func (c *SingleFundingSignComplete) Validate() error {
|
|
|
|
if c.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
|
|
|
|
}
|