2016-01-05 19:19:22 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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
|
|
|
// HTLCSettleRequest is sent by Alice to Bob when she wishes to settle a
|
|
|
|
// particular HTLC referenced by its HTLCKey within a specific active channel
|
2016-06-21 07:55:07 +03:00
|
|
|
// referenced by ChannelPoint. The message allows multiple hash preimages to be
|
2016-05-23 23:54:34 +03:00
|
|
|
// presented in order to support N-of-M HTLC contracts. A subsequent
|
|
|
|
// CommitSignature message will be sent by Alice to "lock-in" the removal of the
|
|
|
|
// specified HTLC, possible containing a batch signature covering several settled
|
|
|
|
// HTLC's.
|
2016-01-05 19:19:22 +03:00
|
|
|
type HTLCSettleRequest struct {
|
2016-06-21 07:55:07 +03:00
|
|
|
// ChannelPoint references an active channel which holds the HTLC to be
|
2016-05-23 23:54:34 +03:00
|
|
|
// settled.
|
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 denotes the exact HTLC stage within the receiving node's
|
|
|
|
// commitment transaction to be removed.
|
2016-06-30 21:53:11 +03:00
|
|
|
// TODO(roasbeef): rename to LogIndex
|
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
|
|
|
// RedemptionProofs are the R-value preimages required to fully settle
|
|
|
|
// an HTLC. The number of preimages in the slice will depend on the
|
|
|
|
// specific ContractType of the referenced HTLC.
|
2016-06-30 21:53:11 +03:00
|
|
|
RedemptionProofs [][32]byte
|
2016-01-05 19:19:22 +03:00
|
|
|
}
|
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// NewHTLCSettleRequest returns a new empty HTLCSettleRequest.
|
2016-06-21 07:55:07 +03:00
|
|
|
func NewHTLCSettleRequest(chanPoint *wire.OutPoint, key HTLCKey,
|
2016-06-30 21:53:11 +03:00
|
|
|
redemptionProofs [][32]byte) *HTLCSettleRequest {
|
2016-05-31 02:49:48 +03:00
|
|
|
|
|
|
|
return &HTLCSettleRequest{
|
2016-06-21 07:55:07 +03:00
|
|
|
ChannelPoint: chanPoint,
|
2016-05-31 02:49:48 +03:00
|
|
|
HTLCKey: key,
|
|
|
|
RedemptionProofs: redemptionProofs,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time check to ensure HTLCSettleRequest implements the lnwire.Message
|
|
|
|
// interface.
|
|
|
|
var _ Message = (*HTLCSettleRequest)(nil)
|
|
|
|
|
2016-05-23 23:54:34 +03:00
|
|
|
// Decode deserializes a serialized HTLCSettleRequest 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 *HTLCSettleRequest) 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-06-30 21:53:11 +03:00
|
|
|
// RedemptionProofs(N*32)
|
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
|
|
|
&c.RedemptionProofs,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// Encode serializes the target HTLCSettleRequest 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 *HTLCSettleRequest) 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
|
|
|
c.RedemptionProofs,
|
|
|
|
)
|
|
|
|
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 *HTLCSettleRequest) Command() uint32 {
|
|
|
|
return CmdHTLCSettleRequest
|
|
|
|
}
|
|
|
|
|
2016-05-23 23:54:34 +03:00
|
|
|
// MaxPayloadLength returns the maximum allowed payload size for a HTLCSettleRequest
|
|
|
|
// 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 *HTLCSettleRequest) MaxPayloadLength(uint32) uint32 {
|
2016-06-30 21:53:11 +03:00
|
|
|
// 36 + 8 + (32 * 15)
|
|
|
|
return 524
|
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 HTLCSettleRequest are valid.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2016-01-05 19:19:22 +03:00
|
|
|
func (c *HTLCSettleRequest) Validate() error {
|
2016-01-17 04:14:35 +03:00
|
|
|
// We're good!
|
2016-01-05 19:19:22 +03:00
|
|
|
return nil
|
|
|
|
}
|