record/hop: add primitive hop TLV record constructors

This commit is contained in:
Conner Fromknecht 2019-08-30 01:40:47 -07:00
parent c397a2ea78
commit 495f80e0bc
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

33
record/hop.go Normal file

@ -0,0 +1,33 @@
package record
import (
"github.com/lightningnetwork/lnd/tlv"
)
// NewAmtToFwdRecord creates a tlv.Record that encodes the amount_to_forward
// (type 2) for an onion payload.
func NewAmtToFwdRecord(amt *uint64) tlv.Record {
return tlv.MakeDynamicRecord(
tlv.AmtOnionType, amt, func() uint64 {
return tlv.SizeTUint64(*amt)
},
tlv.ETUint64, tlv.DTUint64,
)
}
// NewLockTimeRecord creates a tlv.Record that encodes the outgoing_cltv_value
// (type 4) for an onion payload.
func NewLockTimeRecord(lockTime *uint32) tlv.Record {
return tlv.MakeDynamicRecord(
tlv.LockTimeOnionType, lockTime, func() uint64 {
return tlv.SizeTUint32(*lockTime)
},
tlv.ETUint32, tlv.DTUint32,
)
}
// NewNextHopIDRecord creates a tlv.Record that encodes the short_channel_id
// (type 6) for an onion payload.
func NewNextHopIDRecord(cid *uint64) tlv.Record {
return tlv.MakePrimitiveRecord(tlv.NextHopOnionType, cid)
}