2017-02-16 13:34:09 +01:00
|
|
|
package lnwire
|
|
|
|
|
2017-04-17 00:22:20 +02:00
|
|
|
import "io"
|
2017-02-16 13:34:09 +01:00
|
|
|
|
|
|
|
// UpdateFufillHTLC is sent by Alice to Bob when she wishes to settle a
|
|
|
|
// 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.
|
|
|
|
type UpdateFufillHTLC struct {
|
2017-04-17 00:22:20 +02:00
|
|
|
// ChanID references an active channel which holds the HTLC to be
|
2017-02-16 13:34:09 +01:00
|
|
|
// settled.
|
2017-04-17 00:22:20 +02:00
|
|
|
ChanID ChannelID
|
2017-02-16 13:34:09 +01: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
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewUpdateFufillHTLC returns a new empty UpdateFufillHTLC.
|
2017-04-17 00:22:20 +02:00
|
|
|
func NewUpdateFufillHTLC(chanID ChannelID, id uint64,
|
2017-02-16 13:34:09 +01:00
|
|
|
preimage [32]byte) *UpdateFufillHTLC {
|
|
|
|
|
|
|
|
return &UpdateFufillHTLC{
|
2017-04-17 00:22:20 +02:00
|
|
|
ChanID: chanID,
|
2017-02-16 13:34:09 +01:00
|
|
|
ID: id,
|
|
|
|
PaymentPreimage: preimage,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time check to ensure UpdateFufillHTLC implements the lnwire.Message
|
|
|
|
// interface.
|
|
|
|
var _ Message = (*UpdateFufillHTLC)(nil)
|
|
|
|
|
|
|
|
// Decode deserializes a serialized UpdateFufillHTLC message stored in the passed
|
|
|
|
// io.Reader observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *UpdateFufillHTLC) Decode(r io.Reader, pver uint32) error {
|
2017-02-23 19:59:50 +01:00
|
|
|
return readElements(r,
|
2017-04-17 00:22:20 +02:00
|
|
|
&c.ChanID,
|
2017-02-16 13:34:09 +01:00
|
|
|
&c.ID,
|
|
|
|
c.PaymentPreimage[:],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode serializes the target UpdateFufillHTLC into the passed io.Writer
|
|
|
|
// observing the protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *UpdateFufillHTLC) Encode(w io.Writer, pver uint32) error {
|
2017-02-23 19:59:50 +01:00
|
|
|
return writeElements(w,
|
2017-04-17 00:22:20 +02:00
|
|
|
c.ChanID,
|
2017-02-16 13:34:09 +01:00
|
|
|
c.ID,
|
|
|
|
c.PaymentPreimage[:],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:57:43 +02:00
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
2017-02-16 13:34:09 +01:00
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-20 00:57:43 +02:00
|
|
|
func (c *UpdateFufillHTLC) MsgType() MessageType {
|
|
|
|
return MsgUpdateFufillHTLC
|
2017-02-16 13:34:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// MaxPayloadLength returns the maximum allowed payload size for a UpdateFufillHTLC
|
|
|
|
// complete message observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *UpdateFufillHTLC) MaxPayloadLength(uint32) uint32 {
|
2017-04-17 00:22:20 +02:00
|
|
|
// 32 + 8 + 32
|
|
|
|
return 72
|
2017-02-16 13:34:09 +01:00
|
|
|
}
|