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