Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,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) 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

Expand Down
50 changes: 10 additions & 40 deletions client/rpc/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
zakir-code marked this conversation as resolved.
Show resolved Hide resolved
},
}

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
}
Expand Down