From ef5c84aea8f1b6c6090c728ae8738ae5d93f277c Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Sat, 29 Jul 2023 17:16:13 +0800 Subject: [PATCH 1/8] feat(cli): `status` cmd cli support output text --- client/rpc/rpc_test.go | 3 ++- client/rpc/status.go | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/client/rpc/rpc_test.go b/client/rpc/rpc_test.go index 1d00b51003a2..6f8a19999dd6 100644 --- a/client/rpc/rpc_test.go +++ b/client/rpc/rpc_test.go @@ -11,6 +11,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/rpc" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" @@ -48,7 +49,7 @@ func (s *IntegrationTestSuite) TestStatusCommand() { val0 := s.network.Validators[0] cmd := rpc.StatusCommand() - out, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cmd, []string{}) + out, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cmd, []string{fmt.Sprintf("--%s=json", flags.FlagOutput)}) s.Require().NoError(err) // Make sure the output has the validator moniker. diff --git a/client/rpc/status.go b/client/rpc/status.go index 30f59d7c8657..b90b371aab8f 100644 --- a/client/rpc/status.go +++ b/client/rpc/status.go @@ -2,6 +2,7 @@ package rpc import ( "context" + "encoding/json" "github.com/cometbft/cometbft/p2p" coretypes "github.com/cometbft/cometbft/rpc/core/types" @@ -16,17 +17,17 @@ import ( // ValidatorInfo is info about the node's validator, same as CometBFT, // except that we use our own PubKey. type validatorInfo struct { - Address []byte - PubKey cryptotypes.PubKey - VotingPower int64 + Address []byte `json:"address"` + PubKey cryptotypes.PubKey `json:"pub_key"` + VotingPower int64 `json:"voting_power"` } // ResultStatus is node's info, same as CometBFT, except that we use our own // PubKey. type resultStatus struct { - NodeInfo p2p.DefaultNodeInfo - SyncInfo coretypes.SyncInfo - ValidatorInfo validatorInfo + NodeInfo p2p.DefaultNodeInfo `json:"node_info"` + SyncInfo coretypes.SyncInfo `json:"sync_info"` + ValidatorInfo validatorInfo `json:"validator_info"` } // StatusCommand returns the command to return the status of the network. @@ -63,17 +64,17 @@ func StatusCommand() *cobra.Command { }, } - output, err := clientCtx.LegacyAmino.MarshalJSON(statusWithPk) + output, err := json.Marshal(statusWithPk) if err != nil { return err } - cmd.Println(string(output)) - return nil + return clientCtx.PrintRaw(output) }, } cmd.Flags().StringP(flags.FlagNode, "n", "tcp://localhost:26657", "Node to connect to") + cmd.Flags().StringP(flags.FlagOutput, "o", "text", "Output format (text|json)") return cmd } From 630456df78250f812235b6811b16ec908212df3f Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Sat, 29 Jul 2023 18:36:28 +0800 Subject: [PATCH 2/8] revert: default json format output --- client/rpc/status.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/rpc/status.go b/client/rpc/status.go index b90b371aab8f..6cbec21849c5 100644 --- a/client/rpc/status.go +++ b/client/rpc/status.go @@ -74,7 +74,7 @@ func StatusCommand() *cobra.Command { } cmd.Flags().StringP(flags.FlagNode, "n", "tcp://localhost:26657", "Node to connect to") - cmd.Flags().StringP(flags.FlagOutput, "o", "text", "Output format (text|json)") + cmd.Flags().StringP(flags.FlagOutput, "o", "json", "Output format (text|json)") return cmd } From dfdcf0fa8f14dd6d1dc4538ac7fd7cbb4fa74674 Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Sat, 29 Jul 2023 18:39:43 +0800 Subject: [PATCH 3/8] revert: status cmd cli test --- client/rpc/rpc_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/rpc/rpc_test.go b/client/rpc/rpc_test.go index 6f8a19999dd6..1d00b51003a2 100644 --- a/client/rpc/rpc_test.go +++ b/client/rpc/rpc_test.go @@ -11,7 +11,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/metadata" - "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/rpc" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" @@ -49,7 +48,7 @@ func (s *IntegrationTestSuite) TestStatusCommand() { val0 := s.network.Validators[0] cmd := rpc.StatusCommand() - out, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cmd, []string{fmt.Sprintf("--%s=json", flags.FlagOutput)}) + out, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cmd, []string{}) s.Require().NoError(err) // Make sure the output has the validator moniker. From 6a035897291b54d6992362ac332015450a49d8cf Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Sat, 29 Jul 2023 18:40:59 +0800 Subject: [PATCH 4/8] fix: use tmjson to marshal status --- client/rpc/status.go | 42 ++---------------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/client/rpc/status.go b/client/rpc/status.go index 6cbec21849c5..2fc047d17e62 100644 --- a/client/rpc/status.go +++ b/client/rpc/status.go @@ -2,34 +2,15 @@ package rpc import ( "context" - "encoding/json" - "github.com/cometbft/cometbft/p2p" + 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" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" ) -// ValidatorInfo is info about the node's validator, same as CometBFT, -// except that we use our own PubKey. -type validatorInfo struct { - Address []byte `json:"address"` - PubKey cryptotypes.PubKey `json:"pub_key"` - VotingPower int64 `json:"voting_power"` -} - -// ResultStatus is node's info, same as CometBFT, except that we use our own -// PubKey. -type resultStatus struct { - NodeInfo p2p.DefaultNodeInfo `json:"node_info"` - SyncInfo coretypes.SyncInfo `json:"sync_info"` - ValidatorInfo validatorInfo `json:"validator_info"` -} - // StatusCommand returns the command to return the status of the network. func StatusCommand() *cobra.Command { cmd := &cobra.Command{ @@ -46,29 +27,10 @@ func StatusCommand() *cobra.Command { return err } - var pk cryptotypes.PubKey - // `status` has TM pubkeys, we need to convert them to our pubkeys. - if status.ValidatorInfo.PubKey != nil { - pk, err = cryptocodec.FromCmtPubKeyInterface(status.ValidatorInfo.PubKey) - if err != nil { - return err - } - } - statusWithPk := resultStatus{ - NodeInfo: status.NodeInfo, - SyncInfo: status.SyncInfo, - ValidatorInfo: validatorInfo{ - Address: status.ValidatorInfo.Address, - PubKey: pk, - VotingPower: status.ValidatorInfo.VotingPower, - }, - } - - output, err := json.Marshal(statusWithPk) + output, err := cmtjson.Marshal(status) if err != nil { return err } - return clientCtx.PrintRaw(output) }, } From d78609fa5c5fab9321729487986476975cb4b6aa Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Sun, 30 Jul 2023 10:10:35 +0800 Subject: [PATCH 5/8] fix: default json format output --- client/rpc/status.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/client/rpc/status.go b/client/rpc/status.go index 2fc047d17e62..5f50ae36af14 100644 --- a/client/rpc/status.go +++ b/client/rpc/status.go @@ -31,6 +31,13 @@ func StatusCommand() *cobra.Command { 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) }, } From 645f7238de6eabab252802526bcfbe7b80ffd21b Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Sun, 30 Jul 2023 10:12:38 +0800 Subject: [PATCH 6/8] chore: update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa0fe324d1ec..9b16fb6e6158 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features * (x/bank) [#16795](https://github.com/cosmos/cosmos-sdk/pull/16852) Add `DenomMetadataByQueryString` query in bank module to support metadata query by query string. +* (cli) [#17184](https://github.com/cosmos/cosmos-sdk/pull/17184) `status` command add support for text format output ### Improvements From d2c963825dc78794a80b0d1d693a8594544a155d Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Sun, 30 Jul 2023 16:39:34 +0800 Subject: [PATCH 7/8] chore: update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b16fb6e6158..76371c07f979 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,7 +41,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features * (x/bank) [#16795](https://github.com/cosmos/cosmos-sdk/pull/16852) Add `DenomMetadataByQueryString` query in bank module to support metadata query by query string. -* (cli) [#17184](https://github.com/cosmos/cosmos-sdk/pull/17184) `status` command add support for text format output ### Improvements @@ -94,6 +93,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (server) [#17177](https://github.com/cosmos/cosmos-sdk/pull/17177) Remove `iavl-lazy-loading` configuration. * (rosetta) [#16276](https://github.com/cosmos/cosmos-sdk/issues/16276) Rosetta migration to standalone repo. +* (cli) [#17184](https://github.com/cosmos/cosmos-sdk/pull/17184) `status` command add support for text format output ## [v0.50.0-beta.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.0-beta.0) - 2023-07-19 From 9695a978144ba71bb7d94fdefb61561e93d82483 Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Sun, 30 Jul 2023 16:57:31 +0800 Subject: [PATCH 8/8] chore: update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76371c07f979..8dd8471d2810 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -93,7 +93,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (server) [#17177](https://github.com/cosmos/cosmos-sdk/pull/17177) Remove `iavl-lazy-loading` configuration. * (rosetta) [#16276](https://github.com/cosmos/cosmos-sdk/issues/16276) Rosetta migration to standalone repo. -* (cli) [#17184](https://github.com/cosmos/cosmos-sdk/pull/17184) `status` command add support for text format output +* (cli) [#17184](https://github.com/cosmos/cosmos-sdk/pull/17184) All json keys returned by the `status` command are now snake case instead of pascal case. ## [v0.50.0-beta.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.0-beta.0) - 2023-07-19