cmd/lncli/watchtower: add tower info command

This commit is contained in:
Conner Fromknecht 2019-06-20 16:56:11 -07:00
parent ea311649b4
commit 24b160b1c4
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
3 changed files with 77 additions and 1 deletions

@ -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)

@ -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
}

@ -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
}