2016-01-05 19:19:22 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// ChannelPoint represents a unique state update within currently active
|
|
|
|
// channel. A channel update across all open chnnels can be uniquely identified
|
|
|
|
// by a two-tuple: (fundingTXID, HTLCKey). All explicit updates to an open
|
|
|
|
// channel will reference a ChannelPoint to apply the update to.
|
|
|
|
type ChannelPoint struct {
|
|
|
|
// ChannelID references the particular active channel to which this
|
|
|
|
// HTLCAddReject message is binded to.
|
|
|
|
ChannelID uint64
|
|
|
|
|
|
|
|
// HTLCKey is used to identify which HTLC previously attempted to be
|
|
|
|
// added via an HTLCAddRequest message is being declined.
|
|
|
|
HTLCKey HTLCKey
|
|
|
|
}
|
|
|
|
|
2016-05-23 23:54:34 +03:00
|
|
|
// HTLCAddReject is sent by Bob when he wishes to reject a particular HTLC that
|
|
|
|
// Alice attempted to add via an HTLCAddRequest message. The rejected HTLC is
|
|
|
|
// referenced by its unique HTLCKey ID. An HTLCAddReject message is bound to a
|
|
|
|
// single active channel, referenced by a unique ChannelID. Additionally, the
|
|
|
|
// HTLCKey of the rejected HTLC is present
|
2016-01-05 19:19:22 +03:00
|
|
|
type HTLCAddReject struct {
|
2016-05-23 23:54:34 +03:00
|
|
|
// ChannelID references the particular active channel to which this
|
|
|
|
// HTLCAddReject message is binded to.
|
2016-01-05 19:19:22 +03:00
|
|
|
ChannelID uint64
|
2016-05-23 23:54:34 +03:00
|
|
|
|
|
|
|
// HTLCKey is used to identify which HTLC previously attempted to be
|
|
|
|
// added via an HTLCAddRequest message is being declined.
|
|
|
|
HTLCKey HTLCKey
|
2016-01-05 19:19:22 +03:00
|
|
|
}
|
|
|
|
|
2016-05-23 23:54:34 +03:00
|
|
|
// Decode deserializes a serialized HTLCAddReject 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 *HTLCAddReject) Decode(r io.Reader, pver uint32) error {
|
2016-05-23 23:54:34 +03:00
|
|
|
// ChannelID (8)
|
|
|
|
// HTLCKey (8)
|
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-05-23 23:54:34 +03:00
|
|
|
// NewHTLCAddReject returns a new empty HTLCAddReject message.
|
2016-01-05 19:19:22 +03:00
|
|
|
func NewHTLCAddReject() *HTLCAddReject {
|
|
|
|
return &HTLCAddReject{}
|
|
|
|
}
|
|
|
|
|
2016-05-23 23:54:34 +03:00
|
|
|
// A compile time check to ensure HTLCAddReject implements the lnwire.Message
|
|
|
|
// interface.
|
|
|
|
var _ Message = (*HTLCAddReject)(nil)
|
|
|
|
|
|
|
|
// Encode serializes the target HTLCAddReject 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 *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
|
|
|
|
}
|
|
|
|
|
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 *HTLCAddReject) Command() uint32 {
|
|
|
|
return CmdHTLCAddReject
|
|
|
|
}
|
|
|
|
|
2016-05-23 23:54:34 +03:00
|
|
|
// MaxPayloadLength returns the maximum allowed payload size for a HTLCAddReject
|
|
|
|
// 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 *HTLCAddReject) MaxPayloadLength(uint32) uint32 {
|
2016-05-23 23:54:34 +03:00
|
|
|
// 8 + 8
|
2016-01-05 19:19:22 +03:00
|
|
|
return 16
|
|
|
|
}
|
|
|
|
|
2016-05-23 23:54:34 +03:00
|
|
|
// Validate performs any necessary sanity checks to ensure all fields present
|
|
|
|
// on the HTLCAddReject are valid.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
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
|
|
|
|
}
|
|
|
|
|
2016-05-23 23:54:34 +03:00
|
|
|
// String returns the string representation of the target HTLCAddReject.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2016-01-05 19:19:22 +03:00
|
|
|
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")
|
|
|
|
}
|