mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
lncli: add lncli autopilot commands
This commit adds commands 'status', 'enable' and 'disable' for autopilot. The commands will only be enabled for autopilotrpc builds of lncli.
This commit is contained in:
parent
fdf903b8a9
commit
80ac8c1df0
113
cmd/lncli/autopilotrpc_active.go
Normal file
113
cmd/lncli/autopilotrpc_active.go
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
// +build autopilotrpc
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/lightningnetwork/lnd/lnrpc/autopilotrpc"
|
||||||
|
"github.com/urfave/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getAutopilotClient(ctx *cli.Context) (autopilotrpc.AutopilotClient, func()) {
|
||||||
|
conn := getClientConn(ctx, false)
|
||||||
|
|
||||||
|
cleanUp := func() {
|
||||||
|
conn.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
return autopilotrpc.NewAutopilotClient(conn), cleanUp
|
||||||
|
}
|
||||||
|
|
||||||
|
var getStatusCommand = cli.Command{
|
||||||
|
Name: "status",
|
||||||
|
Usage: "Get the active status of autopilot.",
|
||||||
|
Description: "",
|
||||||
|
Action: actionDecorator(getStatus),
|
||||||
|
}
|
||||||
|
|
||||||
|
func getStatus(ctx *cli.Context) error {
|
||||||
|
ctxb := context.Background()
|
||||||
|
client, cleanUp := getAutopilotClient(ctx)
|
||||||
|
defer cleanUp()
|
||||||
|
|
||||||
|
req := &autopilotrpc.StatusRequest{}
|
||||||
|
|
||||||
|
resp, err := client.Status(ctxb, req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
printRespJSON(resp)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var enableCommand = cli.Command{
|
||||||
|
Name: "enable",
|
||||||
|
Usage: "Enable the autopilot.",
|
||||||
|
Description: "",
|
||||||
|
Action: actionDecorator(enable),
|
||||||
|
}
|
||||||
|
|
||||||
|
var disableCommand = cli.Command{
|
||||||
|
Name: "disable",
|
||||||
|
Usage: "Disable the active autopilot.",
|
||||||
|
Description: "",
|
||||||
|
Action: actionDecorator(disable),
|
||||||
|
}
|
||||||
|
|
||||||
|
func enable(ctx *cli.Context) error {
|
||||||
|
ctxb := context.Background()
|
||||||
|
client, cleanUp := getAutopilotClient(ctx)
|
||||||
|
defer cleanUp()
|
||||||
|
|
||||||
|
// We will enable the autopilot.
|
||||||
|
req := &autopilotrpc.ModifyStatusRequest{
|
||||||
|
Enable: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.ModifyStatus(ctxb, req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
printRespJSON(resp)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func disable(ctx *cli.Context) error {
|
||||||
|
ctxb := context.Background()
|
||||||
|
client, cleanUp := getAutopilotClient(ctx)
|
||||||
|
defer cleanUp()
|
||||||
|
|
||||||
|
// We will disable the autopilot.
|
||||||
|
req := &autopilotrpc.ModifyStatusRequest{
|
||||||
|
Enable: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.ModifyStatus(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 {
|
||||||
|
return []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "autopilot",
|
||||||
|
Category: "Autopilot",
|
||||||
|
Usage: "Interact with a running autopilot.",
|
||||||
|
Description: "",
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
getStatusCommand,
|
||||||
|
enableCommand,
|
||||||
|
disableCommand,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
10
cmd/lncli/autopilotrpc_default.go
Normal file
10
cmd/lncli/autopilotrpc_default.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// +build !autopilotrpc
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "github.com/urfave/cli"
|
||||||
|
|
||||||
|
// autopilotCommands will return nil for non-autopilotrpc builds.
|
||||||
|
func autopilotCommands() []cli.Command {
|
||||||
|
return nil
|
||||||
|
}
|
@ -293,6 +293,9 @@ func main() {
|
|||||||
forwardingHistoryCommand,
|
forwardingHistoryCommand,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add any extra autopilot commands determined by build flags.
|
||||||
|
app.Commands = append(app.Commands, autopilotCommands()...)
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user