htlcswitch+routing: use TLV hop constructors
This commit is contained in:
parent
495f80e0bc
commit
dc0f429271
@ -9,6 +9,7 @@ import (
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
)
|
||||
|
||||
@ -175,15 +176,9 @@ func (r *sphinxHopIterator) ForwardingInstructions() (ForwardingInfo, error) {
|
||||
var cid uint64
|
||||
|
||||
tlvStream, err := tlv.NewStream(
|
||||
tlv.MakeDynamicRecord(
|
||||
tlv.AmtOnionType, &amt, nil,
|
||||
tlv.ETUint64, tlv.DTUint64,
|
||||
),
|
||||
tlv.MakeDynamicRecord(
|
||||
tlv.LockTimeOnionType, &cltv, nil,
|
||||
tlv.ETUint32, tlv.DTUint32,
|
||||
),
|
||||
tlv.MakePrimitiveRecord(tlv.NextHopOnionType, &cid),
|
||||
record.NewAmtToFwdRecord(&amt),
|
||||
record.NewLockTimeRecord(&cltv),
|
||||
record.NewNextHopIDRecord(&cid),
|
||||
)
|
||||
if err != nil {
|
||||
return ForwardingInfo{}, err
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
)
|
||||
|
||||
@ -38,19 +39,9 @@ func TestSphinxHopIteratorForwardingInstructions(t *testing.T) {
|
||||
// as we would normally in the routing network.
|
||||
var b bytes.Buffer
|
||||
tlvRecords := []tlv.Record{
|
||||
tlv.MakeDynamicRecord(
|
||||
tlv.AmtOnionType, &hopData.ForwardAmount, func() uint64 {
|
||||
return tlv.SizeTUint64(hopData.ForwardAmount)
|
||||
},
|
||||
tlv.ETUint64, tlv.DTUint64,
|
||||
),
|
||||
tlv.MakeDynamicRecord(
|
||||
tlv.LockTimeOnionType, &hopData.OutgoingCltv, func() uint64 {
|
||||
return tlv.SizeTUint32(hopData.OutgoingCltv)
|
||||
},
|
||||
tlv.ETUint32, tlv.DTUint32,
|
||||
),
|
||||
tlv.MakePrimitiveRecord(tlv.NextHopOnionType, &nextAddrInt),
|
||||
record.NewAmtToFwdRecord(&hopData.ForwardAmount),
|
||||
record.NewLockTimeRecord(&hopData.OutgoingCltv),
|
||||
record.NewNextHopIDRecord(&nextAddrInt),
|
||||
}
|
||||
tlvStream, err := tlv.NewStream(tlvRecords...)
|
||||
if err != nil {
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
)
|
||||
|
||||
@ -105,19 +106,9 @@ func (h *Hop) PackHopPayload(w io.Writer, nextChanID uint64) error {
|
||||
// required routing fields, as well as these optional values.
|
||||
amt := uint64(h.AmtToForward)
|
||||
combinedRecords := append(h.TLVRecords,
|
||||
tlv.MakeDynamicRecord(
|
||||
tlv.AmtOnionType, &amt, func() uint64 {
|
||||
return tlv.SizeTUint64(amt)
|
||||
},
|
||||
tlv.ETUint64, tlv.DTUint64,
|
||||
),
|
||||
tlv.MakeDynamicRecord(
|
||||
tlv.LockTimeOnionType, &h.OutgoingTimeLock, func() uint64 {
|
||||
return tlv.SizeTUint32(h.OutgoingTimeLock)
|
||||
},
|
||||
tlv.ETUint32, tlv.DTUint32,
|
||||
),
|
||||
tlv.MakePrimitiveRecord(tlv.NextHopOnionType, &nextChanID),
|
||||
record.NewAmtToFwdRecord(&amt),
|
||||
record.NewLockTimeRecord(&h.OutgoingTimeLock),
|
||||
record.NewNextHopIDRecord(&nextChanID),
|
||||
)
|
||||
|
||||
// To ensure we produce a canonical stream, we'll sort the records
|
||||
|
Loading…
Reference in New Issue
Block a user