Files
lnd.xprv/lnwire/error_generic.go
T

74 lines
1.4 KiB
Go
Raw Normal View History

2016-01-05 08:53:42 -08:00
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
2016-01-05 08:53:42 -08:00
type ErrorGeneric struct {
2016-01-16 17:14:35 -08:00
// We can use a different data type for this if necessary...
2016-01-05 08:53:42 -08:00
ChannelID uint64
2016-01-16 17:14:35 -08:00
// Some kind of message
// Max length 8192
2016-01-05 08:53:42 -08:00
Problem string
}
func (c *ErrorGeneric) Decode(r io.Reader, pver uint32) error {
2016-01-16 17:14:35 -08:00
// ChannelID(8)
// Problem
2016-01-05 08:53:42 -08:00
err := readElements(r,
&c.ChannelID,
&c.Problem,
)
if err != nil {
return err
}
return nil
}
2016-01-16 17:14:35 -08:00
// Creates a new ErrorGeneric
2016-01-05 08:53:42 -08:00
func NewErrorGeneric() *ErrorGeneric {
return &ErrorGeneric{}
}
2016-01-16 17:14:35 -08:00
// Serializes the item from the ErrorGeneric struct
// Writes the data to w
2016-01-05 08:53:42 -08:00
func (c *ErrorGeneric) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
c.ChannelID,
c.Problem,
)
if err != nil {
return err
}
return nil
}
func (c *ErrorGeneric) Command() uint32 {
return CmdErrorGeneric
}
func (c *ErrorGeneric) MaxPayloadLength(uint32) uint32 {
2016-01-16 17:14:35 -08:00
// 8+8192
2016-01-05 08:53:42 -08:00
return 8208
}
2016-01-16 17:14:35 -08:00
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
2016-01-05 08:53:42 -08:00
func (c *ErrorGeneric) Validate() error {
if len(c.Problem) > 8192 {
return fmt.Errorf("Problem string length too long")
}
2016-01-16 17:14:35 -08:00
// We're good!
2016-01-05 08:53:42 -08:00
return nil
}
func (c *ErrorGeneric) String() string {
return fmt.Sprintf("\n--- Begin ErrorGeneric ---\n") +
fmt.Sprintf("ChannelID:\t%d\n", c.ChannelID) +
fmt.Sprintf("Problem:\t%s\n", c.Problem) +
fmt.Sprintf("--- End ErrorGeneric ---\n")
}