2018-04-25 07:18:06 -07:00
|
|
|
package cli
|
2018-02-24 05:19:32 -08:00
|
|
|
|
|
|
|
import (
|
2018-02-25 15:45:20 -08:00
|
|
|
"fmt"
|
2019-02-06 16:15:37 -08:00
|
|
|
"strings"
|
2018-02-25 15:45:20 -08:00
|
|
|
|
2018-02-24 05:19:32 -08:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2018-04-02 05:05:23 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
2018-09-13 11:17:32 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2018-03-17 11:18:04 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-01-11 12:08:01 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
2018-02-24 05:19:32 -08:00
|
|
|
)
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQueryValidator implements the validator query command.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdQueryValidator(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: "validator [validator-addr]",
|
2018-05-17 08:12:28 -07:00
|
|
|
Short: "Query a validator",
|
2019-02-06 16:15:37 -08:00
|
|
|
Long: strings.TrimSpace(`Query details about an individual validator:
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
$ <appcli> query staking validator cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
|
2019-02-06 16:15:37 -08:00
|
|
|
`),
|
|
|
|
Args: cobra.ExactArgs(1),
|
2018-03-16 13:36:16 -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
|
|
|
addr, err := sdk.ValAddressFromBech32(args[0])
|
2018-03-16 13:36:16 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
res, err := cliCtx.QueryStore(staking.GetValidatorKey(addr), storeName)
|
2018-03-16 13:36:16 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-05-26 14:21:29 -07:00
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2019-02-06 16:15:37 -08:00
|
|
|
if len(res) == 0 {
|
|
|
|
return fmt.Errorf("No validator found with address %s", addr)
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
return cliCtx.PrintOutput(types.MustUnmarshalValidator(cdc, res))
|
2018-03-16 13:36:16 -07:00
|
|
|
},
|
|
|
|
}
|
2018-02-24 05:19:32 -08:00
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQueryValidators implements the query all validators command.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdQueryValidators(storeName string, cdc *codec.Codec) *cobra.Command {
|
2019-01-22 09:28:39 -08:00
|
|
|
return &cobra.Command{
|
2018-05-17 08:12:28 -07:00
|
|
|
Use: "validators",
|
|
|
|
Short: "Query for all validators",
|
2019-01-22 09:28:39 -08:00
|
|
|
Args: cobra.NoArgs,
|
2019-02-06 16:15:37 -08:00
|
|
|
Long: strings.TrimSpace(`Query details about all validators on a network:
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
$ <appcli> query staking validators
|
2019-02-06 16:15:37 -08:00
|
|
|
`),
|
2018-05-08 09:47:31 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
resKVs, err := cliCtx.QuerySubspace(staking.ValidatorsKey, storeName)
|
2018-05-08 09:47:31 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
var validators staking.Validators
|
2018-07-03 21:29:02 -07:00
|
|
|
for _, kv := range resKVs {
|
2019-01-22 09:28:39 -08:00
|
|
|
validators = append(validators, types.MustUnmarshalValidator(cdc, kv.Value))
|
2018-05-08 09:47:31 -07:00
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
return cliCtx.PrintOutput(validators)
|
2018-05-08 09:47:31 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-28 14:28:12 -07:00
|
|
|
// GetCmdQueryValidatorUnbondingDelegations implements the query all unbonding delegatations from a validator command.
|
2018-11-19 09:02:34 -08:00
|
|
|
func GetCmdQueryValidatorUnbondingDelegations(storeKey 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: "unbonding-delegations-from [validator-addr]",
|
2018-10-28 14:28:12 -07:00
|
|
|
Short: "Query all unbonding delegatations from a validator",
|
2019-02-06 16:15:37 -08:00
|
|
|
Long: strings.TrimSpace(`Query delegations that are unbonding _from_ a validator:
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
$ <appcli> query staking unbonding-delegations-from cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
|
2019-02-06 16:15:37 -08:00
|
|
|
`),
|
|
|
|
Args: cobra.ExactArgs(1),
|
2018-10-28 14:28:12 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2019-01-22 09:28:39 -08:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
2018-10-28 14:28:12 -07:00
|
|
|
valAddr, err := sdk.ValAddressFromBech32(args[0])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
bz, err := cdc.MarshalJSON(staking.NewQueryValidatorParams(valAddr))
|
2018-10-28 14:28:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
route := fmt.Sprintf("custom/%s/%s", storeKey, staking.QueryValidatorUnbondingDelegations)
|
|
|
|
res, err := cliCtx.QueryWithData(route, bz)
|
2018-10-28 14:28:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
var ubds staking.UnbondingDelegations
|
|
|
|
cdc.MustUnmarshalJSON(res, &ubds)
|
|
|
|
return cliCtx.PrintOutput(ubds)
|
2018-10-28 14:28:12 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
// GetCmdQueryValidatorRedelegations implements the query all redelegatations
|
|
|
|
// from a validator command.
|
2018-11-19 09:02:34 -08:00
|
|
|
func GetCmdQueryValidatorRedelegations(storeKey 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: "redelegations-from [validator-addr]",
|
2018-10-28 14:28:12 -07:00
|
|
|
Short: "Query all outgoing redelegatations from a validator",
|
2019-02-06 16:15:37 -08:00
|
|
|
Long: strings.TrimSpace(`Query delegations that are redelegating _from_ a validator:
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
$ <appcli> query staking redelegations-from cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
|
2019-02-06 16:15:37 -08:00
|
|
|
`),
|
|
|
|
Args: cobra.ExactArgs(1),
|
2018-10-28 14:28:12 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2019-01-22 09:28:39 -08:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
valSrcAddr, err := sdk.ValAddressFromBech32(args[0])
|
2018-10-28 14:28:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
bz, err := cdc.MarshalJSON(staking.QueryRedelegationParams{SrcValidatorAddr: valSrcAddr})
|
2018-10-28 14:28:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
route := fmt.Sprintf("custom/%s/%s", storeKey, staking.QueryRedelegations)
|
2019-01-22 09:28:39 -08:00
|
|
|
res, err := cliCtx.QueryWithData(route, bz)
|
2018-10-28 14:28:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
var resp staking.RedelegationResponses
|
|
|
|
if err := cdc.UnmarshalJSON(res, &resp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return cliCtx.PrintOutput(resp)
|
2018-10-28 14:28:12 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQueryDelegation the query delegation command.
|
2019-05-15 07:44:47 -07:00
|
|
|
func GetCmdQueryDelegation(storeKey string, cdc *codec.Codec) *cobra.Command {
|
2019-01-22 09:28:39 -08:00
|
|
|
return &cobra.Command{
|
|
|
|
Use: "delegation [delegator-addr] [validator-addr]",
|
2018-06-26 19:00:12 -07:00
|
|
|
Short: "Query a delegation based on address and validator address",
|
2019-02-06 16:15:37 -08:00
|
|
|
Long: strings.TrimSpace(`Query delegations for an individual delegator on an individual validator:
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
$ <appcli> query staking delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
|
2019-02-06 16:15:37 -08:00
|
|
|
`),
|
|
|
|
Args: cobra.ExactArgs(2),
|
2018-03-16 13:36:16 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2019-01-22 09:28:39 -08:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
delAddr, err := sdk.AccAddressFromBech32(args[0])
|
2018-03-16 13:36:16 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
valAddr, err := sdk.ValAddressFromBech32(args[1])
|
2018-03-16 13:36:16 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
bz, err := cdc.MarshalJSON(staking.NewQueryBondsParams(delAddr, valAddr))
|
2018-03-16 13:36:16 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
route := fmt.Sprintf("custom/%s/%s", storeKey, staking.QueryDelegation)
|
|
|
|
res, err := cliCtx.QueryWithData(route, bz)
|
2018-08-15 12:49:06 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-05-26 14:21:29 -07:00
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
var resp staking.DelegationResp
|
|
|
|
if err := cdc.UnmarshalJSON(res, &resp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return cliCtx.PrintOutput(resp)
|
2018-03-16 13:36:16 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2018-02-24 05:19:32 -08:00
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQueryDelegations implements the command to query all the delegations
|
|
|
|
// made from one delegator.
|
2019-05-15 07:44:47 -07:00
|
|
|
func GetCmdQueryDelegations(storeKey string, cdc *codec.Codec) *cobra.Command {
|
2019-01-22 09:28:39 -08:00
|
|
|
return &cobra.Command{
|
2018-05-17 08:12:28 -07:00
|
|
|
Use: "delegations [delegator-addr]",
|
2019-02-06 16:15:37 -08:00
|
|
|
Short: "Query all delegations made by one delegator",
|
|
|
|
Long: strings.TrimSpace(`Query delegations for an individual delegator on all validators:
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
$ <appcli> query staking delegations cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p
|
2019-02-06 16:15:37 -08:00
|
|
|
`),
|
|
|
|
Args: cobra.ExactArgs(1),
|
2018-05-08 12:55:40 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2019-01-22 09:28:39 -08:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
delAddr, err := sdk.AccAddressFromBech32(args[0])
|
2018-05-08 12:55:40 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
bz, err := cdc.MarshalJSON(staking.NewQueryDelegatorParams(delAddr))
|
2018-05-08 12:55:40 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
route := fmt.Sprintf("custom/%s/%s", storeKey, staking.QueryDelegatorDelegations)
|
|
|
|
res, err := cliCtx.QueryWithData(route, bz)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-05-08 12:55:40 -07:00
|
|
|
}
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
var resp staking.DelegationResponses
|
|
|
|
if err := cdc.UnmarshalJSON(res, &resp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return cliCtx.PrintOutput(resp)
|
2018-05-08 12:55:40 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2018-10-23 01:25:53 -07:00
|
|
|
// GetCmdQueryValidatorDelegations implements the command to query all the
|
|
|
|
// delegations to a specific validator.
|
2018-11-19 09:02:34 -08:00
|
|
|
func GetCmdQueryValidatorDelegations(storeKey string, cdc *codec.Codec) *cobra.Command {
|
2019-01-22 09:28:39 -08:00
|
|
|
return &cobra.Command{
|
2018-10-23 01:25:53 -07:00
|
|
|
Use: "delegations-to [validator-addr]",
|
|
|
|
Short: "Query all delegations made to one validator",
|
2019-02-06 16:15:37 -08:00
|
|
|
Long: strings.TrimSpace(`Query delegations on an individual validator:
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
$ <appcli> query staking delegations-to cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
|
2019-02-06 16:15:37 -08:00
|
|
|
`),
|
|
|
|
Args: cobra.ExactArgs(1),
|
2018-10-23 01:25:53 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2019-01-22 09:28:39 -08:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
valAddr, err := sdk.ValAddressFromBech32(args[0])
|
2018-10-23 01:25:53 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
bz, err := cdc.MarshalJSON(staking.NewQueryValidatorParams(valAddr))
|
2018-10-23 01:25:53 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
route := fmt.Sprintf("custom/%s/%s", storeKey, staking.QueryValidatorDelegations)
|
|
|
|
res, err := cliCtx.QueryWithData(route, bz)
|
2018-10-23 01:25:53 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
var resp staking.DelegationResponses
|
|
|
|
if err := cdc.UnmarshalJSON(res, &resp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return cliCtx.PrintOutput(resp)
|
2018-10-23 01:25:53 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQueryUnbondingDelegation implements the command to query a single
|
|
|
|
// unbonding-delegation record.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdQueryUnbondingDelegation(storeName string, cdc *codec.Codec) *cobra.Command {
|
2019-01-22 09:28:39 -08:00
|
|
|
return &cobra.Command{
|
|
|
|
Use: "unbonding-delegation [delegator-addr] [validator-addr]",
|
2018-06-26 19:00:12 -07:00
|
|
|
Short: "Query an unbonding-delegation record based on delegator and validator address",
|
2019-02-06 16:15:37 -08:00
|
|
|
Long: strings.TrimSpace(`Query unbonding delegations for an individual delegator on an individual validator:
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
$ <appcli> query staking unbonding-delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
|
2019-02-06 16:15:37 -08:00
|
|
|
`),
|
|
|
|
Args: cobra.ExactArgs(2),
|
2018-06-26 19:00:12 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2019-01-22 09:28:39 -08:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
|
|
|
valAddr, err := sdk.ValAddressFromBech32(args[1])
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
delAddr, err := sdk.AccAddressFromBech32(args[0])
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
res, err := cliCtx.QueryStore(staking.GetUBDKey(delAddr, valAddr), storeName)
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
return cliCtx.PrintOutput(types.MustUnmarshalUBD(cdc, res))
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQueryUnbondingDelegations implements the command to query all the
|
|
|
|
// unbonding-delegation records for a delegator.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdQueryUnbondingDelegations(storeName string, cdc *codec.Codec) *cobra.Command {
|
2019-01-22 09:28:39 -08:00
|
|
|
return &cobra.Command{
|
2018-06-26 19:00:12 -07:00
|
|
|
Use: "unbonding-delegations [delegator-addr]",
|
|
|
|
Short: "Query all unbonding-delegations records for one delegator",
|
2019-02-06 16:15:37 -08:00
|
|
|
Long: strings.TrimSpace(`Query unbonding delegations for an individual delegator:
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
$ <appcli> query staking unbonding-delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p
|
2019-02-06 16:15:37 -08:00
|
|
|
`),
|
|
|
|
Args: cobra.ExactArgs(1),
|
2018-06-26 19:00:12 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2019-01-22 09:28:39 -08:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
2018-07-09 16:06:05 -07:00
|
|
|
delegatorAddr, err := sdk.AccAddressFromBech32(args[0])
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
resKVs, err := cliCtx.QuerySubspace(staking.GetUBDsKey(delegatorAddr), storeName)
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
var ubds staking.UnbondingDelegations
|
2018-07-03 21:29:02 -07:00
|
|
|
for _, kv := range resKVs {
|
2019-01-22 09:28:39 -08:00
|
|
|
ubds = append(ubds, types.MustUnmarshalUBD(cdc, kv.Value))
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
return cliCtx.PrintOutput(ubds)
|
2018-06-26 19:00:12 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQueryRedelegation implements the command to query a single
|
2018-08-15 07:59:46 -07:00
|
|
|
// redelegation record.
|
2019-05-15 07:44:47 -07:00
|
|
|
func GetCmdQueryRedelegation(storeKey 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: "redelegation [delegator-addr] [src-validator-addr] [dst-validator-addr]",
|
2018-08-15 07:59:46 -07:00
|
|
|
Short: "Query a redelegation record based on delegator and a source and destination validator address",
|
2019-02-06 16:15:37 -08:00
|
|
|
Long: strings.TrimSpace(`Query a redelegation record for an individual delegator between a source and destination validator:
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
$ <appcli> query staking redelegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
|
2019-02-06 16:15:37 -08:00
|
|
|
`),
|
|
|
|
Args: cobra.ExactArgs(3),
|
2018-06-26 19:00:12 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2019-01-22 09:28:39 -08:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
delAddr, err := sdk.AccAddressFromBech32(args[0])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
valSrcAddr, err := sdk.ValAddressFromBech32(args[1])
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
valDstAddr, err := sdk.ValAddressFromBech32(args[2])
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
bz, err := cdc.MarshalJSON(staking.NewQueryRedelegationParams(delAddr, valSrcAddr, valDstAddr))
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
route := fmt.Sprintf("custom/%s/%s", storeKey, staking.QueryRedelegations)
|
|
|
|
res, err := cliCtx.QueryWithData(route, bz)
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
var resp staking.RedelegationResponses
|
|
|
|
if err := cdc.UnmarshalJSON(res, &resp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return cliCtx.PrintOutput(resp)
|
2018-06-26 19:00:12 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQueryRedelegations implements the command to query all the
|
2018-08-15 07:59:46 -07:00
|
|
|
// redelegation records for a delegator.
|
2019-05-15 07:44:47 -07:00
|
|
|
func GetCmdQueryRedelegations(storeKey string, cdc *codec.Codec) *cobra.Command {
|
2019-01-22 09:28:39 -08:00
|
|
|
return &cobra.Command{
|
2018-08-15 07:59:46 -07:00
|
|
|
Use: "redelegations [delegator-addr]",
|
2018-06-26 19:00:12 -07:00
|
|
|
Args: cobra.ExactArgs(1),
|
2019-02-06 16:15:37 -08:00
|
|
|
Short: "Query all redelegations records for one delegator",
|
|
|
|
Long: strings.TrimSpace(`Query all redelegation records for an individual delegator:
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
$ <appcli> query staking redelegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p
|
2019-02-06 16:15:37 -08:00
|
|
|
`),
|
2018-06-26 19:00:12 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2019-01-22 09:28:39 -08:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
delAddr, err := sdk.AccAddressFromBech32(args[0])
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
bz, err := cdc.MarshalJSON(staking.QueryRedelegationParams{DelegatorAddr: delAddr})
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
route := fmt.Sprintf("custom/%s/%s", storeKey, staking.QueryRedelegations)
|
|
|
|
res, err := cliCtx.QueryWithData(route, bz)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var resp staking.RedelegationResponses
|
|
|
|
if err := cdc.UnmarshalJSON(res, &resp); err != nil {
|
|
|
|
return err
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
return cliCtx.PrintOutput(resp)
|
2018-06-26 19:00:12 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2018-08-21 08:32:54 -07:00
|
|
|
|
|
|
|
// GetCmdQueryPool implements the pool query command.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdQueryPool(storeName string, cdc *codec.Codec) *cobra.Command {
|
2019-01-22 09:28:39 -08:00
|
|
|
return &cobra.Command{
|
2018-08-21 08:32:54 -07:00
|
|
|
Use: "pool",
|
2018-08-28 09:59:42 -07:00
|
|
|
Args: cobra.NoArgs,
|
2019-02-06 16:15:37 -08:00
|
|
|
Short: "Query the current staking pool values",
|
|
|
|
Long: strings.TrimSpace(`Query values for amounts stored in the staking pool:
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
$ <appcli> query staking pool
|
2019-02-06 16:15:37 -08:00
|
|
|
`),
|
2018-08-21 08:32:54 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
res, err := cliCtx.QueryStore(staking.PoolKey, storeName)
|
2018-08-21 08:32:54 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
return cliCtx.PrintOutput(types.MustUnmarshalPool(cdc, res))
|
2018-08-21 08:32:54 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCmdQueryPool implements the params query command.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdQueryParams(storeName string, cdc *codec.Codec) *cobra.Command {
|
2019-01-22 09:28:39 -08:00
|
|
|
return &cobra.Command{
|
|
|
|
Use: "params",
|
2018-08-28 09:59:42 -07:00
|
|
|
Args: cobra.NoArgs,
|
2019-02-06 16:15:37 -08:00
|
|
|
Short: "Query the current staking parameters information",
|
|
|
|
Long: strings.TrimSpace(`Query values set as staking parameters:
|
|
|
|
|
2019-05-18 01:42:24 -07:00
|
|
|
$ <appcli> query staking params
|
2019-02-06 16:15:37 -08:00
|
|
|
`),
|
2018-08-21 08:32:54 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
route := fmt.Sprintf("custom/%s/%s", storeName, staking.QueryParameters)
|
|
|
|
bz, err := cliCtx.QueryWithData(route, nil)
|
2018-08-21 08:32:54 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
var params staking.Params
|
|
|
|
cdc.MustUnmarshalJSON(bz, ¶ms)
|
|
|
|
return cliCtx.PrintOutput(params)
|
2018-08-21 08:32:54 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|