mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 06:07:16 +01:00
zpay32: move HopHint and DefaultFinalCLTVDelta
This commit is contained in:
31
zpay32/hophint.go
Normal file
31
zpay32/hophint.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package zpay32
|
||||
|
||||
import "github.com/btcsuite/btcd/btcec"
|
||||
|
||||
const (
|
||||
// DefaultFinalCLTVDelta is the default value to be used as the final
|
||||
// CLTV delta for a route if one is unspecified.
|
||||
DefaultFinalCLTVDelta = 9
|
||||
)
|
||||
|
||||
// HopHint is a routing hint that contains the minimum information of a channel
|
||||
// required for an intermediate hop in a route to forward the payment to the
|
||||
// next. This should be ideally used for private channels, since they are not
|
||||
// publicly advertised to the network for routing.
|
||||
type HopHint struct {
|
||||
// NodeID is the public key of the node at the start of the channel.
|
||||
NodeID *btcec.PublicKey
|
||||
|
||||
// ChannelID is the unique identifier of the channel.
|
||||
ChannelID uint64
|
||||
|
||||
// FeeBaseMSat is the base fee of the channel in millisatoshis.
|
||||
FeeBaseMSat uint32
|
||||
|
||||
// FeeProportionalMillionths is the fee rate, in millionths of a
|
||||
// satoshi, for every satoshi sent through the channel.
|
||||
FeeProportionalMillionths uint32
|
||||
|
||||
// CLTVExpiryDelta is the time-lock delta of the channel.
|
||||
CLTVExpiryDelta uint16
|
||||
}
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/btcsuite/btcutil/bech32"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -146,7 +145,7 @@ type Invoice struct {
|
||||
// represent private routes.
|
||||
//
|
||||
// NOTE: This is optional.
|
||||
RouteHints [][]routing.HopHint
|
||||
RouteHints [][]HopHint
|
||||
}
|
||||
|
||||
// Amount is a functional option that allows callers of NewInvoice to set the
|
||||
@@ -214,7 +213,7 @@ func FallbackAddr(fallbackAddr btcutil.Address) func(*Invoice) {
|
||||
|
||||
// RouteHint is a functional option that allows callers of NewInvoice to add
|
||||
// one or more hop hints that represent a private route to the destination.
|
||||
func RouteHint(routeHint []routing.HopHint) func(*Invoice) {
|
||||
func RouteHint(routeHint []HopHint) func(*Invoice) {
|
||||
return func(i *Invoice) {
|
||||
i.RouteHints = append(i.RouteHints, routeHint)
|
||||
}
|
||||
@@ -476,7 +475,7 @@ func (invoice *Invoice) MinFinalCLTVExpiry() uint64 {
|
||||
return *invoice.minFinalCLTVExpiry
|
||||
}
|
||||
|
||||
return routing.DefaultFinalCLTVDelta
|
||||
return DefaultFinalCLTVDelta
|
||||
}
|
||||
|
||||
// validateInvoice does a sanity check of the provided Invoice, making sure it
|
||||
@@ -843,7 +842,7 @@ func parseFallbackAddr(data []byte, net *chaincfg.Params) (btcutil.Address, erro
|
||||
|
||||
// parseRouteHint converts the data (encoded in base32) into an array containing
|
||||
// one or more routing hop hints that represent a single route hint.
|
||||
func parseRouteHint(data []byte) ([]routing.HopHint, error) {
|
||||
func parseRouteHint(data []byte) ([]HopHint, error) {
|
||||
base256Data, err := bech32.ConvertBits(data, 5, 8, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -854,10 +853,10 @@ func parseRouteHint(data []byte) ([]routing.HopHint, error) {
|
||||
"got %d", hopHintLen, len(base256Data))
|
||||
}
|
||||
|
||||
var routeHint []routing.HopHint
|
||||
var routeHint []HopHint
|
||||
|
||||
for len(base256Data) > 0 {
|
||||
hopHint := routing.HopHint{}
|
||||
hopHint := HopHint{}
|
||||
hopHint.NodeID, err = btcec.ParsePubKey(base256Data[:33], btcec.S256())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/btcsuite/btcutil/bech32"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
)
|
||||
|
||||
// TestDecodeAmount ensures that the amount string in the hrp of the Invoice
|
||||
@@ -738,7 +737,7 @@ func TestParseRouteHint(t *testing.T) {
|
||||
tests := []struct {
|
||||
data []byte
|
||||
valid bool
|
||||
result []routing.HopHint
|
||||
result []HopHint
|
||||
}{
|
||||
{
|
||||
data: []byte{0x0, 0x0, 0x0, 0x0},
|
||||
@@ -747,7 +746,7 @@ func TestParseRouteHint(t *testing.T) {
|
||||
{
|
||||
data: []byte{},
|
||||
valid: true,
|
||||
result: []routing.HopHint{},
|
||||
result: []HopHint{},
|
||||
},
|
||||
{
|
||||
data: testSingleHopData,
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
|
||||
litecoinCfg "github.com/ltcsuite/ltcd/chaincfg"
|
||||
)
|
||||
@@ -53,7 +52,7 @@ var (
|
||||
testHopHintPubkeyBytes2, _ = hex.DecodeString("039e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c77255")
|
||||
testHopHintPubkey2, _ = btcec.ParsePubKey(testHopHintPubkeyBytes2, btcec.S256())
|
||||
|
||||
testSingleHop = []routing.HopHint{
|
||||
testSingleHop = []HopHint{
|
||||
{
|
||||
NodeID: testHopHintPubkey1,
|
||||
ChannelID: 0x0102030405060708,
|
||||
@@ -62,7 +61,7 @@ var (
|
||||
CLTVExpiryDelta: 3,
|
||||
},
|
||||
}
|
||||
testDoubleHop = []routing.HopHint{
|
||||
testDoubleHop = []HopHint{
|
||||
{
|
||||
NodeID: testHopHintPubkey1,
|
||||
ChannelID: 0x0102030405060708,
|
||||
@@ -414,7 +413,7 @@ func TestDecodeEncode(t *testing.T) {
|
||||
DescriptionHash: &testDescriptionHash,
|
||||
Destination: testPubKey,
|
||||
FallbackAddr: testRustyAddr,
|
||||
RouteHints: [][]routing.HopHint{testSingleHop},
|
||||
RouteHints: [][]HopHint{testSingleHop},
|
||||
}
|
||||
},
|
||||
beforeEncoding: func(i *Invoice) {
|
||||
@@ -437,7 +436,7 @@ func TestDecodeEncode(t *testing.T) {
|
||||
DescriptionHash: &testDescriptionHash,
|
||||
Destination: testPubKey,
|
||||
FallbackAddr: testRustyAddr,
|
||||
RouteHints: [][]routing.HopHint{testDoubleHop},
|
||||
RouteHints: [][]HopHint{testDoubleHop},
|
||||
}
|
||||
},
|
||||
beforeEncoding: func(i *Invoice) {
|
||||
@@ -844,7 +843,7 @@ func compareHashes(a, b *[32]byte) bool {
|
||||
return bytes.Equal(a[:], b[:])
|
||||
}
|
||||
|
||||
func compareRouteHints(a, b []routing.HopHint) error {
|
||||
func compareRouteHints(a, b []HopHint) error {
|
||||
if len(a) != len(b) {
|
||||
return fmt.Errorf("expected len routingInfo %d, got %d",
|
||||
len(a), len(b))
|
||||
|
||||
Reference in New Issue
Block a user