2017-02-16 20:34:09 +08:00
|
|
|
package lnwire
|
|
|
|
|
2019-09-25 12:00:59 -07:00
|
|
|
import (
|
2021-06-17 14:17:30 +08:00
|
|
|
"bytes"
|
2019-09-25 12:00:59 -07:00
|
|
|
"io"
|
|
|
|
)
|
2017-02-16 20:34:09 +08:00
|
|
|
|
2018-02-07 04:11:11 +01:00
|
|
|
// UpdateFulfillHTLC is sent by Alice to Bob when she wishes to settle a
|
2017-02-16 20:34:09 +08: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 04:11:11 +01:00
|
|
|
type UpdateFulfillHTLC struct {
|
2017-04-16 15:22:20 -07:00
|
|
|
// ChanID references an active channel which holds the HTLC to be
|
2017-02-16 20:34:09 +08:00
|
|
|
// settled.
|
2017-04-16 15:22:20 -07:00
|
|
|
ChanID ChannelID
|
2017-02-16 20:34:09 +08: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
|
2020-01-27 17:25:36 -08:00
|
|
|
|
2024-05-03 16:22:05 +01:00
|
|
|
// CustomRecords maps TLV types to byte slices, storing arbitrary data
|
|
|
|
// intended for inclusion in the ExtraData field.
|
|
|
|
CustomRecords CustomRecords
|
|
|
|
|
2020-01-27 17:25:36 -08:00
|
|
|
// ExtraData is the set of data that was appended to this message to
|
|
|
|
// fill out the full maximum transport message size. These fields can
|
|
|
|
// be used to specify optional data such as custom TLV fields.
|
|
|
|
ExtraData ExtraOpaqueData
|
2017-02-16 20:34:09 +08:00
|
|
|
}
|
|
|
|
|
2018-02-07 04:11:11 +01:00
|
|
|
// NewUpdateFulfillHTLC returns a new empty UpdateFulfillHTLC.
|
|
|
|
func NewUpdateFulfillHTLC(chanID ChannelID, id uint64,
|
|
|
|
preimage [32]byte) *UpdateFulfillHTLC {
|
2017-02-16 20:34:09 +08:00
|
|
|
|
2018-02-07 04:11:11 +01:00
|
|
|
return &UpdateFulfillHTLC{
|
2017-04-16 15:22:20 -07:00
|
|
|
ChanID: chanID,
|
2017-02-16 20:34:09 +08:00
|
|
|
ID: id,
|
|
|
|
PaymentPreimage: preimage,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-07 04:11:11 +01:00
|
|
|
// A compile time check to ensure UpdateFulfillHTLC implements the lnwire.Message
|
2017-02-16 20:34:09 +08:00
|
|
|
// interface.
|
2018-02-07 04:11:11 +01:00
|
|
|
var _ Message = (*UpdateFulfillHTLC)(nil)
|
2017-02-16 20:34:09 +08:00
|
|
|
|
2018-02-07 04:11:11 +01:00
|
|
|
// Decode deserializes a serialized UpdateFulfillHTLC message stored in the passed
|
2017-02-16 20:34:09 +08:00
|
|
|
// io.Reader observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2018-02-07 04:11:11 +01:00
|
|
|
func (c *UpdateFulfillHTLC) Decode(r io.Reader, pver uint32) error {
|
2024-05-03 16:22:05 +01:00
|
|
|
// msgExtraData is a temporary variable used to read the message extra
|
|
|
|
// data field from the reader.
|
|
|
|
var msgExtraData ExtraOpaqueData
|
|
|
|
|
|
|
|
if err := ReadElements(r,
|
2017-04-16 15:22:20 -07:00
|
|
|
&c.ChanID,
|
2017-02-16 20:34:09 +08:00
|
|
|
&c.ID,
|
|
|
|
c.PaymentPreimage[:],
|
2024-05-03 16:22:05 +01:00
|
|
|
&msgExtraData,
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract custom records from the extra data field.
|
|
|
|
customRecords, _, extraData, err := ParseAndExtractCustomRecords(
|
|
|
|
msgExtraData,
|
2017-02-16 20:34:09 +08:00
|
|
|
)
|
2024-05-03 16:22:05 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
c.CustomRecords = customRecords
|
|
|
|
c.ExtraData = extraData
|
|
|
|
|
|
|
|
return nil
|
2017-02-16 20:34:09 +08:00
|
|
|
}
|
|
|
|
|
2018-02-07 04:11:11 +01:00
|
|
|
// Encode serializes the target UpdateFulfillHTLC into the passed io.Writer
|
2017-02-16 20:34:09 +08:00
|
|
|
// observing the protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2021-06-17 14:17:30 +08:00
|
|
|
func (c *UpdateFulfillHTLC) Encode(w *bytes.Buffer, pver uint32) error {
|
2021-06-18 15:15:44 +08:00
|
|
|
if err := WriteChannelID(w, c.ChanID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteUint64(w, c.ID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteBytes(w, c.PaymentPreimage[:]); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-05-03 16:22:05 +01:00
|
|
|
// Combine the custom records and the extra data, then encode the
|
|
|
|
// result as a byte slice.
|
|
|
|
extraData, err := MergeAndEncode(nil, c.ExtraData, c.CustomRecords)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return WriteBytes(w, extraData)
|
2017-02-16 20:34:09 +08:00
|
|
|
}
|
|
|
|
|
2017-04-19 15:57:43 -07:00
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
2017-02-16 20:34:09 +08:00
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2018-02-07 04:11:11 +01:00
|
|
|
func (c *UpdateFulfillHTLC) MsgType() MessageType {
|
|
|
|
return MsgUpdateFulfillHTLC
|
2017-02-16 20:34:09 +08:00
|
|
|
}
|
|
|
|
|
2019-09-25 12:00:59 -07:00
|
|
|
// TargetChanID returns the channel id of the link for which this message is
|
|
|
|
// intended.
|
|
|
|
//
|
2020-07-02 17:46:06 -04:00
|
|
|
// NOTE: Part of peer.LinkUpdater interface.
|
2019-09-25 12:00:59 -07:00
|
|
|
func (c *UpdateFulfillHTLC) TargetChanID() ChannelID {
|
|
|
|
return c.ChanID
|
|
|
|
}
|