github.com/decred/dcrlnd@v0.7.6/record/hop.go (about) 1 package record 2 3 import ( 4 "github.com/decred/dcrlnd/tlv" 5 ) 6 7 const ( 8 // AmtOnionType is the type used in the onion to refrence the amount to 9 // send to the next hop. 10 AmtOnionType tlv.Type = 2 11 12 // LockTimeTLV is the type used in the onion to refenernce the CLTV 13 // value that should be used for the next hop's HTLC. 14 LockTimeOnionType tlv.Type = 4 15 16 // NextHopOnionType is the type used in the onion to reference the ID 17 // of the next hop. 18 NextHopOnionType tlv.Type = 6 19 ) 20 21 // NewAmtToFwdRecord creates a tlv.Record that encodes the amount_to_forward 22 // (type 2) for an onion payload. 23 func NewAmtToFwdRecord(amt *uint64) tlv.Record { 24 return tlv.MakeDynamicRecord( 25 AmtOnionType, amt, func() uint64 { 26 return tlv.SizeTUint64(*amt) 27 }, 28 tlv.ETUint64, tlv.DTUint64, 29 ) 30 } 31 32 // NewLockTimeRecord creates a tlv.Record that encodes the outgoing_cltv_value 33 // (type 4) for an onion payload. 34 func NewLockTimeRecord(lockTime *uint32) tlv.Record { 35 return tlv.MakeDynamicRecord( 36 LockTimeOnionType, lockTime, func() uint64 { 37 return tlv.SizeTUint32(*lockTime) 38 }, 39 tlv.ETUint32, tlv.DTUint32, 40 ) 41 } 42 43 // NewNextHopIDRecord creates a tlv.Record that encodes the short_channel_id 44 // (type 6) for an onion payload. 45 func NewNextHopIDRecord(cid *uint64) tlv.Record { 46 return tlv.MakePrimitiveRecord(NextHopOnionType, cid) 47 }