From 5b797055f85620278715330490b9623ba2174b9b Mon Sep 17 00:00:00 2001 From: Slyghtning Date: Fri, 14 Jun 2024 12:37:58 +0200 Subject: [PATCH] utils: refactor SelectHopHints to use narrower interface --- client.go | 3 ++- loopin.go | 4 ++-- utils.go | 25 ++++++++++++------------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/client.go b/client.go index 7f350b85..504fcb67 100644 --- a/client.go +++ b/client.go @@ -683,7 +683,8 @@ func (s *Client) LoopInQuote(ctx context.Context, // Because the Private flag is set, we'll generate our own // set of hop hints and use that request.RouteHints, err = SelectHopHints( - ctx, s.lndServices, request.Amount, DefaultMaxHopHints, includeNodes, + ctx, s.lndServices.Client, request.Amount, + DefaultMaxHopHints, includeNodes, ) if err != nil { return nil, err diff --git a/loopin.go b/loopin.go index 5fc40a18..b72d1795 100644 --- a/loopin.go +++ b/loopin.go @@ -111,8 +111,8 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig, // Because the Private flag is set, we'll generate our own set // of hop hints. request.RouteHints, err = SelectHopHints( - globalCtx, cfg.lnd, request.Amount, DefaultMaxHopHints, - includeNodes, + globalCtx, cfg.lnd.Client, request.Amount, + DefaultMaxHopHints, includeNodes, ) if err != nil { return nil, err diff --git a/utils.go b/utils.go index cacff5c7..4fd9800f 100644 --- a/utils.go +++ b/utils.go @@ -30,30 +30,29 @@ var ( // isPublicNode checks if a node is public, by simply checking if there's any // channels reported to the node. -func isPublicNode(ctx context.Context, lnd *lndclient.LndServices, +func isPublicNode(ctx context.Context, lndClient lndclient.LightningClient, pubKey [33]byte) (bool, error) { // GetNodeInfo doesn't report our private channels with the queried node - // so we can use it to determine if the node is considered public. - nodeInfo, err := lnd.Client.GetNodeInfo( - ctx, pubKey, true, - ) + // so, we can use it to determine if the node is considered public. + nodeInfo, err := lndClient.GetNodeInfo(ctx, pubKey, true) if err != nil { return false, err } - return (nodeInfo.ChannelCount > 0), nil + return nodeInfo.ChannelCount > 0, nil } // fetchChannelEdgesByID fetches the edge info for the passed channel and // returns the channeldb structs filled with the data that is needed for // LND's SelectHopHints implementation. -func fetchChannelEdgesByID(ctx context.Context, lnd *lndclient.LndServices, - chanID uint64) (*models.ChannelEdgeInfo, *models.ChannelEdgePolicy, +func fetchChannelEdgesByID(ctx context.Context, + lndClient lndclient.LightningClient, chanID uint64) ( + *models.ChannelEdgeInfo, *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) { - chanInfo, err := lnd.Client.GetChanInfo(ctx, chanID) + chanInfo, err := lndClient.GetChanInfo(ctx, chanID) if err != nil { return nil, nil, nil, err } @@ -125,14 +124,14 @@ func getAlias(aliasCache map[lnwire.ChannelID]lnwire.ShortChannelID, // SelectHopHints calls into LND's exposed SelectHopHints prefiltered to the // includeNodes map (unless it's empty). -func SelectHopHints(ctx context.Context, lnd *lndclient.LndServices, +func SelectHopHints(ctx context.Context, lndClient lndclient.LightningClient, amt btcutil.Amount, numMaxHophints int, includeNodes map[route.Vertex]struct{}) ([][]zpay32.HopHint, error) { aliasCache := make(map[lnwire.ChannelID]lnwire.ShortChannelID) // Fetch all active and public channels. - channels, err := lnd.Client.ListChannels(ctx, false, false) + channels, err := lndClient.ListChannels(ctx, false, false) if err != nil { return nil, err } @@ -175,13 +174,13 @@ func SelectHopHints(ctx context.Context, lnd *lndclient.LndServices, cfg := &SelectHopHintsCfg{ IsPublicNode: func(pubKey [33]byte) (bool, error) { - return isPublicNode(ctx, lnd, pubKey) + return isPublicNode(ctx, lndClient, pubKey) }, FetchChannelEdgesByID: func(chanID uint64) ( *models.ChannelEdgeInfo, *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) { - return fetchChannelEdgesByID(ctx, lnd, chanID) + return fetchChannelEdgesByID(ctx, lndClient, chanID) }, GetAlias: func(id lnwire.ChannelID) ( lnwire.ShortChannelID, error) {