2017-07-14 20:28:40 +02:00
|
|
|
package lnwire
|
|
|
|
|
2018-02-23 10:55:51 +01:00
|
|
|
import (
|
2021-06-17 08:17:30 +02:00
|
|
|
"bytes"
|
2018-02-23 10:55:51 +01:00
|
|
|
"io"
|
|
|
|
)
|
2017-07-14 20:28:40 +02:00
|
|
|
|
|
|
|
// UpdateFee is the message the channel initiator sends to the other peer if
|
|
|
|
// the channel commitment fee needs to be updated.
|
|
|
|
type UpdateFee struct {
|
|
|
|
// ChanID is the channel that this UpdateFee is meant for.
|
|
|
|
ChanID ChannelID
|
|
|
|
|
|
|
|
// FeePerKw is the fee-per-kw on commit transactions that the sender of
|
|
|
|
// this message wants to use for this channel.
|
2018-02-23 10:55:51 +01:00
|
|
|
//
|
|
|
|
// TODO(halseth): make SatPerKWeight when fee estimation is moved to
|
|
|
|
// own package. Currently this will cause an import cycle.
|
2017-12-01 07:07:42 +01:00
|
|
|
FeePerKw uint32
|
2020-01-28 02:25:36 +01: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-07-14 20:28:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewUpdateFee creates a new UpdateFee message.
|
2017-12-01 07:07:42 +01:00
|
|
|
func NewUpdateFee(chanID ChannelID, feePerKw uint32) *UpdateFee {
|
2017-07-14 20:28:40 +02:00
|
|
|
return &UpdateFee{
|
|
|
|
ChanID: chanID,
|
|
|
|
FeePerKw: feePerKw,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time check to ensure UpdateFee implements the lnwire.Message
|
|
|
|
// interface.
|
|
|
|
var _ Message = (*UpdateFee)(nil)
|
|
|
|
|
2017-07-15 02:10:29 +02:00
|
|
|
// Decode deserializes a serialized UpdateFee message stored in the passed
|
|
|
|
// io.Reader observing the specified protocol version.
|
2017-07-14 20:28:40 +02:00
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *UpdateFee) Decode(r io.Reader, pver uint32) error {
|
2018-12-10 03:27:41 +01:00
|
|
|
return ReadElements(r,
|
2017-07-14 20:28:40 +02:00
|
|
|
&c.ChanID,
|
|
|
|
&c.FeePerKw,
|
2020-01-28 02:25:36 +01:00
|
|
|
&c.ExtraData,
|
2017-07-14 20:28:40 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode serializes the target UpdateFee into the passed io.Writer
|
|
|
|
// observing the protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2021-06-17 08:17:30 +02:00
|
|
|
func (c *UpdateFee) Encode(w *bytes.Buffer, pver uint32) error {
|
2018-12-10 03:27:41 +01:00
|
|
|
return WriteElements(w,
|
2017-07-14 20:28:40 +02:00
|
|
|
c.ChanID,
|
|
|
|
c.FeePerKw,
|
2020-01-28 02:25:36 +01:00
|
|
|
c.ExtraData,
|
2017-07-14 20:28:40 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *UpdateFee) MsgType() MessageType {
|
|
|
|
return MsgUpdateFee
|
|
|
|
}
|
|
|
|
|
2019-09-25 21:00:59 +02:00
|
|
|
// TargetChanID returns the channel id of the link for which this message is
|
|
|
|
// intended.
|
|
|
|
//
|
2020-07-02 23:46:06 +02:00
|
|
|
// NOTE: Part of peer.LinkUpdater interface.
|
2019-09-25 21:00:59 +02:00
|
|
|
func (c *UpdateFee) TargetChanID() ChannelID {
|
|
|
|
return c.ChanID
|
|
|
|
}
|