cmd/lncli/watchtower: add tower info command
This commit is contained in:
parent
ea311649b4
commit
24b160b1c4
@ -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)
|
||||
|
65
cmd/lncli/watchtower_active.go
Normal file
65
cmd/lncli/watchtower_active.go
Normal file
@ -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
|
||||
}
|
10
cmd/lncli/watchtower_default.go
Normal file
10
cmd/lncli/watchtower_default.go
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user