github.com/decred/dcrlnd@v0.7.6/channeldb/migration/lnwire21/update_fulfill_htlc.go (about) 1 package lnwire 2 3 import ( 4 "io" 5 ) 6 7 // UpdateFulfillHTLC is sent by Alice to Bob when she wishes to settle a 8 // particular HTLC referenced by its HTLCKey within a specific active channel 9 // referenced by ChannelPoint. A subsequent CommitSig message will be sent by 10 // Alice to "lock-in" the removal of the specified HTLC, possible containing a 11 // batch signature covering several settled HTLC's. 12 type UpdateFulfillHTLC struct { 13 // ChanID references an active channel which holds the HTLC to be 14 // settled. 15 ChanID ChannelID 16 17 // ID denotes the exact HTLC stage within the receiving node's 18 // commitment transaction to be removed. 19 ID uint64 20 21 // PaymentPreimage is the R-value preimage required to fully settle an 22 // HTLC. 23 PaymentPreimage [32]byte 24 } 25 26 // NewUpdateFulfillHTLC returns a new empty UpdateFulfillHTLC. 27 func NewUpdateFulfillHTLC(chanID ChannelID, id uint64, 28 preimage [32]byte) *UpdateFulfillHTLC { 29 30 return &UpdateFulfillHTLC{ 31 ChanID: chanID, 32 ID: id, 33 PaymentPreimage: preimage, 34 } 35 } 36 37 // A compile time check to ensure UpdateFulfillHTLC implements the lnwire.Message 38 // interface. 39 var _ Message = (*UpdateFulfillHTLC)(nil) 40 41 // Decode deserializes a serialized UpdateFulfillHTLC message stored in the passed 42 // io.Reader observing the specified protocol version. 43 // 44 // This is part of the lnwire.Message interface. 45 func (c *UpdateFulfillHTLC) Decode(r io.Reader, pver uint32) error { 46 return ReadElements(r, 47 &c.ChanID, 48 &c.ID, 49 c.PaymentPreimage[:], 50 ) 51 } 52 53 // Encode serializes the target UpdateFulfillHTLC into the passed io.Writer 54 // observing the protocol version specified. 55 // 56 // This is part of the lnwire.Message interface. 57 func (c *UpdateFulfillHTLC) Encode(w io.Writer, pver uint32) error { 58 return WriteElements(w, 59 c.ChanID, 60 c.ID, 61 c.PaymentPreimage[:], 62 ) 63 } 64 65 // MsgType returns the integer uniquely identifying this message type on the 66 // wire. 67 // 68 // This is part of the lnwire.Message interface. 69 func (c *UpdateFulfillHTLC) MsgType() MessageType { 70 return MsgUpdateFulfillHTLC 71 } 72 73 // MaxPayloadLength returns the maximum allowed payload size for an UpdateFulfillHTLC 74 // complete message observing the specified protocol version. 75 // 76 // This is part of the lnwire.Message interface. 77 func (c *UpdateFulfillHTLC) MaxPayloadLength(uint32) uint32 { 78 // 32 + 8 + 32 79 return 72 80 } 81 82 // TargetChanID returns the channel id of the link for which this message is 83 // intended. 84 // 85 // NOTE: Part of peer.LinkUpdater interface. 86 func (c *UpdateFulfillHTLC) TargetChanID() ChannelID { 87 return c.ChanID 88 }