Skip to content

Commit 9af6576

Browse files
committed
cli: add optional last hop to the loop in quote
1 parent 0e7ed91 commit 9af6576

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

cmd/loop/loopin.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,25 @@ func loopIn(ctx *cli.Context) error {
109109
return err
110110
}
111111

112+
var lastHop []byte
113+
if ctx.IsSet(lastHopFlag.Name) {
114+
lastHopVertex, err := route.NewVertexFromStr(
115+
ctx.String(lastHopFlag.Name),
116+
)
117+
if err != nil {
118+
return err
119+
}
120+
121+
lastHop = lastHopVertex[:]
122+
}
123+
112124
quoteReq := &looprpc.QuoteRequest{
113-
Amt: int64(amt),
114-
ConfTarget: htlcConfTarget,
115-
ExternalHtlc: external,
125+
Amt: int64(amt),
126+
ConfTarget: htlcConfTarget,
127+
ExternalHtlc: external,
128+
LoopInLastHop: lastHop,
116129
}
130+
117131
quote, err := client.GetLoopInQuote(context.Background(), quoteReq)
118132
if err != nil {
119133
return err
@@ -147,17 +161,7 @@ func loopIn(ctx *cli.Context) error {
147161
HtlcConfTarget: htlcConfTarget,
148162
Label: label,
149163
Initiator: defaultInitiator,
150-
}
151-
152-
if ctx.IsSet(lastHopFlag.Name) {
153-
lastHop, err := route.NewVertexFromStr(
154-
ctx.String(lastHopFlag.Name),
155-
)
156-
if err != nil {
157-
return err
158-
}
159-
160-
req.LastHop = lastHop[:]
164+
LastHop: lastHop,
161165
}
162166

163167
resp, err := client.LoopIn(context.Background(), req)

cmd/loop/quote.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/lightninglabs/loop"
1010
"github.com/lightninglabs/loop/looprpc"
11+
"github.com/lightningnetwork/lnd/routing/route"
1112
"github.com/urfave/cli"
1213
)
1314

@@ -22,8 +23,16 @@ var quoteInCommand = cli.Command{
2223
Usage: "get a quote for the cost of a loop in swap",
2324
ArgsUsage: "amt",
2425
Description: "Allows to determine the cost of a swap up front",
25-
Flags: []cli.Flag{confTargetFlag, verboseFlag},
26-
Action: quoteIn,
26+
Flags: []cli.Flag{
27+
cli.StringFlag{
28+
Name: lastHopFlag.Name,
29+
Usage: "the pubkey of the last hop to use for the " +
30+
"quote",
31+
},
32+
confTargetFlag,
33+
verboseFlag,
34+
},
35+
Action: quoteIn,
2736
}
2837

2938
func quoteIn(ctx *cli.Context) error {
@@ -44,11 +53,23 @@ func quoteIn(ctx *cli.Context) error {
4453
}
4554
defer cleanup()
4655

47-
ctxb := context.Background()
4856
quoteReq := &looprpc.QuoteRequest{
4957
Amt: int64(amt),
5058
ConfTarget: int32(ctx.Uint64("conf_target")),
5159
}
60+
61+
if ctx.IsSet(lastHopFlag.Name) {
62+
lastHopVertex, err := route.NewVertexFromStr(
63+
ctx.String(lastHopFlag.Name),
64+
)
65+
if err != nil {
66+
return err
67+
}
68+
69+
quoteReq.LoopInLastHop = lastHopVertex[:]
70+
}
71+
72+
ctxb := context.Background()
5273
quoteResp, err := client.GetLoopInQuote(ctxb, quoteReq)
5374
if err != nil {
5475
return err

0 commit comments

Comments
 (0)