2015-12-31 13:42:25 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/btcsuite/btcd/btcec"
|
|
|
|
"github.com/btcsuite/btcd/wire"
|
|
|
|
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CloseComplete struct {
|
|
|
|
ReservationID uint64
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
ResponderCloseSig *btcec.Signature // Requester's Commitment
|
|
|
|
CloseShaHash *wire.ShaHash // TxID of the Close Tx
|
2015-12-31 13:42:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CloseComplete) Decode(r io.Reader, pver uint32) error {
|
2016-01-17 04:14:35 +03:00
|
|
|
// ReservationID (8)
|
|
|
|
// ResponderCloseSig (73)
|
|
|
|
// First byte length then sig
|
|
|
|
// CloseShaHash (32)
|
2015-12-31 13:42:25 +03:00
|
|
|
err := readElements(r,
|
|
|
|
&c.ReservationID,
|
|
|
|
&c.ResponderCloseSig,
|
|
|
|
&c.CloseShaHash)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Creates a new CloseComplete
|
2015-12-31 13:42:25 +03:00
|
|
|
func NewCloseComplete() *CloseComplete {
|
|
|
|
return &CloseComplete{}
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Serializes the item from the CloseComplete struct
|
|
|
|
// Writes the data to w
|
2015-12-31 13:42:25 +03:00
|
|
|
func (c *CloseComplete) Encode(w io.Writer, pver uint32) error {
|
2016-01-17 04:14:35 +03:00
|
|
|
// ReservationID
|
|
|
|
// ResponderCloseSig
|
|
|
|
// CloseShaHash
|
2015-12-31 13:42:25 +03:00
|
|
|
err := writeElements(w,
|
|
|
|
c.ReservationID,
|
|
|
|
c.ResponderCloseSig,
|
|
|
|
c.CloseShaHash)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CloseComplete) Command() uint32 {
|
|
|
|
return CmdCloseComplete
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CloseComplete) MaxPayloadLength(uint32) uint32 {
|
2016-01-17 04:14:35 +03:00
|
|
|
// 8 + 73 + 32
|
2015-12-31 13:42:25 +03:00
|
|
|
return 113
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
|
2015-12-31 13:42:25 +03:00
|
|
|
func (c *CloseComplete) Validate() error {
|
2016-01-17 04:14:35 +03:00
|
|
|
// We're good!
|
2015-12-31 13:42:25 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CloseComplete) String() string {
|
|
|
|
var serializedSig []byte
|
|
|
|
var shaString string
|
|
|
|
if c.ResponderCloseSig != nil && c.ResponderCloseSig.R != nil {
|
|
|
|
serializedSig = c.ResponderCloseSig.Serialize()
|
|
|
|
}
|
|
|
|
if c.CloseShaHash != nil {
|
|
|
|
shaString = (*c).CloseShaHash.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("\n--- Begin CloseComplete ---\n") +
|
|
|
|
fmt.Sprintf("ReservationID:\t\t%d\n", c.ReservationID) +
|
|
|
|
fmt.Sprintf("ResponderCloseSig:\t%x\n", serializedSig) +
|
|
|
|
fmt.Sprintf("CloseShaHash:\t\t%s\n", shaString) +
|
|
|
|
fmt.Sprintf("--- End CloseComplete ---\n")
|
|
|
|
}
|