diff --git a/PENDING.md b/PENDING.md index f315af561e7e..aa7cca2c4a2c 100644 --- a/PENDING.md +++ b/PENDING.md @@ -18,6 +18,7 @@ FEATURES * Gaia REST API (`gaiacli advanced rest-server`) * Gaia CLI (`gaiacli`) + * [cli] [\#2569](https://github.com/cosmos/cosmos-sdk/pull/2569) Add commands to query validator unbondings and redelegations * Gaia diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index c375bcf4ec59..ad1549641bd9 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -285,6 +285,12 @@ func TestGaiaCLICreateValidator(t *testing.T) { validator = executeGetValidator(t, fmt.Sprintf("gaiacli query validator %s --output=json %v", sdk.ValAddress(barAddr), flags)) require.Equal(t, "1.0000000000", validator.Tokens.String()) + validatorUbds := executeGetValidatorUnbondingDelegations(t, + fmt.Sprintf("gaiacli query unbonding-delegations-from %s --output=json %v", + sdk.ValAddress(barAddr), flags)) + require.Len(t, validatorUbds, 1) + require.Equal(t, "1", validatorUbds[0].Balance.Amount.String()) + params := executeGetParams(t, fmt.Sprintf("gaiacli query parameters --output=json %v", flags)) require.True(t, defaultParams.Equal(params)) @@ -693,6 +699,24 @@ func executeGetValidator(t *testing.T, cmdStr string) stake.Validator { return validator } +func executeGetValidatorUnbondingDelegations(t *testing.T, cmdStr string) []stake.UnbondingDelegation { + out, _ := tests.ExecuteT(t, cmdStr, "") + var ubds []stake.UnbondingDelegation + cdc := app.MakeCodec() + err := cdc.UnmarshalJSON([]byte(out), &ubds) + require.NoError(t, err, "out %v\n, err %v", out, err) + return ubds +} + +func executeGetValidatorRedelegations(t *testing.T, cmdStr string) []stake.Redelegation { + out, _ := tests.ExecuteT(t, cmdStr, "") + var reds []stake.Redelegation + cdc := app.MakeCodec() + err := cdc.UnmarshalJSON([]byte(out), &reds) + require.NoError(t, err, "out %v\n, err %v", out, err) + return reds +} + func executeGetPool(t *testing.T, cmdStr string) stake.Pool { out, _ := tests.ExecuteT(t, cmdStr, "") var pool stake.Pool diff --git a/cmd/gaia/cmd/gaiacli/main.go b/cmd/gaia/cmd/gaiacli/main.go index a2804706b760..6f11e68a5acd 100644 --- a/cmd/gaia/cmd/gaiacli/main.go +++ b/cmd/gaia/cmd/gaiacli/main.go @@ -28,10 +28,11 @@ import ( ) const ( - storeAcc = "acc" - storeGov = "gov" - storeSlashing = "slashing" - storeStake = "stake" + storeAcc = "acc" + storeGov = "gov" + storeSlashing = "slashing" + storeStake = "stake" + queryRouteStake = "stake" ) // rootCmd is the entry point for this binary @@ -70,21 +71,23 @@ func main() { authcmd.GetAccountCmd(storeAcc, cdc, authcmd.GetAccountDecoder(cdc)), stakecmd.GetCmdQueryDelegation(storeStake, cdc), stakecmd.GetCmdQueryDelegations(storeStake, cdc), + stakecmd.GetCmdQueryUnbondingDelegation(storeStake, cdc), + stakecmd.GetCmdQueryUnbondingDelegations(storeStake, cdc), + stakecmd.GetCmdQueryRedelegation(storeStake, cdc), + stakecmd.GetCmdQueryRedelegations(storeStake, cdc), + stakecmd.GetCmdQueryValidator(storeStake, cdc), + stakecmd.GetCmdQueryValidators(storeStake, cdc), + stakecmd.GetCmdQueryValidatorUnbondingDelegations(queryRouteStake, cdc), + stakecmd.GetCmdQueryValidatorRedelegations(queryRouteStake, cdc), stakecmd.GetCmdQueryParams(storeStake, cdc), stakecmd.GetCmdQueryPool(storeStake, cdc), govcmd.GetCmdQueryProposal(storeGov, cdc), govcmd.GetCmdQueryProposals(storeGov, cdc), + govcmd.GetCmdQueryVote(storeGov, cdc), + govcmd.GetCmdQueryVotes(storeGov, cdc), govcmd.GetCmdQueryDeposit(storeGov, cdc), govcmd.GetCmdQueryDeposits(storeGov, cdc), - stakecmd.GetCmdQueryRedelegation(storeStake, cdc), - stakecmd.GetCmdQueryRedelegations(storeStake, cdc), slashingcmd.GetCmdQuerySigningInfo(storeSlashing, cdc), - stakecmd.GetCmdQueryUnbondingDelegation(storeStake, cdc), - stakecmd.GetCmdQueryUnbondingDelegations(storeStake, cdc), - stakecmd.GetCmdQueryValidator(storeStake, cdc), - stakecmd.GetCmdQueryValidators(storeStake, cdc), - govcmd.GetCmdQueryVote(storeGov, cdc), - govcmd.GetCmdQueryVotes(storeGov, cdc), )...) //Add query commands diff --git a/docs/sdk/clients.md b/docs/sdk/clients.md index 4703c492185c..f784dd238dd2 100644 --- a/docs/sdk/clients.md +++ b/docs/sdk/clients.md @@ -272,7 +272,13 @@ Or if you want to check all your current unbonding-delegations with disctinct va gaiacli query unbonding-delegations ``` -You can also get previous unbonding-delegation(s) status by adding the `--height` flag. +Additionally, as you can get all the unbonding-delegations from a particular validator: + +```bash + gaiacli query unbonding-delegations-from +``` + +To get previous unbonding-delegation(s) status on past blocks, try adding the `--height` flag. #### Redelegate Tokens @@ -315,7 +321,13 @@ Or if you want to check all your current unbonding-delegations with disctinct va gaiacli query redelegations ``` -You can also get previous redelegation(s) status by adding the `--height` flag. +Additionally, as you can get all the outgoing redelegations from a particular validator: + +```bash + gaiacli query redelegations-from +``` + +To get previous redelegation(s) status on past blocks, try adding the `--height` flag. ### Governance diff --git a/examples/basecoin/cmd/basecli/main.go b/examples/basecoin/cmd/basecli/main.go index 94c5c6e01692..1732e82eb916 100644 --- a/examples/basecoin/cmd/basecli/main.go +++ b/examples/basecoin/cmd/basecli/main.go @@ -49,6 +49,8 @@ func main() { client.GetCommands( stakecmd.GetCmdQueryValidator("stake", cdc), stakecmd.GetCmdQueryValidators("stake", cdc), + stakecmd.GetCmdQueryValidatorUnbondingDelegations("stake", cdc), + stakecmd.GetCmdQueryValidatorRedelegations("stake", cdc), stakecmd.GetCmdQueryDelegation("stake", cdc), stakecmd.GetCmdQueryDelegations("stake", cdc), stakecmd.GetCmdQueryPool("stake", cdc), diff --git a/x/stake/client/cli/query.go b/x/stake/client/cli/query.go index ad8030c9315b..28d09df8ef10 100644 --- a/x/stake/client/cli/query.go +++ b/x/stake/client/cli/query.go @@ -114,6 +114,80 @@ func GetCmdQueryValidators(storeName string, cdc *codec.Codec) *cobra.Command { return cmd } +// GetCmdQueryValidatorUnbondingDelegations implements the query all unbonding delegatations from a validator command. +func GetCmdQueryValidatorUnbondingDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command { + cmd := &cobra.Command{ + Use: "unbonding-delegations-from [operator-addr]", + Short: "Query all unbonding delegatations from a validator", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + valAddr, err := sdk.ValAddressFromBech32(args[0]) + if err != nil { + return err + } + + cliCtx := context.NewCLIContext().WithCodec(cdc) + params := stake.QueryValidatorParams{ + ValidatorAddr: valAddr, + } + + bz, err := cdc.MarshalJSON(params) + if err != nil { + return err + } + + res, err := cliCtx.QueryWithData( + fmt.Sprintf("custom/%s/validatorUnbondingDelegations", queryRoute), + bz) + if err != nil { + return err + } + + fmt.Println(string(res)) + return nil + }, + } + + return cmd +} + +// GetCmdQueryValidatorRedelegations implements the query all redelegatations from a validator command. +func GetCmdQueryValidatorRedelegations(queryRoute string, cdc *codec.Codec) *cobra.Command { + cmd := &cobra.Command{ + Use: "redelegations-from [operator-addr]", + Short: "Query all outgoing redelegatations from a validator", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + valAddr, err := sdk.ValAddressFromBech32(args[0]) + if err != nil { + return err + } + + cliCtx := context.NewCLIContext().WithCodec(cdc) + params := stake.QueryValidatorParams{ + ValidatorAddr: valAddr, + } + + bz, err := cdc.MarshalJSON(params) + if err != nil { + return err + } + + res, err := cliCtx.QueryWithData( + fmt.Sprintf("custom/%s/validatorRedelegations", queryRoute), + bz) + if err != nil { + return err + } + + fmt.Println(string(res)) + return nil + }, + } + + return cmd +} + // GetCmdQueryDelegation the query delegation command. func GetCmdQueryDelegation(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ @@ -139,6 +213,7 @@ func GetCmdQueryDelegation(storeName string, cdc *codec.Codec) *cobra.Command { } // parse out the delegation + delegation, err := types.UnmarshalDelegation(cdc, key, res) if err != nil { return err @@ -292,7 +367,7 @@ func GetCmdQueryUnbondingDelegations(storeName string, cdc *codec.Codec) *cobra. return err } - // parse out the validators + // parse out the unbonding delegations var ubds []stake.UnbondingDelegation for _, kv := range resKVs { ubd := types.MustUnmarshalUBD(cdc, kv.Key, kv.Value)