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

58 lines
1.3 KiB
Go
Raw Normal View History

2018-05-31 18:02:10 -07:00
package cli
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/libs/cli"
2018-05-31 18:02:10 -07:00
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire" // XXX fix
"github.com/cosmos/cosmos-sdk/x/slashing"
)
// get the command to query signing info
func GetCmdQuerySigningInfo(storeName string, cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{
2018-06-04 18:35:07 -07:00
Use: "signing-info [validator-pubkey]",
2018-05-31 18:02:10 -07:00
Short: "Query a validator's signing information",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
2018-06-01 12:32:26 -07:00
pk, err := sdk.GetValPubKeyBech32(args[0])
2018-05-31 18:02:10 -07:00
if err != nil {
return err
}
2018-07-05 13:36:51 -07:00
key := slashing.GetValidatorSigningInfoKey(sdk.Address(pk.Address()))
2018-05-31 18:02:10 -07:00
ctx := context.NewCoreContextFromViper()
res, err := ctx.QueryStore(key, storeName)
2018-05-31 18:02:10 -07:00
if err != nil {
return err
}
signingInfo := new(slashing.ValidatorSigningInfo)
cdc.MustUnmarshalBinary(res, signingInfo)
switch viper.Get(cli.OutputFlag) {
case "text":
human := signingInfo.HumanReadableString()
fmt.Println(human)
case "json":
// parse out the signing info
output, err := wire.MarshalJSONIndent(cdc, signingInfo)
if err != nil {
return err
}
fmt.Println(string(output))
}
return nil
},
}
return cmd
}