Skip to content

Commit 3260ac6

Browse files
committed
lncli: Add --route_hints flag to sendpayment, queryroutes (fixes #6601)
1 parent 06f1ef4 commit 3260ac6

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

cmd/commands/cmd_payments.go

+59
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"crypto/rand"
77
"encoding/hex"
8+
"encoding/json"
89
"errors"
910
"fmt"
1011
"io"
@@ -254,6 +255,11 @@ var SendPaymentCommand = cli.Command{
254255
Name: "keysend",
255256
Usage: "will generate a pre-image and encode it in the sphinx packet, a dest must be set [experimental]",
256257
},
258+
cli.StringFlag{
259+
Name: "route_hints",
260+
Usage: "route hints to reach the destination, encoded as a JSON string. " +
261+
"See the RouteHint struct in the RPC definition for the full format.",
262+
},
257263
),
258264
Action: SendPayment,
259265
}
@@ -362,6 +368,22 @@ func SendPayment(ctx *cli.Context) error {
362368

363369
req.PaymentAddr = payAddr
364370

371+
// Parse --route_hints if provided.
372+
if ctx.IsSet("route_hints") {
373+
routeHintsJSON := ctx.String("route_hints")
374+
var routeHints []*lnrpc.RouteHint
375+
376+
// Unmarshal the JSON string into the RouteHint slice.
377+
err := json.Unmarshal([]byte(routeHintsJSON), &routeHints)
378+
if err != nil {
379+
return fmt.Errorf("error unmarshaling route_hints "+
380+
"json: %w", err)
381+
}
382+
383+
// Assign the parsed hints to the request.
384+
req.RouteHints = routeHints
385+
}
386+
365387
return SendPaymentRequest(
366388
ctx, req, conn, conn, routerRPCSendPayment,
367389
)
@@ -473,6 +495,22 @@ func SendPayment(ctx *cli.Context) error {
473495

474496
req.PaymentAddr = payAddr
475497

498+
// Parse --route_hints if provided.
499+
if ctx.IsSet("route_hints") {
500+
routeHintsJSON := ctx.String("route_hints")
501+
var routeHints []*lnrpc.RouteHint
502+
503+
// Unmarshal the JSON string into the RouteHint slice.
504+
err := json.Unmarshal([]byte(routeHintsJSON), &routeHints)
505+
if err != nil {
506+
return fmt.Errorf("error unmarshaling route_hints "+
507+
"json: %w", err)
508+
}
509+
510+
// Assign the parsed hints to the request.
511+
req.RouteHints = routeHints
512+
}
513+
476514
return SendPaymentRequest(ctx, req, conn, conn, routerRPCSendPayment)
477515
}
478516

@@ -1154,6 +1192,11 @@ var queryRoutesCommand = cli.Command{
11541192
blindedBaseFlag,
11551193
blindedPPMFlag,
11561194
blindedCLTVFlag,
1195+
cli.StringFlag{
1196+
Name: "route_hints",
1197+
Usage: "route hints to reach the destination, encoded as a JSON string. " +
1198+
"See the RouteHint struct in the RPC definition for the full format.",
1199+
},
11571200
},
11581201
Action: actionDecorator(queryRoutes),
11591202
}
@@ -1248,6 +1291,22 @@ func queryRoutes(ctx *cli.Context) error {
12481291
BlindedPaymentPaths: blindedRoutes,
12491292
}
12501293

1294+
// Parse --route_hints if provided.
1295+
if ctx.IsSet("route_hints") {
1296+
routeHintsJSON := ctx.String("route_hints")
1297+
var routeHints []*lnrpc.RouteHint
1298+
1299+
// Unmarshal the JSON string into the RouteHint slice.
1300+
err := json.Unmarshal([]byte(routeHintsJSON), &routeHints)
1301+
if err != nil {
1302+
return fmt.Errorf("error unmarshaling route_hints "+
1303+
"json: %w", err)
1304+
}
1305+
1306+
// Assign the parsed hints to the request.
1307+
req.RouteHints = routeHints
1308+
}
1309+
12511310
route, err := client.QueryRoutes(ctxc, req)
12521311
if err != nil {
12531312
return err

0 commit comments

Comments
 (0)