From 72e7026da7fb773ed5457f2158f408fb2feca7ca Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 16 Aug 2023 12:47:34 +0200 Subject: [PATCH] feat: use autocli for comet commands (#17389) (cherry picked from commit 208219a4283bad7fd6c9a3d93f50c96e7efbb3ae) # Conflicts: # CHANGELOG.md # tools/hubl/go.mod # tools/hubl/go.sum # tools/hubl/internal/remote.go --- CHANGELOG.md | 6 ++ client/grpc/cmtservice/autocli.go | 71 +++++++++++++++++++ client/grpc/cmtservice/block.go | 2 +- client/grpc/cmtservice/service.go | 4 +- client/grpc/cmtservice/status.go | 3 +- client/grpc/cmtservice/status_test.go | 30 ++++++++ client/rpc/rpc_test.go | 13 ---- client/rpc/status.go | 58 --------------- client/rpc/validators.go | 59 --------------- client/v2/README.md | 10 +++ client/v2/autocli/flags.go | 3 + client/v2/autocli/msg.go | 6 ++ client/v2/autocli/query.go | 6 ++ .../testdata/help-deprecated-msg.golden | 1 + .../autocli/testdata/help-deprecated.golden | 1 + .../v2/autocli/testdata/help-echo-msg.golden | 1 + client/v2/autocli/testdata/help-echo.golden | 1 + runtime/autocli.go | 46 ++++++------ server/cmt_cmds.go | 48 +++++++++++-- simapp/simd/cmd/commands.go | 4 +- tools/hubl/go.mod | 11 ++- tools/hubl/go.sum | 21 +++++- tools/hubl/internal/remote.go | 9 +++ x/consensus/autocli.go | 5 ++ 24 files changed, 252 insertions(+), 167 deletions(-) create mode 100644 client/grpc/cmtservice/autocli.go create mode 100644 client/grpc/cmtservice/status_test.go delete mode 100644 client/rpc/status.go delete mode 100644 client/rpc/validators.go create mode 100644 client/v2/autocli/flags.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 8146b36ac403..9028d433d28a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,9 +46,15 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +<<<<<<< HEAD * (cli) [#17187](https://github.com/cosmos/cosmos-sdk/pull/17187) Do not use `ctx.PrintObjectLegacy` in commands anymore. * ` q gov proposer [proposal-id]` now returns a proposal id as int instead of string. * (testutil) [#17216](https://github.com/cosmos/cosmos-sdk/issues/17216) Add `DefaultContextWithKeys` to `testutil` package. +======= +* (cli) [#17389](https://github.com/cosmos/cosmos-sdk/pull/17389) gRPC CometBFT commands have been added under ` q consensus comet`. Duplicate commands have been removed. CometBFT commands placement in the SDK has been simplified. See the exhaustive list below. + * ` q comet-validator-set` is now ` q consensus comet validator-set` + * `client/rpc.StatusCommand()` is now at `server.StatusCommand()` +>>>>>>> 208219a42 (feat: use autocli for comet commands (#17389)) * (x/group, x/gov) [#17220](https://github.com/cosmos/cosmos-sdk/pull/17220) Add `--skip-metadata` flag in `draft-proposal` to skip metadata prompt. * (x/group, x/gov) [#17109](https://github.com/cosmos/cosmos-sdk/pull/17109) Let proposal summary be 40x longer than metadata limit. * (version) [#17096](https://github.com/cosmos/cosmos-sdk/pull/17096) Improve `getSDKVersion()` to handle module replacements. diff --git a/client/grpc/cmtservice/autocli.go b/client/grpc/cmtservice/autocli.go new file mode 100644 index 000000000000..ea314c6f8c08 --- /dev/null +++ b/client/grpc/cmtservice/autocli.go @@ -0,0 +1,71 @@ +package cmtservice + +import ( + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + cmtv1beta1 "cosmossdk.io/api/cosmos/base/tendermint/v1beta1" +) + +var CometBFTAutoCLIDescriptor = &autocliv1.ServiceCommandDescriptor{ + Service: cmtv1beta1.Service_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "GetNodeInfo", + Use: "node-info", + Short: "Query the current node info", + }, + { + RpcMethod: "GetSyncing", + Use: "syncing", + Short: "Query node syncing status", + }, + { + RpcMethod: "GetLatestBlock", + Use: "block-latest", + Short: "Query for the latest committed block", + }, + { + RpcMethod: "GetBlockByHeight", + Use: "block-by-height [height]", + Short: "Query for a committed block by height", + Long: "Query for a specific committed block using the CometBFT RPC `block_by_height` method", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "height"}}, + }, + { + RpcMethod: "GetLatestValidatorSet", + Use: "validator-set", + Alias: []string{"validator-set-latest", "comet-validator-set", "cometbft-validator-set", "tendermint-validator-set"}, + Short: "Query for the latest validator set", + }, + { + RpcMethod: "GetValidatorSetByHeight", + Use: "validator-set-by-height [height]", + Short: "Query for a validator set by height", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "height"}}, + }, + { + RpcMethod: "ABCIQuery", + Skip: true, + }, + }, +} + +// NewCometBFTCommands is a fake `appmodule.Module` to be considered as a module +// and be added in AutoCLI. +func NewCometBFTCommands() *cometModule { + return &cometModule{} +} + +type cometModule struct{} + +func (m cometModule) IsOnePerModuleType() {} +func (m cometModule) IsAppModule() {} + +func (m cometModule) Name() string { + return "comet" +} + +func (m cometModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: CometBFTAutoCLIDescriptor, + } +} diff --git a/client/grpc/cmtservice/block.go b/client/grpc/cmtservice/block.go index 1575626fa629..f1cde440f912 100644 --- a/client/grpc/cmtservice/block.go +++ b/client/grpc/cmtservice/block.go @@ -10,7 +10,7 @@ import ( ) func getBlockHeight(ctx context.Context, clientCtx client.Context) (int64, error) { - status, err := getNodeStatus(ctx, clientCtx) + status, err := GetNodeStatus(ctx, clientCtx) if err != nil { return 0, err } diff --git a/client/grpc/cmtservice/service.go b/client/grpc/cmtservice/service.go index 39e17ce1a9dc..e26e65332806 100644 --- a/client/grpc/cmtservice/service.go +++ b/client/grpc/cmtservice/service.go @@ -49,7 +49,7 @@ func NewQueryServer( // GetSyncing implements ServiceServer.GetSyncing func (s queryServer) GetSyncing(ctx context.Context, _ *GetSyncingRequest) (*GetSyncingResponse, error) { - status, err := getNodeStatus(ctx, s.clientCtx) + status, err := GetNodeStatus(ctx, s.clientCtx) if err != nil { return nil, err } @@ -189,7 +189,7 @@ func ValidatorsOutput(ctx context.Context, clientCtx client.Context, height *int // GetNodeInfo implements ServiceServer.GetNodeInfo func (s queryServer) GetNodeInfo(ctx context.Context, _ *GetNodeInfoRequest) (*GetNodeInfoResponse, error) { - status, err := getNodeStatus(ctx, s.clientCtx) + status, err := GetNodeStatus(ctx, s.clientCtx) if err != nil { return nil, err } diff --git a/client/grpc/cmtservice/status.go b/client/grpc/cmtservice/status.go index 9f03a71a7672..ea32e00b79a8 100644 --- a/client/grpc/cmtservice/status.go +++ b/client/grpc/cmtservice/status.go @@ -8,7 +8,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" ) -func getNodeStatus(ctx context.Context, clientCtx client.Context) (*coretypes.ResultStatus, error) { +// GetNodeStatus returns the status of the node. +func GetNodeStatus(ctx context.Context, clientCtx client.Context) (*coretypes.ResultStatus, error) { node, err := clientCtx.GetNode() if err != nil { return &coretypes.ResultStatus{}, err diff --git a/client/grpc/cmtservice/status_test.go b/client/grpc/cmtservice/status_test.go new file mode 100644 index 000000000000..73c86e1bfc21 --- /dev/null +++ b/client/grpc/cmtservice/status_test.go @@ -0,0 +1,30 @@ +package cmtservice_test + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/server" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/cosmos/cosmos-sdk/testutil/network" +) + +func TestStatusCommand(t *testing.T) { + cfg, err := network.DefaultConfigWithAppConfig(network.MinimumAppConfig()) + require.NoError(t, err) + + network, err := network.New(t, t.TempDir(), cfg) + require.NoError(t, err) + require.NoError(t, network.WaitForNextBlock()) + + val0 := network.Validators[0] + cmd := server.StatusCommand() + + out, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cmd, []string{}) + require.NoError(t, err) + + // Make sure the output has the validator moniker. + require.Contains(t, out.String(), fmt.Sprintf("\"moniker\":\"%s\"", val0.Moniker)) +} diff --git a/client/rpc/rpc_test.go b/client/rpc/rpc_test.go index 3bd9c39ec867..bffdbf927d0e 100644 --- a/client/rpc/rpc_test.go +++ b/client/rpc/rpc_test.go @@ -11,8 +11,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/metadata" - "github.com/cosmos/cosmos-sdk/client/rpc" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/cosmos/cosmos-sdk/types/address" @@ -44,17 +42,6 @@ func (s *IntegrationTestSuite) TearDownSuite() { s.network.Cleanup() } -func (s *IntegrationTestSuite) TestStatusCommand() { - val0 := s.network.Validators[0] - cmd := rpc.StatusCommand() - - out, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cmd, []string{}) - s.Require().NoError(err) - - // Make sure the output has the validator moniker. - s.Require().Contains(out.String(), fmt.Sprintf("\"moniker\":\"%s\"", val0.Moniker)) -} - func (s *IntegrationTestSuite) TestCLIQueryConn() { s.T().Skip("data race in comet is causing this to fail") var header metadata.MD diff --git a/client/rpc/status.go b/client/rpc/status.go deleted file mode 100644 index 5f50ae36af14..000000000000 --- a/client/rpc/status.go +++ /dev/null @@ -1,58 +0,0 @@ -package rpc - -import ( - "context" - - cmtjson "github.com/cometbft/cometbft/libs/json" - coretypes "github.com/cometbft/cometbft/rpc/core/types" - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" -) - -// StatusCommand returns the command to return the status of the network. -func StatusCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "status", - Short: "Query remote node for status", - RunE: func(cmd *cobra.Command, _ []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - status, err := getNodeStatus(clientCtx) - if err != nil { - return err - } - - output, err := cmtjson.Marshal(status) - if err != nil { - return err - } - - // In order to maintain backwards compatibility, the default json format output - outputFormat, _ := cmd.Flags().GetString(flags.FlagOutput) - if outputFormat == flags.OutputFormatJSON { - clientCtx = clientCtx.WithOutputFormat(flags.OutputFormatJSON) - } - - return clientCtx.PrintRaw(output) - }, - } - - cmd.Flags().StringP(flags.FlagNode, "n", "tcp://localhost:26657", "Node to connect to") - cmd.Flags().StringP(flags.FlagOutput, "o", "json", "Output format (text|json)") - - return cmd -} - -func getNodeStatus(clientCtx client.Context) (*coretypes.ResultStatus, error) { - node, err := clientCtx.GetNode() - if err != nil { - return &coretypes.ResultStatus{}, err - } - - return node.Status(context.Background()) -} diff --git a/client/rpc/validators.go b/client/rpc/validators.go deleted file mode 100644 index 7facee4259d4..000000000000 --- a/client/rpc/validators.go +++ /dev/null @@ -1,59 +0,0 @@ -package rpc - -import ( - "strconv" - - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" - "github.com/cosmos/cosmos-sdk/types/query" -) - -// ValidatorCommand returns the validator set for a given height -func ValidatorCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "comet-validator-set [height]", - Aliases: []string{"cometbft-validator-set", "tendermint-validator-set"}, - Short: "Get the full CometBFT validator set at given height", - Args: cobra.MaximumNArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - var height *int64 - - // optional height - if len(args) > 0 { - val, err := strconv.ParseInt(args[0], 10, 64) - if err != nil { - return err - } - - if val > 0 { - height = &val - } - } - - page, _ := cmd.Flags().GetInt(flags.FlagPage) - limit, _ := cmd.Flags().GetInt(flags.FlagLimit) - - response, err := cmtservice.ValidatorsOutput(cmd.Context(), clientCtx, height, page, limit) - if err != nil { - return err - } - - return clientCtx.PrintProto(response) - }, - } - - cmd.Flags().String(flags.FlagNode, "tcp://localhost:26657", ": to CometBFT RPC interface for this chain") - cmd.Flags().StringP(flags.FlagOutput, "o", "text", "Output format (text|json)") - cmd.Flags().Int(flags.FlagPage, query.DefaultPage, "Query a specific page of paginated results") - cmd.Flags().Int(flags.FlagLimit, 100, "Query number of results returned per page") - - return cmd -} diff --git a/client/v2/README.md b/client/v2/README.md index 6218a0385ed5..516c7f49569e 100644 --- a/client/v2/README.md +++ b/client/v2/README.md @@ -177,6 +177,16 @@ https://github.com/cosmos/cosmos-sdk/blob/fa4d87ef7e6d87aaccc94c337ffd2fe90fcb7a If not set to true, `AutoCLI` will not generate commands for the module if there are already commands registered for the module (when `GetTxCmd()` or `GetTxCmd()` are defined). +### Use AutoCLI for non module commands + +It is possible to use `AutoCLI` for non module commands. The trick is still to implement the `appmodule.Module` interface and append it to the `appOptions.ModuleOptions` map. + +For example, here is how the SDK does it for `cometbft` gRPC commands: + +```go reference +https://github.com/cosmos/cosmos-sdk/blob/julien/autocli-comet/client/grpc/cmtservice/autocli.go#L52-L71 +``` + ## Summary `autocli` let you generate CLI to your Cosmos SDK-based applications without any cobra boilerplate. It allows you to easily generate CLI commands and flags from your protobuf messages, and provides many options for customising the behavior of your CLI application. diff --git a/client/v2/autocli/flags.go b/client/v2/autocli/flags.go new file mode 100644 index 000000000000..e6e153fcc6fe --- /dev/null +++ b/client/v2/autocli/flags.go @@ -0,0 +1,3 @@ +package autocli + +var flagNoIndent = "no-indent" diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index a46387e97ab6..682f6c8e75fa 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -104,6 +104,10 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor } cmd, err := b.buildMethodCommandCommon(descriptor, options, func(cmd *cobra.Command, input protoreflect.Message) error { + if noIdent, _ := cmd.Flags().GetBool(flagNoIndent); noIdent { + jsonMarshalOptions.Indent = "" + } + bz, err := jsonMarshalOptions.Marshal(input.Interface()) if err != nil { return err @@ -114,6 +118,8 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor if b.AddTxConnFlags != nil { b.AddTxConnFlags(cmd) + + cmd.Flags().BoolP(flagNoIndent, "", false, "Do not indent JSON output") } return cmd, err diff --git a/client/v2/autocli/query.go b/client/v2/autocli/query.go index 0a89ac9ab1ce..d73a7601d0af 100644 --- a/client/v2/autocli/query.go +++ b/client/v2/autocli/query.go @@ -110,6 +110,10 @@ func (b *Builder) BuildQueryMethodCommand(descriptor protoreflect.MethodDescript } cmd, err := b.buildMethodCommandCommon(descriptor, options, func(cmd *cobra.Command, input protoreflect.Message) error { + if noIdent, _ := cmd.Flags().GetBool(flagNoIndent); noIdent { + jsonMarshalOptions.Indent = "" + } + clientConn, err := getClientConn(cmd) if err != nil { return err @@ -134,6 +138,8 @@ func (b *Builder) BuildQueryMethodCommand(descriptor protoreflect.MethodDescript if b.AddQueryConnFlags != nil { b.AddQueryConnFlags(cmd) + + cmd.Flags().BoolP(flagNoIndent, "", false, "Do not indent JSON output") } return cmd, nil diff --git a/client/v2/autocli/testdata/help-deprecated-msg.golden b/client/v2/autocli/testdata/help-deprecated-msg.golden index 31d61d736cbe..4de93a2d067b 100644 --- a/client/v2/autocli/testdata/help-deprecated-msg.golden +++ b/client/v2/autocli/testdata/help-deprecated-msg.golden @@ -37,6 +37,7 @@ Flags: --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) (default "os") --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used --ledger Use a connected Ledger device + --no-indent Do not indent JSON output --node string : to CometBFT rpc interface for this chain (default "tcp://localhost:26657") --note string Note to add a description to the transaction (previously --memo) --offline Offline mode (does not allow any online functionality) diff --git a/client/v2/autocli/testdata/help-deprecated.golden b/client/v2/autocli/testdata/help-deprecated.golden index 2987afd7b989..b9f8082195f9 100644 --- a/client/v2/autocli/testdata/help-deprecated.golden +++ b/client/v2/autocli/testdata/help-deprecated.golden @@ -26,6 +26,7 @@ Flags: --map-string-coin map[string]cosmos.base.v1beta1.Coin --map-string-string stringToString (default []) --map-string-uint32 stringToUint32 + --no-indent Do not indent JSON output --node string : to CometBFT RPC interface for this chain (default "tcp://localhost:26657") -o, --output string Output format (text|json) (default "text") --page-count-total diff --git a/client/v2/autocli/testdata/help-echo-msg.golden b/client/v2/autocli/testdata/help-echo-msg.golden index 0b5e9e69b756..7a0905579ad9 100644 --- a/client/v2/autocli/testdata/help-echo-msg.golden +++ b/client/v2/autocli/testdata/help-echo-msg.golden @@ -41,6 +41,7 @@ Flags: --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) (default "os") --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used --ledger Use a connected Ledger device + --no-indent Do not indent JSON output --node string : to CometBFT rpc interface for this chain (default "tcp://localhost:26657") --note string Note to add a description to the transaction (previously --memo) --offline Offline mode (does not allow any online functionality) diff --git a/client/v2/autocli/testdata/help-echo.golden b/client/v2/autocli/testdata/help-echo.golden index 7047649a2915..856ef2c83367 100644 --- a/client/v2/autocli/testdata/help-echo.golden +++ b/client/v2/autocli/testdata/help-echo.golden @@ -32,6 +32,7 @@ Flags: --map-string-coin map[string]cosmos.base.v1beta1.Coin some map of string to coin --map-string-string stringToString some map of string to string (default []) --map-string-uint32 stringToUint32 some map of string to int32 + --no-indent Do not indent JSON output --node string : to CometBFT RPC interface for this chain (default "tcp://localhost:26657") -o, --output string Output format (text|json) (default "text") --page-count-total diff --git a/runtime/autocli.go b/runtime/autocli.go index 62e1b4569478..49ff9619115f 100644 --- a/runtime/autocli.go +++ b/runtime/autocli.go @@ -7,33 +7,35 @@ import ( ) func (m appModule) AutoCLIOptions() *autocliv1.ModuleOptions { - return &autocliv1.ModuleOptions{Query: &autocliv1.ServiceCommandDescriptor{ - Service: appv1alpha1.Query_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Config", - Short: "Queries the current app config", + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + Service: appv1alpha1.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Config", + Short: "Query the current app config", + }, }, - }, - SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{ - "autocli": { - Service: autocliv1.Query_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "AppOptions", - Short: "Queries custom autocli options", + SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{ + "autocli": { + Service: autocliv1.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "AppOptions", + Short: "Query the custom autocli options", + }, }, }, - }, - "reflection": { - Service: reflectionv1.ReflectionService_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "FileDescriptors", - Short: "Queries the app's protobuf file descriptors", + "reflection": { + Service: reflectionv1.ReflectionService_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "FileDescriptors", + Short: "Query the app's protobuf file descriptors", + }, }, }, }, }, - }} + } } diff --git a/server/cmt_cmds.go b/server/cmt_cmds.go index 1decc4c59fda..f03694c93dfa 100644 --- a/server/cmt_cmds.go +++ b/server/cmt_cmds.go @@ -8,6 +8,7 @@ import ( "strings" cmtcfg "github.com/cometbft/cometbft/config" + cmtjson "github.com/cometbft/cometbft/libs/json" "github.com/cometbft/cometbft/light" "github.com/cometbft/cometbft/node" "github.com/cometbft/cometbft/p2p" @@ -24,6 +25,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" rpc "github.com/cosmos/cosmos-sdk/client/rpc" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" servercmtlog "github.com/cosmos/cosmos-sdk/server/log" @@ -34,6 +36,43 @@ import ( auth "github.com/cosmos/cosmos-sdk/x/auth/client/cli" ) +// StatusCommand returns the command to return the status of the network. +func StatusCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "status", + Short: "Query remote node for status", + RunE: func(cmd *cobra.Command, _ []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + status, err := cmtservice.GetNodeStatus(context.Background(), clientCtx) + if err != nil { + return err + } + + output, err := cmtjson.Marshal(status) + if err != nil { + return err + } + + // In order to maintain backwards compatibility, the default json format output + outputFormat, _ := cmd.Flags().GetString(flags.FlagOutput) + if outputFormat == flags.OutputFormatJSON { + clientCtx = clientCtx.WithOutputFormat(flags.OutputFormatJSON) + } + + return clientCtx.PrintRaw(output) + }, + } + + cmd.Flags().StringP(flags.FlagNode, "n", "tcp://localhost:26657", "Node to connect to") + cmd.Flags().StringP(flags.FlagOutput, "o", "json", "Output format (text|json)") + + return cmd +} + // ShowNodeIDCmd - ported from CometBFT, dump node ID to stdout func ShowNodeIDCmd() *cobra.Command { return &cobra.Command{ @@ -48,7 +87,7 @@ func ShowNodeIDCmd() *cobra.Command { return err } - fmt.Println(nodeKey.ID()) + cmd.Println(nodeKey.ID()) return nil }, } @@ -80,7 +119,7 @@ func ShowValidatorCmd() *cobra.Command { return err } - fmt.Println(string(bz)) + cmd.Println(string(bz)) return nil }, } @@ -100,7 +139,8 @@ func ShowAddressCmd() *cobra.Command { privValidator := pvm.LoadFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile()) valConsAddr := (sdk.ConsAddress)(privValidator.GetAddress()) - fmt.Println(valConsAddr.String()) + + cmd.Println(valConsAddr.String()) return nil }, } @@ -130,7 +170,7 @@ func VersionCmd() *cobra.Command { return err } - cmd.Print(string(bs)) + cmd.Println(string(bs)) return nil }, } diff --git a/simapp/simd/cmd/commands.go b/simapp/simd/cmd/commands.go index 06858fc938cc..0ab6421642a2 100644 --- a/simapp/simd/cmd/commands.go +++ b/simapp/simd/cmd/commands.go @@ -19,7 +19,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/pruning" - "github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/client/snapshot" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -126,7 +125,7 @@ func initRootCmd( // add keybase, auxiliary RPC, query, genesis, and tx child commands rootCmd.AddCommand( - rpc.StatusCommand(), + server.StatusCommand(), genesisCommand(txConfig, basicManager), queryCommand(), txCommand(), @@ -159,7 +158,6 @@ func queryCommand() *cobra.Command { } cmd.AddCommand( - rpc.ValidatorCommand(), server.QueryBlockCmd(), authcmd.QueryTxsByEventsCmd(), server.QueryBlocksCmd(), diff --git a/tools/hubl/go.mod b/tools/hubl/go.mod index e20ac75cdf1f..e5b27308742c 100644 --- a/tools/hubl/go.mod +++ b/tools/hubl/go.mod @@ -4,10 +4,17 @@ go 1.20 require ( cosmossdk.io/api v0.7.0 +<<<<<<< HEAD cosmossdk.io/client/v2 v2.0.0-20230719143845-dff6b0e26aa4 cosmossdk.io/errors v1.0.0 github.com/cockroachdb/errors v1.10.0 github.com/cosmos/cosmos-sdk v0.50.0-beta.0 +======= + cosmossdk.io/client/v2 v2.0.0-20230815130322-dded2e9921f0 + cosmossdk.io/errors v1.0.0 + github.com/cockroachdb/errors v1.10.0 + github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230815152400-f42d52f7e531 +>>>>>>> 208219a42 (feat: use autocli for comet commands (#17389)) github.com/manifoldco/promptui v0.9.0 github.com/pelletier/go-toml/v2 v2.0.8 github.com/spf13/cobra v1.7.0 @@ -16,12 +23,12 @@ require ( ) require ( - cosmossdk.io/collections v0.3.0 // indirect + cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 // indirect cosmossdk.io/core v0.9.0 // indirect cosmossdk.io/depinject v1.0.0-alpha.4 // indirect cosmossdk.io/log v1.2.0 // indirect cosmossdk.io/math v1.0.1 // indirect - cosmossdk.io/store v1.0.0-alpha.1 // indirect + cosmossdk.io/store v1.0.0-alpha.1.0.20230728080422-54ed7dab3982 // indirect cosmossdk.io/x/tx v0.9.1 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect diff --git a/tools/hubl/go.sum b/tools/hubl/go.sum index f8e530e5c8f6..ca4107c43f4c 100644 --- a/tools/hubl/go.sum +++ b/tools/hubl/go.sum @@ -37,10 +37,17 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4= cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M= +<<<<<<< HEAD cosmossdk.io/client/v2 v2.0.0-20230719143845-dff6b0e26aa4 h1:rXCotxNnD0DUpcVBYojEZWUTEIJ9p+sgkpEtZlV4+pE= cosmossdk.io/client/v2 v2.0.0-20230719143845-dff6b0e26aa4/go.mod h1:mrwVTC+6n90zDpvn4N12YJVl67QUCDQ3yEqIR4Ovp14= cosmossdk.io/collections v0.3.0 h1:v0eEqLBxebAV+t+Ahwf9tSJOu95HVLINwROXx2TTZ08= cosmossdk.io/collections v0.3.0/go.mod h1:CHE1+niUElL9ikCpevRZcp0yqQ4TU0TrEEGirN0mvIg= +======= +cosmossdk.io/client/v2 v2.0.0-20230815130322-dded2e9921f0 h1:AmhKLC/pmof6iXMDFp5+EgMK0sax5J22sdx4jxv/3HY= +cosmossdk.io/client/v2 v2.0.0-20230815130322-dded2e9921f0/go.mod h1:TbVT7QkpMHo+nwmztzYCfCCzO8w776VDe97ME3yjW0I= +cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 h1:aFHpJtJgdqBH8kRvD86Rl92rvd1+JFpaUpj+5NZNodg= +cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68/go.mod h1:OK08xZu8fxXLoQcFIfkBDayo2aRokLfC3vVcXX0MB8E= +>>>>>>> 208219a42 (feat: use autocli for comet commands (#17389)) cosmossdk.io/core v0.9.0 h1:30ScAOHDIUOCg1DKAwqkho9wuQJnu7GUrMcg0XLioic= cosmossdk.io/core v0.9.0/go.mod h1:NFgl5r41Q36+RixTvyrfsS6qQ65agCbZ1FTpnN7/G1Y= cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc= @@ -51,8 +58,8 @@ cosmossdk.io/log v1.2.0 h1:BbykkDsutXPSy8RojFB3KZEWyvMsToLy0ykb/ZhsLqQ= cosmossdk.io/log v1.2.0/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4= cosmossdk.io/math v1.0.1 h1:Qx3ifyOPaMLNH/89WeZFH268yCvU4xEcnPLu3sJqPPg= cosmossdk.io/math v1.0.1/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= -cosmossdk.io/store v1.0.0-alpha.1 h1:/151XxAgm0tiKuYrtJzMG61lf6enpPuP+D/hIN8cRjQ= -cosmossdk.io/store v1.0.0-alpha.1/go.mod h1:ejgU9GhRGMNBduVnDwC3RyhOmu4uKlNQlTiJgPmbDkI= +cosmossdk.io/store v1.0.0-alpha.1.0.20230728080422-54ed7dab3982 h1:61YFeW2AhwwPfoJWzNJWvVubCj32sm5jZkJfraS9pDQ= +cosmossdk.io/store v1.0.0-alpha.1.0.20230728080422-54ed7dab3982/go.mod h1:QAF9zeRa/9ghuv7E8NS9SzWqRbgVNwH/dZwGhYDHUjI= cosmossdk.io/x/tx v0.9.1 h1:9pmmXA9Vs4qdouOFnzhsdsff2mif0f0kylMq5xTGhRI= cosmossdk.io/x/tx v0.9.1/go.mod h1:/YFGTXG6+kyihd8YbfuJiXHV4R/mIMm2uvVzo80CIhA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= @@ -158,8 +165,13 @@ github.com/cockroachdb/tokenbucket v0.0.0-20230613231145-182959a1fad6/go.mod h1: github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/cometbft/cometbft v0.38.0-rc3 h1:Ly3eVPWoFu0y68PmZwLljucPdEBtfigZtqm+OV1W6dE= github.com/cometbft/cometbft v0.38.0-rc3/go.mod h1:5Jz0Z8YsHSf0ZaAqGvi/ifioSdVFPtEGrm8Y9T/993k= +<<<<<<< HEAD github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo= github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0= +======= +github.com/cometbft/cometbft-db v0.8.0 h1:vUMDaH3ApkX8m0KZvOFFy9b5DZHBAjsnEuo9AKVZpjo= +github.com/cometbft/cometbft-db v0.8.0/go.mod h1:6ASCP4pfhmrCBpfk01/9E1SI29nD3HfVHrY4PG8x5c0= +>>>>>>> 208219a42 (feat: use autocli for comet commands (#17389)) github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= @@ -173,8 +185,13 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0 github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U= github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o= github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= +<<<<<<< HEAD github.com/cosmos/cosmos-sdk v0.50.0-beta.0 h1:cPblupyMlA4qvnvuuQEjYQPq1uqSXBgQmsiGREQ5hd0= github.com/cosmos/cosmos-sdk v0.50.0-beta.0/go.mod h1:MF/wnXyreoL0g8YdRZhUD4apPdgebMc29LgMJB+dh6M= +======= +github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230815152400-f42d52f7e531 h1:wMqsKQzHof2ikpTlM5O1PZG4yr+15am+0ROtD/5wJLA= +github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230815152400-f42d52f7e531/go.mod h1:yQzBSxaplSkNZd34HOEqF4NhOHikbpFwWhWAQSteXrw= +>>>>>>> 208219a42 (feat: use autocli for comet commands (#17389)) github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= diff --git a/tools/hubl/internal/remote.go b/tools/hubl/internal/remote.go index d26f10c93251..51d354008154 100644 --- a/tools/hubl/internal/remote.go +++ b/tools/hubl/internal/remote.go @@ -16,6 +16,11 @@ import ( "cosmossdk.io/client/v2/autocli" "cosmossdk.io/client/v2/autocli/flag" +<<<<<<< HEAD +======= + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" +>>>>>>> 208219a42 (feat: use autocli for comet commands (#17389)) addresscodec "github.com/cosmos/cosmos-sdk/codec/address" ) @@ -88,6 +93,10 @@ func RemoteCommand(config *Config, configDir string) ([]*cobra.Command, error) { continue } + // add comet commands + cometCmds := cmtservice.NewCometBFTCommands() + chainInfo.ModuleOptions[cometCmds.Name()] = cometCmds.AutoCLIOptions() + appOpts := autocli.AppOptions{ ModuleOptions: chainInfo.ModuleOptions, } diff --git a/x/consensus/autocli.go b/x/consensus/autocli.go index 54f3dfcf3245..a8bb0f49c618 100644 --- a/x/consensus/autocli.go +++ b/x/consensus/autocli.go @@ -3,6 +3,8 @@ package consensus import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" consensusv1 "cosmossdk.io/api/cosmos/consensus/v1" + + "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" ) // AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. @@ -17,6 +19,9 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { Short: "Query the current consensus parameters", }, }, + SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{ + "comet": cmtservice.CometBFTAutoCLIDescriptor, + }, }, // Tx is purposely left empty, as the only tx is MsgUpdateParams which is gov gated. }