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"
|
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2018-05-31 18:02:10 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
2019-12-23 08:05:47 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2018-05-31 18:02:10 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-06-05 16:26:17 -07:00
|
|
|
|
2019-07-19 06:43:38 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/slashing/internal/types"
|
2018-05-31 18:02:10 -07:00
|
|
|
)
|
|
|
|
|
2019-06-05 16:26:17 -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,
|
2019-06-15 05:34:11 -07:00
|
|
|
RunE: client.ValidateCmd,
|
2019-06-05 16:26:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
slashingQueryCmd.AddCommand(
|
2019-12-23 08:05:47 -08:00
|
|
|
flags.GetCommands(
|
2019-06-05 16:26:17 -07:00
|
|
|
GetCmdQuerySigningInfo(queryRoute, cdc),
|
|
|
|
GetCmdQueryParams(cdc),
|
|
|
|
)...,
|
|
|
|
)
|
|
|
|
|
|
|
|
return slashingQueryCmd
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQuerySigningInfo implements the command to query signing info.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdQuerySigningInfo(storeName string, cdc *codec.Codec) *cobra.Command {
|
2019-01-22 09:28:39 -08:00
|
|
|
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:
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
$ <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 {
|
2019-01-22 09:28:39 -08:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
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())
|
2019-06-05 16:26:17 -07:00
|
|
|
key := types.GetValidatorSigningInfoKey(consAddr)
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2019-06-13 06:54:17 -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
|
|
|
}
|
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
var signingInfo types.ValidatorSigningInfo
|
2019-01-28 11:37:05 -08:00
|
|
|
cdc.MustUnmarshalBinaryLengthPrefixed(res, &signingInfo)
|
2019-01-22 09:28:39 -08:00
|
|
|
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 {
|
2019-01-22 09:28:39 -08:00
|
|
|
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:
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
$ <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)
|
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
route := fmt.Sprintf("custom/%s/parameters", types.QuerierRoute)
|
2019-06-13 06:54:17 -07:00
|
|
|
res, _, err := cliCtx.QueryWithData(route, nil)
|
2018-12-14 11:09:39 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
var params types.Params
|
2019-01-22 09:28:39 -08:00
|
|
|
cdc.MustUnmarshalJSON(res, ¶ms)
|
|
|
|
return cliCtx.PrintOutput(params)
|
2018-12-14 11:09:39 -08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|