lnd.xprv/lnwire/close_complete.go

87 lines
1.8 KiB
Go
Raw Normal View History

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
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 {
// 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
}
// Creates a new CloseComplete
2015-12-31 13:42:25 +03:00
func NewCloseComplete() *CloseComplete {
return &CloseComplete{}
}
// 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 {
// 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 {
// 8 + 73 + 32
2015-12-31 13:42:25 +03:00
return 113
}
// 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 {
// 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")
}