From 4e2ec08767e9c5b90056ddc8f034395b5e201db7 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 2 May 2023 20:40:16 +0200 Subject: [PATCH] cmd/litcli: commands for status server Note that the client connection for these commands does not require a macaroon. --- cmd/litcli/main.go | 1 + cmd/litcli/status.go | 49 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 cmd/litcli/status.go diff --git a/cmd/litcli/main.go b/cmd/litcli/main.go index 921a670e..6c632c71 100644 --- a/cmd/litcli/main.go +++ b/cmd/litcli/main.go @@ -77,6 +77,7 @@ func main() { app.Commands = append(app.Commands, autopilotCommands) app.Commands = append(app.Commands, litCommands...) app.Commands = append(app.Commands, helperCommands) + app.Commands = append(app.Commands, statusCommands...) err := app.Run(os.Args) if err != nil { diff --git a/cmd/litcli/status.go b/cmd/litcli/status.go new file mode 100644 index 00000000..ffd031bb --- /dev/null +++ b/cmd/litcli/status.go @@ -0,0 +1,49 @@ +package main + +import ( + "context" + + "github.com/lightninglabs/lightning-terminal/litrpc" + "github.com/lightningnetwork/lnd/lnrpc" + "github.com/urfave/cli" +) + +var statusCommands = []cli.Command{ + { + Name: "status", + Usage: "info about litd status", + Category: "Status", + Action: getStatus, + }, +} + +func getStatus(ctx *cli.Context) error { + clientConn, cleanup, err := connectClient(ctx, true) + if err != nil { + return err + } + defer cleanup() + litClient := litrpc.NewStatusClient(clientConn) + + // Get LiT's status. + ctxb := context.Background() + litResp, err := litClient.SubServerStatus( + ctxb, &litrpc.SubServerStatusReq{}, + ) + if err != nil { + return err + } + + printRespJSON(litResp) + + // Get LND's state. + lndClient := lnrpc.NewStateClient(clientConn) + lndResp, err := lndClient.GetState(ctxb, &lnrpc.GetStateRequest{}) + if err != nil { + return err + } + + printRespJSON(lndResp) + + return nil +}