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