feat(cli): status cmd cli support output text (backport #17184) (#17237)

Co-authored-by: zakir <80246097+zakir-code@users.noreply.github.com>
This commit is contained in:
mergify[bot] 2023-08-01 08:48:53 +00:00 committed by GitHub
parent a1f1104d7a
commit ff6a9a6a7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 40 deletions

View File

@ -71,6 +71,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) 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

View File

@ -3,32 +3,14 @@ package rpc
import (
"context"
"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
PubKey cryptotypes.PubKey
VotingPower int64
}
// 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
}
// StatusCommand returns the command to return the status of the network.
func StatusCommand() *cobra.Command {
cmd := &cobra.Command{
@ -45,35 +27,23 @@ 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 := clientCtx.LegacyAmino.MarshalJSON(statusWithPk)
output, err := cmtjson.Marshal(status)
if err != nil {
return err
}
cmd.Println(string(output))
return nil
// 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
}