-
Notifications
You must be signed in to change notification settings - Fork 55
/
status.go
73 lines (57 loc) · 1.52 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package cmd
import (
"context"
"github.com/omni-network/omni/lib/errors"
cmtconfig "github.com/cometbft/cometbft/config"
cmtjson "github.com/cometbft/cometbft/libs/json"
cmthttp "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cosmos/cosmos-sdk/client"
sdkflags "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
)
type statusConfig struct {
Node string
Output string
}
func defaultStatusConfig() statusConfig {
return statusConfig{
Output: sdkflags.OutputFormatJSON,
Node: cmtconfig.DefaultRPCConfig().ListenAddress,
}
}
func newStatusCmd() *cobra.Command {
cfg := defaultStatusConfig()
cmd := &cobra.Command{
Use: "status",
Short: "Query remote node for status",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
err := printStatus(cmd.Context(), cfg)
if err != nil {
return errors.Wrap(err, "status failed")
}
return nil
},
}
bindStatusFlags(cmd, &cfg)
return cmd
}
func printStatus(ctx context.Context, cfg statusConfig) error {
rpcCl, err := cmthttp.New(cfg.Node, "/websocket")
if err != nil {
return errors.Wrap(err, "create rpc client", "address", cfg.Node)
}
status, err := rpcCl.Status(ctx)
if err != nil {
return errors.Wrap(err, "query status", "address", cfg.Node)
}
output, err := cmtjson.Marshal(status)
if err != nil {
return errors.Wrap(err, "marshal status")
}
err = new(client.Context).WithOutputFormat(cfg.Output).PrintRaw(output)
if err != nil {
return errors.Wrap(err, "print status")
}
return nil
}