mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-11 01:11:02 +02:00
To make the "Payments" category a bit less overloaded and to move the Mission Control configuration commands away from the "root" category, we create the new "Mission Control" category that we move the commands into. We do this in a single commit so the next one where we move them into the same file can be a pure code move without any additional changes.
69 lines
1.4 KiB
Go
69 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"github.com/btcsuite/btcutil"
|
|
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
|
"github.com/lightningnetwork/lnd/routing/route"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
var queryProbCommand = cli.Command{
|
|
Name: "queryprob",
|
|
Category: "Mission Control",
|
|
Usage: "Estimate a success probability.",
|
|
ArgsUsage: "from-node to-node amt",
|
|
Action: actionDecorator(queryProb),
|
|
}
|
|
|
|
func queryProb(ctx *cli.Context) error {
|
|
ctxc := getContext()
|
|
args := ctx.Args()
|
|
|
|
if len(args) != 3 {
|
|
return cli.ShowCommandHelp(ctx, "queryprob")
|
|
}
|
|
|
|
fromNode, err := route.NewVertexFromStr(args.Get(0))
|
|
if err != nil {
|
|
return fmt.Errorf("invalid from node key: %v", err)
|
|
}
|
|
|
|
toNode, err := route.NewVertexFromStr(args.Get(1))
|
|
if err != nil {
|
|
return fmt.Errorf("invalid to node key: %v", err)
|
|
}
|
|
|
|
amtSat, err := strconv.ParseUint(args.Get(2), 10, 64)
|
|
if err != nil {
|
|
return fmt.Errorf("invalid amt: %v", err)
|
|
}
|
|
|
|
amtMsat := lnwire.NewMSatFromSatoshis(
|
|
btcutil.Amount(amtSat),
|
|
)
|
|
|
|
conn := getClientConn(ctx, false)
|
|
defer conn.Close()
|
|
|
|
client := routerrpc.NewRouterClient(conn)
|
|
|
|
req := &routerrpc.QueryProbabilityRequest{
|
|
FromNode: fromNode[:],
|
|
ToNode: toNode[:],
|
|
AmtMsat: int64(amtMsat),
|
|
}
|
|
|
|
response, err := client.QueryProbability(ctxc, req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
printRespJSON(response)
|
|
|
|
return nil
|
|
}
|