cosmos-sdk/x/slashing/client/cli/query.go
Anil Kumar Kammari d55c1a2665
Change address from bytes to bech32 strings (#7242)
* init

* Fix bank proto messages

* missing conversions

* remove casttype for addresses

* Fix tests

* Fix consaddress

* more test fixes

* Fix tests

* fixed tests

* migrate missing proto declarations

* format

* Fix format

* Fix alignment

* Fix more tests

* Fix ibc merge issue

* Fix fmt

* Fix more tests

* Fix missing address declarations

* Fix staking tests

* Fix more tests

* Fix config

* fixed tests

* Fix more tests

* Update staking grpc tests

* Fix merge issue

* fixed failing tests in x/distr

* fixed sim tests

* fixed failing tests

* Fix bugs

* Add logs

* fixed slashing issue

* Fix staking grpc tests

* Fix all bank tests :)

* Fix tests in distribution

* Fix more tests in distr

* Fix slashing tests

* Fix statking tests

* Fix evidence tests

* Fix gov tests

* Fix bug in create vesting account

* Fix test

* remove fmt

* fixed gov tests

* fixed x/ibc tests

* fixed x/ibc-transfer tests

* fixed staking tests

* fixed staking tests

* fixed test

* fixed distribution issue

* fix pagination test

* fmt

* lint

* fix build

* fix format

* revert tally tests

* revert tally tests

* lint

* Fix sim test

* revert

* revert

* fixed tally issue

* fix tests

* revert

* fmt

* refactor

* remove `GetAddress()`

* remove fmt

* revert fmt.Striger usage

* Fix tests

* Fix rest test

* disable interfacer lint check

* make proto-format

* add nolint rule

* remove stray println

Co-authored-by: aleem1314 <aleem.md789@gmail.com>
Co-authored-by: atheesh <atheesh@vitwit.com>
2020-09-25 10:25:37 +00:00

150 lines
3.9 KiB
Go

package cli
import (
"context"
"strings"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/slashing/types"
)
// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd() *cobra.Command {
// Group slashing queries under a subcommand
slashingQueryCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the slashing module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
slashingQueryCmd.AddCommand(
GetCmdQuerySigningInfo(),
GetCmdQueryParams(),
GetCmdQuerySigningInfos(),
)
return slashingQueryCmd
}
// GetCmdQuerySigningInfo implements the command to query signing info.
func GetCmdQuerySigningInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "signing-info [validator-conspub]",
Short: "Query a validator's signing information",
Long: strings.TrimSpace(`Use a validators' consensus public key to find the signing-info for that validator:
$ <appcli> query slashing signing-info cosmosvalconspub1zcjduepqfhvwcmt7p06fvdgexxhmz0l8c7sgswl7ulv7aulk364x4g5xsw7sr0k2g5
`),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, args[0])
if err != nil {
return err
}
consAddr := sdk.ConsAddress(pk.Address())
params := &types.QuerySigningInfoRequest{ConsAddress: consAddr.String()}
res, err := queryClient.SigningInfo(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintOutput(&res.ValSigningInfo)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// GetCmdQuerySigningInfos implements the command to query signing infos.
func GetCmdQuerySigningInfos() *cobra.Command {
cmd := &cobra.Command{
Use: "signing-infos",
Short: "Query signing information of all validators",
Long: strings.TrimSpace(`signing infos of validators:
$ <appcli> query slashing signing-infos
`),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
params := &types.QuerySigningInfosRequest{Pagination: pageReq}
res, err := queryClient.SigningInfos(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintOutput(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "signing infos")
return cmd
}
// GetCmdQueryParams implements a command to fetch slashing parameters.
func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query the current slashing parameters",
Args: cobra.NoArgs,
Long: strings.TrimSpace(`Query genesis parameters for the slashing module:
$ <appcli> query slashing params
`),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryParamsRequest{}
res, err := queryClient.Params(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintOutput(&res.Params)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}