2016-01-05 19:19:22 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HTLCAddReject struct {
|
|
|
|
ChannelID uint64
|
2016-01-15 04:02:23 +03:00
|
|
|
HTLCKey HTLCKey
|
2016-01-05 19:19:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *HTLCAddReject) Decode(r io.Reader, pver uint32) error {
|
2016-01-17 04:14:35 +03:00
|
|
|
// ChannelID(8)
|
|
|
|
// CommitmentHeight(8)
|
|
|
|
// NextResponderCommitmentRevocationHash(20)
|
|
|
|
// ResponderRevocationPreimage(20)
|
|
|
|
// ResponderCommitSig(2+73max)
|
2016-01-05 19:19:22 +03:00
|
|
|
err := readElements(r,
|
|
|
|
&c.ChannelID,
|
2016-01-15 04:02:23 +03:00
|
|
|
&c.HTLCKey,
|
2016-01-05 19:19:22 +03:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Creates a new HTLCAddReject
|
2016-01-05 19:19:22 +03:00
|
|
|
func NewHTLCAddReject() *HTLCAddReject {
|
|
|
|
return &HTLCAddReject{}
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Serializes the item from the HTLCAddReject struct
|
|
|
|
// Writes the data to w
|
2016-01-05 19:19:22 +03:00
|
|
|
func (c *HTLCAddReject) Encode(w io.Writer, pver uint32) error {
|
|
|
|
err := writeElements(w,
|
|
|
|
c.ChannelID,
|
2016-01-15 04:02:23 +03:00
|
|
|
c.HTLCKey,
|
2016-01-05 19:19:22 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *HTLCAddReject) Command() uint32 {
|
|
|
|
return CmdHTLCAddReject
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *HTLCAddReject) MaxPayloadLength(uint32) uint32 {
|
2016-01-17 04:14:35 +03:00
|
|
|
// 16 base size
|
2016-01-05 19:19:22 +03:00
|
|
|
return 16
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
|
2016-01-05 19:19:22 +03:00
|
|
|
func (c *HTLCAddReject) Validate() error {
|
2016-01-17 04:14:35 +03:00
|
|
|
// We're good!
|
2016-01-05 19:19:22 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *HTLCAddReject) String() string {
|
|
|
|
return fmt.Sprintf("\n--- Begin HTLCAddReject ---\n") +
|
|
|
|
fmt.Sprintf("ChannelID:\t\t%d\n", c.ChannelID) +
|
2016-01-15 04:02:23 +03:00
|
|
|
fmt.Sprintf("HTLCKey:\t\t%d\n", c.HTLCKey) +
|
2016-01-05 19:19:22 +03:00
|
|
|
fmt.Sprintf("--- End HTLCAddReject ---\n")
|
|
|
|
}
|