From 9af6576dae3e8283aece30493acb794c981a71a2 Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Thu, 27 May 2021 17:42:07 +0200 Subject: [PATCH] cli: add optional last hop to the loop in quote --- cmd/loop/loopin.go | 32 ++++++++++++++++++-------------- cmd/loop/quote.go | 27 ++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/cmd/loop/loopin.go b/cmd/loop/loopin.go index 6049fd4..cbeec12 100644 --- a/cmd/loop/loopin.go +++ b/cmd/loop/loopin.go @@ -109,11 +109,25 @@ func loopIn(ctx *cli.Context) error { return err } + var lastHop []byte + if ctx.IsSet(lastHopFlag.Name) { + lastHopVertex, err := route.NewVertexFromStr( + ctx.String(lastHopFlag.Name), + ) + if err != nil { + return err + } + + lastHop = lastHopVertex[:] + } + quoteReq := &looprpc.QuoteRequest{ - Amt: int64(amt), - ConfTarget: htlcConfTarget, - ExternalHtlc: external, + Amt: int64(amt), + ConfTarget: htlcConfTarget, + ExternalHtlc: external, + LoopInLastHop: lastHop, } + quote, err := client.GetLoopInQuote(context.Background(), quoteReq) if err != nil { return err @@ -147,17 +161,7 @@ func loopIn(ctx *cli.Context) error { HtlcConfTarget: htlcConfTarget, Label: label, Initiator: defaultInitiator, - } - - if ctx.IsSet(lastHopFlag.Name) { - lastHop, err := route.NewVertexFromStr( - ctx.String(lastHopFlag.Name), - ) - if err != nil { - return err - } - - req.LastHop = lastHop[:] + LastHop: lastHop, } resp, err := client.LoopIn(context.Background(), req) diff --git a/cmd/loop/quote.go b/cmd/loop/quote.go index 40c03af..9f8a6c0 100644 --- a/cmd/loop/quote.go +++ b/cmd/loop/quote.go @@ -8,6 +8,7 @@ import ( "github.com/lightninglabs/loop" "github.com/lightninglabs/loop/looprpc" + "github.com/lightningnetwork/lnd/routing/route" "github.com/urfave/cli" ) @@ -22,8 +23,16 @@ var quoteInCommand = cli.Command{ Usage: "get a quote for the cost of a loop in swap", ArgsUsage: "amt", Description: "Allows to determine the cost of a swap up front", - Flags: []cli.Flag{confTargetFlag, verboseFlag}, - Action: quoteIn, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: lastHopFlag.Name, + Usage: "the pubkey of the last hop to use for the " + + "quote", + }, + confTargetFlag, + verboseFlag, + }, + Action: quoteIn, } func quoteIn(ctx *cli.Context) error { @@ -44,11 +53,23 @@ func quoteIn(ctx *cli.Context) error { } defer cleanup() - ctxb := context.Background() quoteReq := &looprpc.QuoteRequest{ Amt: int64(amt), ConfTarget: int32(ctx.Uint64("conf_target")), } + + if ctx.IsSet(lastHopFlag.Name) { + lastHopVertex, err := route.NewVertexFromStr( + ctx.String(lastHopFlag.Name), + ) + if err != nil { + return err + } + + quoteReq.LoopInLastHop = lastHopVertex[:] + } + + ctxb := context.Background() quoteResp, err := client.GetLoopInQuote(ctxb, quoteReq) if err != nil { return err