|
5 | 5 | "context"
|
6 | 6 | "crypto/rand"
|
7 | 7 | "encoding/hex"
|
| 8 | + "encoding/json" |
8 | 9 | "errors"
|
9 | 10 | "fmt"
|
10 | 11 | "io"
|
@@ -254,6 +255,11 @@ var SendPaymentCommand = cli.Command{
|
254 | 255 | Name: "keysend",
|
255 | 256 | Usage: "will generate a pre-image and encode it in the sphinx packet, a dest must be set [experimental]",
|
256 | 257 | },
|
| 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 | + }, |
257 | 263 | ),
|
258 | 264 | Action: SendPayment,
|
259 | 265 | }
|
@@ -362,6 +368,22 @@ func SendPayment(ctx *cli.Context) error {
|
362 | 368 |
|
363 | 369 | req.PaymentAddr = payAddr
|
364 | 370 |
|
| 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 | + |
365 | 387 | return SendPaymentRequest(
|
366 | 388 | ctx, req, conn, conn, routerRPCSendPayment,
|
367 | 389 | )
|
@@ -473,6 +495,22 @@ func SendPayment(ctx *cli.Context) error {
|
473 | 495 |
|
474 | 496 | req.PaymentAddr = payAddr
|
475 | 497 |
|
| 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 | + |
476 | 514 | return SendPaymentRequest(ctx, req, conn, conn, routerRPCSendPayment)
|
477 | 515 | }
|
478 | 516 |
|
@@ -1154,6 +1192,11 @@ var queryRoutesCommand = cli.Command{
|
1154 | 1192 | blindedBaseFlag,
|
1155 | 1193 | blindedPPMFlag,
|
1156 | 1194 | 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 | + }, |
1157 | 1200 | },
|
1158 | 1201 | Action: actionDecorator(queryRoutes),
|
1159 | 1202 | }
|
@@ -1248,6 +1291,22 @@ func queryRoutes(ctx *cli.Context) error {
|
1248 | 1291 | BlindedPaymentPaths: blindedRoutes,
|
1249 | 1292 | }
|
1250 | 1293 |
|
| 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 | + |
1251 | 1310 | route, err := client.QueryRoutes(ctxc, req)
|
1252 | 1311 | if err != nil {
|
1253 | 1312 | return err
|
|
0 commit comments