cosmos-sdk/x/slashing/client/cli/query.go

101 lines
2.8 KiB
Go
Raw Normal View History

2018-05-31 18:02:10 -07:00
package cli
import (
"fmt"
2019-02-06 16:15:37 -08:00
"strings"
2018-05-31 18:02:10 -07:00
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
2018-05-31 18:02:10 -07:00
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
2018-05-31 18:02:10 -07:00
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/slashing/internal/types"
2018-05-31 18:02:10 -07:00
)
// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *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(
client.GetCommands(
GetCmdQuerySigningInfo(queryRoute, cdc),
GetCmdQueryParams(cdc),
)...,
)
return slashingQueryCmd
}
2018-08-06 11:11:30 -07:00
// GetCmdQuerySigningInfo implements the command to query signing info.
func GetCmdQuerySigningInfo(storeName string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
2019-02-06 16:15:37 -08:00
Use: "signing-info [validator-conspub]",
2018-05-31 18:02:10 -07:00
Short: "Query a validator's signing information",
2019-02-06 16:15:37 -08:00
Long: strings.TrimSpace(`Use a validators' consensus public key to find the signing-info for that validator:
$ <appcli> query slashing signing-info cosmosvalconspub1zcjduepqfhvwcmt7p06fvdgexxhmz0l8c7sgswl7ulv7aulk364x4g5xsw7sr0k2g5
2019-02-06 16:15:37 -08:00
`),
Args: cobra.ExactArgs(1),
2018-05-31 18:02:10 -07:00
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
pk, err := sdk.GetConsPubKeyBech32(args[0])
2018-05-31 18:02:10 -07:00
if err != nil {
return err
}
2018-08-06 11:11:30 -07:00
2019-01-28 11:37:05 -08:00
consAddr := sdk.ConsAddress(pk.Address())
key := types.GetValidatorSigningInfoKey(consAddr)
2018-08-06 11:11:30 -07:00
res, _, err := cliCtx.QueryStore(key, storeName)
2018-05-31 18:02:10 -07:00
if err != nil {
return err
}
2018-08-06 11:11:30 -07:00
2019-01-28 11:37:05 -08:00
if len(res) == 0 {
2019-08-19 09:06:27 -07:00
return fmt.Errorf("validator %s not found in slashing store", consAddr)
2019-01-28 11:37:05 -08:00
}
var signingInfo types.ValidatorSigningInfo
2019-01-28 11:37:05 -08:00
cdc.MustUnmarshalBinaryLengthPrefixed(res, &signingInfo)
return cliCtx.PrintOutput(signingInfo)
2018-05-31 18:02:10 -07:00
},
}
}
2018-12-14 11:09:39 -08:00
// GetCmdQueryParams implements a command to fetch slashing parameters.
func GetCmdQueryParams(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
2018-12-14 11:09:39 -08:00
Use: "params",
Short: "Query the current slashing parameters",
2019-02-06 16:15:37 -08:00
Args: cobra.NoArgs,
Long: strings.TrimSpace(`Query genesis parameters for the slashing module:
$ <appcli> query slashing params
2019-02-06 16:15:37 -08:00
`),
2018-12-14 11:09:39 -08:00
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
route := fmt.Sprintf("custom/%s/parameters", types.QuerierRoute)
res, _, err := cliCtx.QueryWithData(route, nil)
2018-12-14 11:09:39 -08:00
if err != nil {
return err
}
var params types.Params
cdc.MustUnmarshalJSON(res, &params)
return cliCtx.PrintOutput(params)
2018-12-14 11:09:39 -08:00
},
}
}