update_fee.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package lnwire
  2. import (
  3. "bytes"
  4. "io"
  5. )
  6. // UpdateFee is the message the channel initiator sends to the other peer if
  7. // the channel commitment fee needs to be updated.
  8. type UpdateFee struct {
  9. // ChanID is the channel that this UpdateFee is meant for.
  10. ChanID ChannelID
  11. // FeePerKw is the fee-per-kw on commit transactions that the sender of
  12. // this message wants to use for this channel.
  13. //
  14. // TODO(halseth): make SatPerKWeight when fee estimation is moved to
  15. // own package. Currently this will cause an import cycle.
  16. FeePerKw uint32
  17. // ExtraData is the set of data that was appended to this message to
  18. // fill out the full maximum transport message size. These fields can
  19. // be used to specify optional data such as custom TLV fields.
  20. ExtraData ExtraOpaqueData
  21. }
  22. // NewUpdateFee creates a new UpdateFee message.
  23. func NewUpdateFee(chanID ChannelID, feePerKw uint32) *UpdateFee {
  24. return &UpdateFee{
  25. ChanID: chanID,
  26. FeePerKw: feePerKw,
  27. }
  28. }
  29. // A compile time check to ensure UpdateFee implements the lnwire.Message
  30. // interface.
  31. var _ Message = (*UpdateFee)(nil)
  32. // Decode deserializes a serialized UpdateFee message stored in the passed
  33. // io.Reader observing the specified protocol version.
  34. //
  35. // This is part of the lnwire.Message interface.
  36. func (c *UpdateFee) Decode(r io.Reader, pver uint32) error {
  37. return ReadElements(r,
  38. &c.ChanID,
  39. &c.FeePerKw,
  40. &c.ExtraData,
  41. )
  42. }
  43. // Encode serializes the target UpdateFee into the passed io.Writer
  44. // observing the protocol version specified.
  45. //
  46. // This is part of the lnwire.Message interface.
  47. func (c *UpdateFee) Encode(w *bytes.Buffer, pver uint32) error {
  48. if err := WriteChannelID(w, c.ChanID); err != nil {
  49. return err
  50. }
  51. if err := WriteUint32(w, c.FeePerKw); err != nil {
  52. return err
  53. }
  54. return WriteBytes(w, c.ExtraData)
  55. }
  56. // MsgType returns the integer uniquely identifying this message type on the
  57. // wire.
  58. //
  59. // This is part of the lnwire.Message interface.
  60. func (c *UpdateFee) MsgType() MessageType {
  61. return MsgUpdateFee
  62. }
  63. // TargetChanID returns the channel id of the link for which this message is
  64. // intended.
  65. //
  66. // NOTE: Part of peer.LinkUpdater interface.
  67. func (c *UpdateFee) TargetChanID() ChannelID {
  68. return c.ChanID
  69. }