2017-02-16 15:34:09 +03:00
|
|
|
package lnwire
|
|
|
|
|
2019-09-25 22:00:59 +03:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
2017-02-16 15:34:09 +03:00
|
|
|
|
2018-02-07 06:11:11 +03:00
|
|
|
// UpdateFulfillHTLC is sent by Alice to Bob when she wishes to settle a
|
2017-02-16 15:34:09 +03:00
|
|
|
// particular HTLC referenced by its HTLCKey within a specific active channel
|
|
|
|
// referenced by ChannelPoint. A subsequent CommitSig 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.
|
2018-02-07 06:11:11 +03:00
|
|
|
type UpdateFulfillHTLC struct {
|
2017-04-17 01:22:20 +03:00
|
|
|
// ChanID references an active channel which holds the HTLC to be
|
2017-02-16 15:34:09 +03:00
|
|
|
// settled.
|
2017-04-17 01:22:20 +03:00
|
|
|
ChanID ChannelID
|
2017-02-16 15:34:09 +03:00
|
|
|
|
|
|
|
// ID denotes the exact HTLC stage within the receiving node's
|
|
|
|
// commitment transaction to be removed.
|
|
|
|
ID uint64
|
|
|
|
|
|
|
|
// PaymentPreimage is the R-value preimage required to fully settle an
|
|
|
|
// HTLC.
|
|
|
|
PaymentPreimage [32]byte
|
|
|
|
}
|
|
|
|
|
2018-02-07 06:11:11 +03:00
|
|
|
// NewUpdateFulfillHTLC returns a new empty UpdateFulfillHTLC.
|
|
|
|
func NewUpdateFulfillHTLC(chanID ChannelID, id uint64,
|
|
|
|
preimage [32]byte) *UpdateFulfillHTLC {
|
2017-02-16 15:34:09 +03:00
|
|
|
|
2018-02-07 06:11:11 +03:00
|
|
|
return &UpdateFulfillHTLC{
|
2017-04-17 01:22:20 +03:00
|
|
|
ChanID: chanID,
|
2017-02-16 15:34:09 +03:00
|
|
|
ID: id,
|
|
|
|
PaymentPreimage: preimage,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-07 06:11:11 +03:00
|
|
|
// A compile time check to ensure UpdateFulfillHTLC implements the lnwire.Message
|
2017-02-16 15:34:09 +03:00
|
|
|
// interface.
|
2018-02-07 06:11:11 +03:00
|
|
|
var _ Message = (*UpdateFulfillHTLC)(nil)
|
2017-02-16 15:34:09 +03:00
|
|
|
|
2018-02-07 06:11:11 +03:00
|
|
|
// Decode deserializes a serialized UpdateFulfillHTLC message stored in the passed
|
2017-02-16 15:34:09 +03:00
|
|
|
// io.Reader observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2018-02-07 06:11:11 +03:00
|
|
|
func (c *UpdateFulfillHTLC) Decode(r io.Reader, pver uint32) error {
|
2018-12-10 05:27:41 +03:00
|
|
|
return ReadElements(r,
|
2017-04-17 01:22:20 +03:00
|
|
|
&c.ChanID,
|
2017-02-16 15:34:09 +03:00
|
|
|
&c.ID,
|
|
|
|
c.PaymentPreimage[:],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-02-07 06:11:11 +03:00
|
|
|
// Encode serializes the target UpdateFulfillHTLC into the passed io.Writer
|
2017-02-16 15:34:09 +03:00
|
|
|
// observing the protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2018-02-07 06:11:11 +03:00
|
|
|
func (c *UpdateFulfillHTLC) Encode(w io.Writer, pver uint32) error {
|
2018-12-10 05:27:41 +03:00
|
|
|
return WriteElements(w,
|
2017-04-17 01:22:20 +03:00
|
|
|
c.ChanID,
|
2017-02-16 15:34:09 +03:00
|
|
|
c.ID,
|
|
|
|
c.PaymentPreimage[:],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-04-20 01:57:43 +03:00
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
2017-02-16 15:34:09 +03:00
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2018-02-07 06:11:11 +03:00
|
|
|
func (c *UpdateFulfillHTLC) MsgType() MessageType {
|
|
|
|
return MsgUpdateFulfillHTLC
|
2017-02-16 15:34:09 +03:00
|
|
|
}
|
|
|
|
|
2018-04-18 05:02:04 +03:00
|
|
|
// MaxPayloadLength returns the maximum allowed payload size for an UpdateFulfillHTLC
|
2017-02-16 15:34:09 +03:00
|
|
|
// complete message observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2018-02-07 06:11:11 +03:00
|
|
|
func (c *UpdateFulfillHTLC) MaxPayloadLength(uint32) uint32 {
|
2017-04-17 01:22:20 +03:00
|
|
|
// 32 + 8 + 32
|
|
|
|
return 72
|
2017-02-16 15:34:09 +03:00
|
|
|
}
|
2019-09-25 22:00:59 +03:00
|
|
|
|
|
|
|
// TargetChanID returns the channel id of the link for which this message is
|
|
|
|
// intended.
|
|
|
|
//
|
2020-07-03 00:46:06 +03:00
|
|
|
// NOTE: Part of peer.LinkUpdater interface.
|
2019-09-25 22:00:59 +03:00
|
|
|
func (c *UpdateFulfillHTLC) TargetChanID() ChannelID {
|
|
|
|
return c.ChanID
|
|
|
|
}
|