lncli: add state command
This commit is contained in:
parent
9ef556624e
commit
b4bc6f918e
45
cmd/lncli/cmd_state.go
Normal file
45
cmd/lncli/cmd_state.go
Normal file
@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var getStateCommand = cli.Command{
|
||||
Name: "state",
|
||||
Category: "Startup",
|
||||
Usage: "Get the current state of the wallet and RPC",
|
||||
Description: `
|
||||
Get the current state of the wallet. The possible states are:
|
||||
- NON_EXISTING: wallet has not yet been initialized.
|
||||
- LOCKED: wallet is locked.
|
||||
- UNLOCKED: wallet has been unlocked successfully, but the full RPC is
|
||||
not yet ready.
|
||||
- RPC_READY: the daemon has started and the RPC is fully available.
|
||||
`,
|
||||
Flags: []cli.Flag{},
|
||||
Action: actionDecorator(getState),
|
||||
}
|
||||
|
||||
func getState(ctx *cli.Context) error {
|
||||
ctxb := context.Background()
|
||||
client, cleanUp := getStateServiceClient(ctx)
|
||||
defer cleanUp()
|
||||
|
||||
req := &lnrpc.SubscribeStateRequest{}
|
||||
stream, err := client.SubscribeState(ctxb, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get a single state, then exit.
|
||||
resp, err := stream.Recv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printRespJSON(resp)
|
||||
return nil
|
||||
}
|
@ -57,6 +57,16 @@ func getWalletUnlockerClient(ctx *cli.Context) (lnrpc.WalletUnlockerClient, func
|
||||
return lnrpc.NewWalletUnlockerClient(conn), cleanUp
|
||||
}
|
||||
|
||||
func getStateServiceClient(ctx *cli.Context) (lnrpc.StateClient, func()) {
|
||||
conn := getClientConn(ctx, true)
|
||||
|
||||
cleanUp := func() {
|
||||
conn.Close()
|
||||
}
|
||||
|
||||
return lnrpc.NewStateClient(conn), cleanUp
|
||||
}
|
||||
|
||||
func getClient(ctx *cli.Context) (lnrpc.LightningClient, func()) {
|
||||
conn := getClientConn(ctx, false)
|
||||
|
||||
@ -351,6 +361,7 @@ func main() {
|
||||
trackPaymentCommand,
|
||||
versionCommand,
|
||||
profileSubCommand,
|
||||
getStateCommand,
|
||||
}
|
||||
|
||||
// Add any extra commands determined by build flags.
|
||||
|
Loading…
Reference in New Issue
Block a user