Skip to content

Commit

Permalink
Merge PR cosmos#2596: Cmds for validator unbondings and redelegations
Browse files Browse the repository at this point in the history
  • Loading branch information
fedekunze authored and cwgoes committed Oct 28, 2018
1 parent d71f38b commit 855e0ac
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 15 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 24 additions & 0 deletions cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand Down
27 changes: 15 additions & 12 deletions cmd/gaia/cmd/gaiacli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions docs/sdk/clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,13 @@ Or if you want to check all your current unbonding-delegations with disctinct va
gaiacli query unbonding-delegations <account_cosmos>
```

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 <account_cosmosval>
```

To get previous unbonding-delegation(s) status on past blocks, try adding the `--height` flag.

#### Redelegate Tokens

Expand Down Expand Up @@ -315,7 +321,13 @@ Or if you want to check all your current unbonding-delegations with disctinct va
gaiacli query redelegations <account_cosmos>
```

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 <account_cosmosval>
```

To get previous redelegation(s) status on past blocks, try adding the `--height` flag.

### Governance

Expand Down
2 changes: 2 additions & 0 deletions examples/basecoin/cmd/basecli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
77 changes: 76 additions & 1 deletion x/stake/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 855e0ac

Please sign in to comment.