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"
|
|
|
|
|
2018-02-24 05:19:32 -08:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
2018-07-02 13:34:06 -07:00
|
|
|
"github.com/tendermint/tendermint/libs/cli"
|
2018-02-24 05:19:32 -08:00
|
|
|
|
2018-04-02 05:05:23 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
2018-03-17 11:18:04 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-06-26 19:00:12 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/wire"
|
2018-02-25 15:45:20 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
2018-07-03 20:44:54 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
2018-02-24 05:19:32 -08:00
|
|
|
)
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQueryValidator implements the validator query command.
|
2018-05-09 21:01:58 -07:00
|
|
|
func GetCmdQueryValidator(storeName string, cdc *wire.Codec) *cobra.Command {
|
2018-03-16 13:36:16 -07:00
|
|
|
cmd := &cobra.Command{
|
2018-05-17 08:12:28 -07:00
|
|
|
Use: "validator [owner-addr]",
|
|
|
|
Short: "Query a validator",
|
2018-05-04 18:29:12 -07:00
|
|
|
Args: cobra.ExactArgs(1),
|
2018-03-16 13:36:16 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-07-09 16:06:05 -07:00
|
|
|
addr, err := sdk.AccAddressFromBech32(args[0])
|
2018-03-16 13:36:16 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-05-09 21:01:58 -07:00
|
|
|
key := stake.GetValidatorKey(addr)
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
|
|
|
res, err := cliCtx.QueryStore(key, storeName)
|
2018-03-16 13:36:16 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-07-05 18:24:00 -07:00
|
|
|
} else if len(res) == 0 {
|
|
|
|
return fmt.Errorf("No validator found with address %s", args[0])
|
2018-03-16 13:36:16 -07:00
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-07-04 14:07:06 -07:00
|
|
|
validator := types.MustUnmarshalValidator(cdc, addr, res)
|
2018-03-16 13:36:16 -07:00
|
|
|
|
2018-05-26 14:21:29 -07:00
|
|
|
switch viper.Get(cli.OutputFlag) {
|
|
|
|
case "text":
|
|
|
|
human, err := validator.HumanReadableString()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println(human)
|
|
|
|
|
|
|
|
case "json":
|
|
|
|
// parse out the validator
|
|
|
|
output, err := wire.MarshalJSONIndent(cdc, validator)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-05-26 14:21:29 -07:00
|
|
|
fmt.Println(string(output))
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
|
|
|
// TODO: output with proofs / machine parseable etc.
|
2018-05-10 17:51:48 -07:00
|
|
|
return nil
|
2018-03-16 13:36:16 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
2018-02-24 05:19:32 -08:00
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQueryValidators implements the query all validators command.
|
2018-05-10 17:51:48 -07:00
|
|
|
func GetCmdQueryValidators(storeName string, cdc *wire.Codec) *cobra.Command {
|
2018-05-08 09:47:31 -07:00
|
|
|
cmd := &cobra.Command{
|
2018-05-17 08:12:28 -07:00
|
|
|
Use: "validators",
|
|
|
|
Short: "Query for all validators",
|
2018-05-08 09:47:31 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-05-10 17:51:48 -07:00
|
|
|
key := stake.ValidatorsKey
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
|
|
|
resKVs, err := cliCtx.QuerySubspace(key, storeName)
|
2018-05-08 09:47:31 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-30 07:42:59 -07:00
|
|
|
// parse out the validators
|
|
|
|
var validators []stake.Validator
|
2018-07-03 21:29:02 -07:00
|
|
|
for _, kv := range resKVs {
|
2018-07-03 22:32:49 -07:00
|
|
|
addr := kv.Key[1:]
|
2018-07-04 14:07:06 -07:00
|
|
|
validator := types.MustUnmarshalValidator(cdc, addr, kv.Value)
|
2018-05-30 07:42:59 -07:00
|
|
|
validators = append(validators, validator)
|
2018-05-08 09:47:31 -07:00
|
|
|
}
|
|
|
|
|
2018-05-26 14:21:29 -07:00
|
|
|
switch viper.Get(cli.OutputFlag) {
|
|
|
|
case "text":
|
2018-05-30 07:53:12 -07:00
|
|
|
for _, validator := range validators {
|
|
|
|
resp, err := validator.HumanReadableString()
|
2018-05-26 14:21:29 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-05-26 14:21:29 -07:00
|
|
|
fmt.Println(resp)
|
|
|
|
}
|
|
|
|
case "json":
|
2018-05-30 07:53:12 -07:00
|
|
|
output, err := wire.MarshalJSONIndent(cdc, validators)
|
2018-05-26 14:21:29 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-05-26 14:21:29 -07:00
|
|
|
fmt.Println(string(output))
|
|
|
|
return nil
|
2018-05-08 09:47:31 -07:00
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// TODO: output with proofs / machine parseable etc.
|
|
|
|
return nil
|
2018-05-08 09:47:31 -07:00
|
|
|
},
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-05-08 09:47:31 -07:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQueryDelegation the query delegation command.
|
2018-05-09 18:39:14 -07:00
|
|
|
func GetCmdQueryDelegation(storeName string, cdc *wire.Codec) *cobra.Command {
|
2018-03-16 13:36:16 -07:00
|
|
|
cmd := &cobra.Command{
|
2018-05-17 08:12:28 -07:00
|
|
|
Use: "delegation",
|
2018-06-26 19:00:12 -07:00
|
|
|
Short: "Query a delegation based on address and validator address",
|
2018-03-16 13:36:16 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-07-09 16:06:05 -07:00
|
|
|
valAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidator))
|
2018-03-16 13:36:16 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-07-09 16:06:05 -07:00
|
|
|
delAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressDelegator))
|
2018-03-16 13:36:16 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-07-02 15:16:47 -07:00
|
|
|
key := stake.GetDelegationKey(delAddr, valAddr)
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
|
|
|
res, err := cliCtx.QueryStore(key, storeName)
|
2018-03-16 13:36:16 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
// parse out the delegation
|
2018-07-04 14:07:06 -07:00
|
|
|
delegation := types.MustUnmarshalDelegation(cdc, key, res)
|
2018-05-26 14:21:29 -07:00
|
|
|
|
|
|
|
switch viper.Get(cli.OutputFlag) {
|
|
|
|
case "text":
|
2018-06-26 19:00:12 -07:00
|
|
|
resp, err := delegation.HumanReadableString()
|
2018-05-26 14:21:29 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-05-26 14:21:29 -07:00
|
|
|
fmt.Println(resp)
|
|
|
|
case "json":
|
2018-06-26 19:00:12 -07:00
|
|
|
output, err := wire.MarshalJSONIndent(cdc, delegation)
|
2018-05-26 14:21:29 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-05-26 14:21:29 -07:00
|
|
|
fmt.Println(string(output))
|
|
|
|
return nil
|
2018-03-16 13:36:16 -07:00
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-03-16 13:36:16 -07:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-05-09 21:01:58 -07:00
|
|
|
cmd.Flags().AddFlagSet(fsValidator)
|
2018-04-17 21:33:33 -07:00
|
|
|
cmd.Flags().AddFlagSet(fsDelegator)
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-03-16 13:36:16 -07:00
|
|
|
return cmd
|
|
|
|
}
|
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.
|
2018-05-09 21:01:58 -07:00
|
|
|
func GetCmdQueryDelegations(storeName string, cdc *wire.Codec) *cobra.Command {
|
2018-05-08 12:55:40 -07:00
|
|
|
cmd := &cobra.Command{
|
2018-05-17 08:12:28 -07:00
|
|
|
Use: "delegations [delegator-addr]",
|
|
|
|
Short: "Query all delegations made from one delegator",
|
|
|
|
Args: cobra.ExactArgs(1),
|
2018-05-08 12:55:40 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-07-09 16:06:05 -07:00
|
|
|
delegatorAddr, 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
|
|
|
|
2018-07-02 15:16:47 -07:00
|
|
|
key := stake.GetDelegationsKey(delegatorAddr)
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
|
|
|
resKVs, err := cliCtx.QuerySubspace(key, storeName)
|
2018-05-08 12:55:40 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-30 07:42:59 -07:00
|
|
|
// parse out the validators
|
2018-05-09 21:01:58 -07:00
|
|
|
var delegations []stake.Delegation
|
2018-07-03 21:29:02 -07:00
|
|
|
for _, kv := range resKVs {
|
2018-07-04 14:07:06 -07:00
|
|
|
delegation := types.MustUnmarshalDelegation(cdc, kv.Key, kv.Value)
|
2018-05-09 21:01:58 -07:00
|
|
|
delegations = append(delegations, delegation)
|
2018-05-08 12:55:40 -07:00
|
|
|
}
|
|
|
|
|
2018-05-09 21:01:58 -07:00
|
|
|
output, err := wire.MarshalJSONIndent(cdc, delegations)
|
2018-05-08 12:55:40 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-05-08 12:55:40 -07:00
|
|
|
fmt.Println(string(output))
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// TODO: output with proofs / machine parseable etc.
|
|
|
|
return nil
|
2018-05-08 12:55:40 -07:00
|
|
|
},
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-05-08 12:55:40 -07:00
|
|
|
return cmd
|
|
|
|
}
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQueryUnbondingDelegation implements the command to query a single
|
|
|
|
// unbonding-delegation record.
|
2018-06-26 19:00:12 -07:00
|
|
|
func GetCmdQueryUnbondingDelegation(storeName string, cdc *wire.Codec) *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "unbonding-delegation",
|
|
|
|
Short: "Query an unbonding-delegation record based on delegator and validator address",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-07-09 16:06:05 -07:00
|
|
|
valAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidator))
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-07-09 16:06:05 -07:00
|
|
|
delAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressDelegator))
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-07-02 15:16:47 -07:00
|
|
|
key := stake.GetUBDKey(delAddr, valAddr)
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
|
|
|
res, err := cliCtx.QueryStore(key, storeName)
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse out the unbonding delegation
|
2018-07-04 14:07:06 -07:00
|
|
|
ubd := types.MustUnmarshalUBD(cdc, key, res)
|
2018-06-26 19:00:12 -07:00
|
|
|
|
|
|
|
switch viper.Get(cli.OutputFlag) {
|
|
|
|
case "text":
|
|
|
|
resp, err := ubd.HumanReadableString()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
fmt.Println(resp)
|
|
|
|
case "json":
|
|
|
|
output, err := wire.MarshalJSONIndent(cdc, ubd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
fmt.Println(string(output))
|
|
|
|
return nil
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Flags().AddFlagSet(fsValidator)
|
|
|
|
cmd.Flags().AddFlagSet(fsDelegator)
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQueryUnbondingDelegations implements the command to query all the
|
|
|
|
// unbonding-delegation records for a delegator.
|
2018-06-26 19:00:12 -07:00
|
|
|
func GetCmdQueryUnbondingDelegations(storeName string, cdc *wire.Codec) *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "unbonding-delegations [delegator-addr]",
|
|
|
|
Short: "Query all unbonding-delegations records for one delegator",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
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
|
|
|
|
2018-07-02 15:16:47 -07:00
|
|
|
key := stake.GetUBDsKey(delegatorAddr)
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
|
|
|
resKVs, err := cliCtx.QuerySubspace(key, storeName)
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse out the validators
|
|
|
|
var ubds []stake.UnbondingDelegation
|
2018-07-03 21:29:02 -07:00
|
|
|
for _, kv := range resKVs {
|
2018-07-04 14:07:06 -07:00
|
|
|
ubd := types.MustUnmarshalUBD(cdc, kv.Key, kv.Value)
|
2018-06-26 19:00:12 -07:00
|
|
|
ubds = append(ubds, ubd)
|
|
|
|
}
|
|
|
|
|
|
|
|
output, err := wire.MarshalJSONIndent(cdc, ubds)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
fmt.Println(string(output))
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// TODO: output with proofs / machine parseable etc.
|
|
|
|
return nil
|
2018-06-26 19:00:12 -07:00
|
|
|
},
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQueryRedelegation implements the command to query a single
|
|
|
|
// unbonding-delegation record.
|
2018-06-26 19:00:12 -07:00
|
|
|
func GetCmdQueryRedelegation(storeName string, cdc *wire.Codec) *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "unbonding-delegation",
|
|
|
|
Short: "Query an unbonding-delegation record based on delegator and validator address",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-07-09 16:06:05 -07:00
|
|
|
valSrcAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidatorSrc))
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-07-09 16:06:05 -07:00
|
|
|
valDstAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidatorDst))
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-07-09 16:06:05 -07:00
|
|
|
delAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressDelegator))
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-07-02 15:16:47 -07:00
|
|
|
key := stake.GetREDKey(delAddr, valSrcAddr, valDstAddr)
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
|
|
|
res, err := cliCtx.QueryStore(key, storeName)
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse out the unbonding delegation
|
2018-07-04 14:07:06 -07:00
|
|
|
red := types.MustUnmarshalRED(cdc, key, res)
|
2018-06-26 19:00:12 -07:00
|
|
|
|
|
|
|
switch viper.Get(cli.OutputFlag) {
|
|
|
|
case "text":
|
|
|
|
resp, err := red.HumanReadableString()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
fmt.Println(resp)
|
|
|
|
case "json":
|
|
|
|
output, err := wire.MarshalJSONIndent(cdc, red)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
fmt.Println(string(output))
|
|
|
|
return nil
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Flags().AddFlagSet(fsRedelegation)
|
|
|
|
cmd.Flags().AddFlagSet(fsDelegator)
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdQueryRedelegations implements the command to query all the
|
|
|
|
// unbonding-delegation records for a delegator.
|
2018-06-26 19:00:12 -07:00
|
|
|
func GetCmdQueryRedelegations(storeName string, cdc *wire.Codec) *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "unbonding-delegations [delegator-addr]",
|
|
|
|
Short: "Query all unbonding-delegations records for one delegator",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
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
|
|
|
|
2018-07-02 15:16:47 -07:00
|
|
|
key := stake.GetREDsKey(delegatorAddr)
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
|
|
|
resKVs, err := cliCtx.QuerySubspace(key, storeName)
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse out the validators
|
|
|
|
var reds []stake.Redelegation
|
2018-07-03 21:29:02 -07:00
|
|
|
for _, kv := range resKVs {
|
2018-07-04 14:07:06 -07:00
|
|
|
red := types.MustUnmarshalRED(cdc, kv.Key, kv.Value)
|
2018-06-26 19:00:12 -07:00
|
|
|
reds = append(reds, red)
|
|
|
|
}
|
|
|
|
|
|
|
|
output, err := wire.MarshalJSONIndent(cdc, reds)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
fmt.Println(string(output))
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// TODO: output with proofs / machine parseable etc.
|
|
|
|
return nil
|
2018-06-26 19:00:12 -07:00
|
|
|
},
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
return cmd
|
|
|
|
}
|