diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index 51917e4e..5832ce20 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -300,11 +300,12 @@ func main() { restoreChanBackupCommand, } - // Add any extra autopilot commands determined by build flags. + // Add any extra commands determined by build flags. app.Commands = append(app.Commands, autopilotCommands()...) app.Commands = append(app.Commands, invoicesCommands()...) app.Commands = append(app.Commands, routerCommands()...) app.Commands = append(app.Commands, walletCommands()...) + app.Commands = append(app.Commands, watchtowerCommands()...) if err := app.Run(os.Args); err != nil { fatal(err) diff --git a/cmd/lncli/watchtower_active.go b/cmd/lncli/watchtower_active.go new file mode 100644 index 00000000..bfa9af66 --- /dev/null +++ b/cmd/lncli/watchtower_active.go @@ -0,0 +1,65 @@ +// +build watchtowerrpc + +package main + +import ( + "context" + "encoding/hex" + + "github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc" + "github.com/urfave/cli" +) + +func watchtowerCommands() []cli.Command { + return []cli.Command{ + { + Name: "tower", + Usage: "Interact with the watchtower.", + Category: "Watchtower", + Subcommands: []cli.Command{ + towerInfoCommand, + }, + }, + } +} + +func getWatchtowerClient(ctx *cli.Context) (watchtowerrpc.WatchtowerClient, func()) { + conn := getClientConn(ctx, false) + cleanup := func() { + conn.Close() + } + return watchtowerrpc.NewWatchtowerClient(conn), cleanup +} + +var towerInfoCommand = cli.Command{ + Name: "info", + Usage: "Returns basic information related to the active watchtower.", + Action: actionDecorator(towerInfo), +} + +func towerInfo(ctx *cli.Context) error { + if ctx.NArg() != 0 || ctx.NumFlags() > 0 { + return cli.ShowCommandHelp(ctx, "info") + } + + client, cleanup := getWatchtowerClient(ctx) + defer cleanup() + + req := &watchtowerrpc.GetInfoRequest{} + resp, err := client.GetInfo(context.Background(), req) + if err != nil { + return err + } + + printJSON(struct { + Pubkey string `json:"pubkey"` + Listeners []string `json:"listeners"` + URIs []string `json:"uris"` + }{ + Pubkey: hex.EncodeToString(resp.Pubkey), + Listeners: resp.Listeners, + URIs: resp.Uris, + }) + + return nil +} diff --git a/cmd/lncli/watchtower_default.go b/cmd/lncli/watchtower_default.go new file mode 100644 index 00000000..41d887a9 --- /dev/null +++ b/cmd/lncli/watchtower_default.go @@ -0,0 +1,10 @@ +// +build !watchtowerrpc + +package main + +import "github.com/urfave/cli" + +// watchtowerCommands will return nil for non-watchtowerrpc builds. +func watchtowerCommands() []cli.Command { + return nil +}