From 5306ed5b68e0e4552913ba4102fef411980b6c33 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 19 Dec 2018 14:54:56 +0100 Subject: [PATCH] lncli: add autopilot query command To query the autopilot heuristics for scores. --- cmd/lncli/autopilotrpc_active.go | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/cmd/lncli/autopilotrpc_active.go b/cmd/lncli/autopilotrpc_active.go index 542fb60c1..c770e69a2 100644 --- a/cmd/lncli/autopilotrpc_active.go +++ b/cmd/lncli/autopilotrpc_active.go @@ -94,6 +94,47 @@ func disable(ctx *cli.Context) error { return nil } +var queryScoresCommand = cli.Command{ + Name: "query", + Usage: "Query the autopilot heuristcs for nodes' scores.", + ArgsUsage: " ...", + Description: "", + Action: actionDecorator(queryScores), +} + +func queryScores(ctx *cli.Context) error { + ctxb := context.Background() + client, cleanUp := getAutopilotClient(ctx) + defer cleanUp() + + args := ctx.Args() + var pubs []string + + // Keep reading pubkeys as long as there are arguments. +loop: + for { + switch { + case args.Present(): + pubs = append(pubs, args.First()) + args = args.Tail() + default: + break loop + } + } + + req := &autopilotrpc.QueryScoresRequest{ + Pubkeys: pubs, + } + + resp, err := client.QueryScores(ctxb, req) + if err != nil { + return err + } + + printRespJSON(resp) + return nil +} + // autopilotCommands will return the set of commands to enable for autopilotrpc // builds. func autopilotCommands() []cli.Command { @@ -107,6 +148,7 @@ func autopilotCommands() []cli.Command { getStatusCommand, enableCommand, disableCommand, + queryScoresCommand, }, }, }