Files
lnd.xprv/lnwire/htlc_timeoutrequest.go
T

71 lines
1.4 KiB
Go
Raw Normal View History

package lnwire
import (
"fmt"
"io"
)
2016-01-16 17:14:35 -08:00
// Multiple Clearing Requests are possible by putting this inside an array of
// clearing requests
type HTLCTimeoutRequest struct {
2016-01-16 17:14:35 -08:00
// We can use a different data type for this if necessary...
ChannelID uint64
2016-01-16 17:14:35 -08:00
// ID of this request
2016-01-14 17:02:23 -08:00
HTLCKey HTLCKey
}
func (c *HTLCTimeoutRequest) Decode(r io.Reader, pver uint32) error {
2016-01-16 17:14:35 -08:00
// ChannelID(8)
// HTLCKey(8)
err := readElements(r,
&c.ChannelID,
2016-01-14 17:02:23 -08:00
&c.HTLCKey,
)
if err != nil {
return err
}
return nil
}
2016-01-16 17:14:35 -08:00
// Creates a new HTLCTimeoutRequest
func NewHTLCTimeoutRequest() *HTLCTimeoutRequest {
return &HTLCTimeoutRequest{}
}
2016-01-16 17:14:35 -08:00
// Serializes the item from the HTLCTimeoutRequest struct
// Writes the data to w
func (c *HTLCTimeoutRequest) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
c.ChannelID,
2016-01-14 17:02:23 -08:00
c.HTLCKey,
)
if err != nil {
return err
}
return nil
}
func (c *HTLCTimeoutRequest) Command() uint32 {
return CmdHTLCTimeoutRequest
}
func (c *HTLCTimeoutRequest) MaxPayloadLength(uint32) uint32 {
2016-01-16 17:14:35 -08:00
// 16
return 16
}
2016-01-16 17:14:35 -08:00
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
func (c *HTLCTimeoutRequest) Validate() error {
2016-01-16 17:14:35 -08:00
// We're good!
return nil
}
func (c *HTLCTimeoutRequest) String() string {
return fmt.Sprintf("\n--- Begin HTLCTimeoutRequest ---\n") +
fmt.Sprintf("ChannelID:\t%d\n", c.ChannelID) +
2016-01-14 17:02:23 -08:00
fmt.Sprintf("HTLCKey:\t%d\n", c.HTLCKey) +
fmt.Sprintf("--- End HTLCTimeoutRequest ---\n")
}