LCD and CLI
This commit is contained in:
parent
9c6ef3e23c
commit
2d429731b3
|
@ -23,6 +23,7 @@ FEATURES
|
||||||
* [cli] [\#2569](https://github.com/cosmos/cosmos-sdk/pull/2569) Add commands to query validator unbondings and redelegations
|
* [cli] [\#2569](https://github.com/cosmos/cosmos-sdk/pull/2569) Add commands to query validator unbondings and redelegations
|
||||||
* [cli] [\#2524](https://github.com/cosmos/cosmos-sdk/issues/2524) Add support offline mode to `gaiacli tx sign`. Lookups are not performed if the flag `--offline` is on.
|
* [cli] [\#2524](https://github.com/cosmos/cosmos-sdk/issues/2524) Add support offline mode to `gaiacli tx sign`. Lookups are not performed if the flag `--offline` is on.
|
||||||
* [cli] [\#2558](https://github.com/cosmos/cosmos-sdk/issues/2558) Rename --print-sigs to --validate-signatures. It now performs a complete set of sanity checks and reports to the user. Also added --print-signature-only to print the signature only, not the whole transaction.
|
* [cli] [\#2558](https://github.com/cosmos/cosmos-sdk/issues/2558) Rename --print-sigs to --validate-signatures. It now performs a complete set of sanity checks and reports to the user. Also added --print-signature-only to print the signature only, not the whole transaction.
|
||||||
|
* [stake][cli] [\#2027] Add CLI query command for getting all delegations to a specific validator.
|
||||||
|
|
||||||
* Gaia
|
* Gaia
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ IMPROVEMENTS
|
||||||
- \#2660 [x/mock/simulation] Staking transactions get tested far more frequently
|
- \#2660 [x/mock/simulation] Staking transactions get tested far more frequently
|
||||||
- #2610 [x/stake] Block redelegation to and from the same validator
|
- #2610 [x/stake] Block redelegation to and from the same validator
|
||||||
- #2652 [x/auth] Add benchmark for get and set account
|
- #2652 [x/auth] Add benchmark for get and set account
|
||||||
|
- \#2027 [x/stake] Add `Querier` for getting all delegations to a specific validator.
|
||||||
|
|
||||||
* Tendermint
|
* Tendermint
|
||||||
|
|
||||||
|
|
|
@ -538,7 +538,7 @@ func TestBonding(t *testing.T) {
|
||||||
|
|
||||||
require.Equal(t, int64(40), coins.AmountOf(denom).Int64())
|
require.Equal(t, int64(40), coins.AmountOf(denom).Int64())
|
||||||
|
|
||||||
// query validator
|
// query delegation
|
||||||
bond := getDelegation(t, port, addr, operAddrs[0])
|
bond := getDelegation(t, port, addr, operAddrs[0])
|
||||||
require.Equal(t, amt, bond.Shares)
|
require.Equal(t, amt, bond.Shares)
|
||||||
|
|
||||||
|
@ -546,6 +546,10 @@ func TestBonding(t *testing.T) {
|
||||||
require.Len(t, delegatorDels, 1)
|
require.Len(t, delegatorDels, 1)
|
||||||
require.Equal(t, amt, delegatorDels[0].Shares)
|
require.Equal(t, amt, delegatorDels[0].Shares)
|
||||||
|
|
||||||
|
// query all delegations to validator
|
||||||
|
bonds := getValidatorDelegations(t, port, operAddrs[0])
|
||||||
|
require.Len(t, bonds, 2)
|
||||||
|
|
||||||
bondedValidators := getDelegatorValidators(t, port, addr)
|
bondedValidators := getDelegatorValidators(t, port, addr)
|
||||||
require.Len(t, bondedValidators, 1)
|
require.Len(t, bondedValidators, 1)
|
||||||
require.Equal(t, operAddrs[0], bondedValidators[0].OperatorAddr)
|
require.Equal(t, operAddrs[0], bondedValidators[0].OperatorAddr)
|
||||||
|
@ -1206,6 +1210,17 @@ func getValidator(t *testing.T, port string, validatorAddr sdk.ValAddress) stake
|
||||||
return validator
|
return validator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getValidatorDelegations(t *testing.T, port string, validatorAddr sdk.ValAddress) []stake.Delegation {
|
||||||
|
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/validators/%s/delegations", validatorAddr.String()), nil)
|
||||||
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
|
|
||||||
|
var delegations []stake.Delegation
|
||||||
|
err := cdc.UnmarshalJSON([]byte(body), &delegations)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
return delegations
|
||||||
|
}
|
||||||
|
|
||||||
func getValidatorUnbondingDelegations(t *testing.T, port string, validatorAddr sdk.ValAddress) []stake.UnbondingDelegation {
|
func getValidatorUnbondingDelegations(t *testing.T, port string, validatorAddr sdk.ValAddress) []stake.UnbondingDelegation {
|
||||||
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/validators/%s/unbonding_delegations", validatorAddr.String()), nil)
|
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/validators/%s/unbonding_delegations", validatorAddr.String()), nil)
|
||||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
|
|
|
@ -268,6 +268,10 @@ func TestGaiaCLICreateValidator(t *testing.T) {
|
||||||
require.Equal(t, validator.OperatorAddr, sdk.ValAddress(barAddr))
|
require.Equal(t, validator.OperatorAddr, sdk.ValAddress(barAddr))
|
||||||
require.True(sdk.DecEq(t, sdk.NewDec(2), validator.Tokens))
|
require.True(sdk.DecEq(t, sdk.NewDec(2), validator.Tokens))
|
||||||
|
|
||||||
|
validatorDelegations := executeGetValidatorDelegations(t, fmt.Sprintf("gaiacli query delegations-to %s --output=json %v", sdk.ValAddress(barAddr), flags))
|
||||||
|
require.Len(t, validatorDelegations, 1)
|
||||||
|
require.NotZero(t, validatorDelegations[0].Shares)
|
||||||
|
|
||||||
// unbond a single share
|
// unbond a single share
|
||||||
unbondStr := fmt.Sprintf("gaiacli tx unbond begin %v", flags)
|
unbondStr := fmt.Sprintf("gaiacli tx unbond begin %v", flags)
|
||||||
unbondStr += fmt.Sprintf(" --from=%s", "bar")
|
unbondStr += fmt.Sprintf(" --from=%s", "bar")
|
||||||
|
@ -720,6 +724,15 @@ func executeGetValidatorRedelegations(t *testing.T, cmdStr string) []stake.Redel
|
||||||
return reds
|
return reds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func executeGetValidatorDelegations(t *testing.T, cmdStr string) []stake.Delegation {
|
||||||
|
out, _ := tests.ExecuteT(t, cmdStr, "")
|
||||||
|
var delegations []stake.Delegation
|
||||||
|
cdc := app.MakeCodec()
|
||||||
|
err := cdc.UnmarshalJSON([]byte(out), &delegations)
|
||||||
|
require.NoError(t, err, "out %v\n, err %v", out, err)
|
||||||
|
return delegations
|
||||||
|
}
|
||||||
|
|
||||||
func executeGetPool(t *testing.T, cmdStr string) stake.Pool {
|
func executeGetPool(t *testing.T, cmdStr string) stake.Pool {
|
||||||
out, _ := tests.ExecuteT(t, cmdStr, "")
|
out, _ := tests.ExecuteT(t, cmdStr, "")
|
||||||
var pool stake.Pool
|
var pool stake.Pool
|
||||||
|
|
|
@ -290,6 +290,43 @@ func GetCmdQueryDelegations(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCmdQueryValidatorDelegations implements the command to query all the
|
||||||
|
// delegations to a specific validator.
|
||||||
|
func GetCmdQueryValidatorDelegations(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "delegations-to [validator-addr]",
|
||||||
|
Short: "Query all delegations made to one validator",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
validatorAddr, err := sdk.ValAddressFromBech32(args[0])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
params := stake.QueryValidatorParams{
|
||||||
|
ValidatorAddr: validatorAddr,
|
||||||
|
}
|
||||||
|
|
||||||
|
bz, err := cdc.MarshalJSON(params)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||||
|
|
||||||
|
res, err := cliCtx.QueryWithData("custom/stake/validatorDelegations", bz)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(res))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
// GetCmdQueryUnbondingDelegation implements the command to query a single
|
// GetCmdQueryUnbondingDelegation implements the command to query a single
|
||||||
// unbonding-delegation record.
|
// unbonding-delegation record.
|
||||||
func GetCmdQueryUnbondingDelegation(storeName string, cdc *codec.Codec) *cobra.Command {
|
func GetCmdQueryUnbondingDelegation(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||||
|
|
|
@ -78,6 +78,12 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Co
|
||||||
validatorHandlerFn(cliCtx, cdc),
|
validatorHandlerFn(cliCtx, cdc),
|
||||||
).Methods("GET")
|
).Methods("GET")
|
||||||
|
|
||||||
|
// Get all delegations to a validator
|
||||||
|
r.HandleFunc(
|
||||||
|
"/stake/validators/{validatorAddr}/delegations",
|
||||||
|
validatorDelegationsHandlerFn(cliCtx, cdc),
|
||||||
|
).Methods("GET")
|
||||||
|
|
||||||
// Get all unbonding delegations from a validator
|
// Get all unbonding delegations from a validator
|
||||||
r.HandleFunc(
|
r.HandleFunc(
|
||||||
"/stake/validators/{validatorAddr}/unbonding_delegations",
|
"/stake/validators/{validatorAddr}/unbonding_delegations",
|
||||||
|
@ -227,6 +233,11 @@ func validatorHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Handle
|
||||||
return queryValidator(cliCtx, cdc, "custom/stake/validator")
|
return queryValidator(cliCtx, cdc, "custom/stake/validator")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTTP request handler to query all unbonding delegations from a validator
|
||||||
|
func validatorDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
|
||||||
|
return queryValidator(cliCtx, cdc, "custom/stake/validatorDelegations")
|
||||||
|
}
|
||||||
|
|
||||||
// HTTP request handler to query all unbonding delegations from a validator
|
// HTTP request handler to query all unbonding delegations from a validator
|
||||||
func validatorUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
|
func validatorUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
|
||||||
return queryValidator(cliCtx, cdc, "custom/stake/validatorUnbondingDelegations")
|
return queryValidator(cliCtx, cdc, "custom/stake/validatorUnbondingDelegations")
|
||||||
|
|
Loading…
Reference in New Issue