2016-01-05 19:19:22 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2016-06-21 07:55:07 +03:00
|
|
|
|
|
|
|
"github.com/roasbeef/btcd/wire"
|
2016-01-05 19:19:22 +03:00
|
|
|
)
|
|
|
|
|
2016-05-23 23:54:34 +03:00
|
|
|
// HTLCTimeoutRequest is sent by Alice to Bob in order to timeout a previously
|
|
|
|
// added HTLC. Upon receipt of an HTLCTimeoutRequest the HTLC should be removed
|
|
|
|
// from the next commitment transaction, with the HTLCTimeoutRequest propgated
|
|
|
|
// backwards in the route to fully clear the HTLC.
|
2016-01-05 19:19:22 +03:00
|
|
|
type HTLCTimeoutRequest struct {
|
2016-06-21 07:55:07 +03:00
|
|
|
// ChannelPoint is the particular active channel that this HTLCTimeoutRequest
|
2016-05-23 23:54:34 +03:00
|
|
|
// is binded to.
|
2016-06-21 07:55:07 +03:00
|
|
|
ChannelPoint *wire.OutPoint
|
2016-01-05 19:19:22 +03:00
|
|
|
|
2016-05-23 23:54:34 +03:00
|
|
|
// HTLCKey references which HTLC on the remote node's commitment
|
|
|
|
// transaction has timed out.
|
2016-01-15 04:02:23 +03:00
|
|
|
HTLCKey HTLCKey
|
2016-01-05 19:19:22 +03:00
|
|
|
}
|
|
|
|
|
2016-05-23 23:54:34 +03:00
|
|
|
// Decode deserializes a serialized HTLCTimeoutRequest message stored in the passed
|
|
|
|
// io.Reader observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2016-01-05 19:19:22 +03:00
|
|
|
func (c *HTLCTimeoutRequest) Decode(r io.Reader, pver uint32) error {
|
2016-06-21 07:55:07 +03:00
|
|
|
// ChannelPoint(8)
|
2016-01-17 04:14:35 +03:00
|
|
|
// HTLCKey(8)
|
2016-01-05 19:19:22 +03:00
|
|
|
err := readElements(r,
|
2016-06-21 07:55:07 +03:00
|
|
|
&c.ChannelPoint,
|
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-05-23 23:54:34 +03:00
|
|
|
// NewHTLCTimeoutRequest creates a new HTLCTimeoutRequest message.
|
2016-01-05 19:19:22 +03:00
|
|
|
func NewHTLCTimeoutRequest() *HTLCTimeoutRequest {
|
|
|
|
return &HTLCTimeoutRequest{}
|
|
|
|
}
|
|
|
|
|
2016-05-23 23:54:34 +03:00
|
|
|
// A compile time check to ensure HTLCTimeoutRequest implements the lnwire.Message
|
|
|
|
// interface.
|
|
|
|
var _ Message = (*HTLCTimeoutRequest)(nil)
|
|
|
|
|
|
|
|
// Encode serializes the target HTLCTimeoutRequest into the passed io.Writer observing
|
|
|
|
// the protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2016-01-05 19:19:22 +03:00
|
|
|
func (c *HTLCTimeoutRequest) Encode(w io.Writer, pver uint32) error {
|
|
|
|
err := writeElements(w,
|
2016-06-21 07:55:07 +03:00
|
|
|
c.ChannelPoint,
|
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-05-23 23:54:34 +03:00
|
|
|
// Command returns the integer uniquely identifying this message type on the
|
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2016-01-05 19:19:22 +03:00
|
|
|
func (c *HTLCTimeoutRequest) Command() uint32 {
|
|
|
|
return CmdHTLCTimeoutRequest
|
|
|
|
}
|
|
|
|
|
2016-05-23 23:54:34 +03:00
|
|
|
// MaxPayloadLength returns the maximum allowed payload size for a HTLCTimeoutRequest
|
|
|
|
// complete message observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2016-01-05 19:19:22 +03:00
|
|
|
func (c *HTLCTimeoutRequest) MaxPayloadLength(uint32) uint32 {
|
2016-06-21 07:55:07 +03:00
|
|
|
// 36 + 8
|
|
|
|
return 44
|
2016-01-05 19:19:22 +03:00
|
|
|
}
|
|
|
|
|
2016-05-23 23:54:34 +03:00
|
|
|
// Validate performs any necessary sanity checks to ensure all fields present
|
|
|
|
// on the HTLCTimeoutRequest are valid.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2016-01-05 19:19:22 +03:00
|
|
|
func (c *HTLCTimeoutRequest) Validate() error {
|
2016-01-17 04:14:35 +03:00
|
|
|
// We're good!
|
2016-01-05 19:19:22 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-23 23:54:34 +03:00
|
|
|
// String returns the string representation of the target HTLCTimeoutRequest. //
|
|
|
|
// This is part of the lnwire.Message interface.
|
2016-01-05 19:19:22 +03:00
|
|
|
func (c *HTLCTimeoutRequest) String() string {
|
|
|
|
return fmt.Sprintf("\n--- Begin HTLCTimeoutRequest ---\n") +
|
2016-06-21 07:55:07 +03:00
|
|
|
fmt.Sprintf("ChannelPoint:\t%d\n", c.ChannelPoint) +
|
2016-01-15 04:02:23 +03:00
|
|
|
fmt.Sprintf("HTLCKey:\t%d\n", c.HTLCKey) +
|
2016-01-05 19:19:22 +03:00
|
|
|
fmt.Sprintf("--- End HTLCTimeoutRequest ---\n")
|
|
|
|
}
|