Skip to content

Commit

Permalink
Merge PR: Duplicated votes query information by REST way (#165)
Browse files Browse the repository at this point in the history
* FIX: Duplicated votes query information by REST way

* FIX: pass ut
  • Loading branch information
RevelationOfTuring authored May 25, 2020
1 parent ab9d514 commit 5157b6c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 18 deletions.
2 changes: 1 addition & 1 deletion x/staking/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ $ %s query staking votes-to okchainvaloper1alq9na49n9yycysh889rl90g9nhe58lcs50wu
return err
}

bytes, err := cdc.MarshalJSON(types.NewQueryValidatorVotesParams(valAddr))
bytes, err := cdc.MarshalJSON(types.NewQueryValidatorParams(valAddr))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion x/staking/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ func queryVotesToCheck(valAddr sdk.ValAddress, expVoterCnt int, expVoters []sdk.
q := keeper.NewQuerier(resultCtx.tc.mockKeeper.Keeper)
cdc := ModuleCdc

params := types.NewQueryValidatorVotesParams(valAddr)
params := types.NewQueryValidatorParams(valAddr)
bz, _ := cdc.MarshalJSON(params)

res, e := q(ctx, []string{types.QueryValidatorVotes}, abci.RequestQuery{Data: bz})
Expand Down
4 changes: 2 additions & 2 deletions x/staking/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ func queryProxy(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, sdk.E
}

func queryValidatorVotes(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, sdk.Error) {
var params types.QueryValidatorVotesParams
var params types.QueryValidatorParams

if err := types.ModuleCdc.UnmarshalJSON(req.Data, &params); err != nil {
return nil, sdk.ErrInternal(fmt.Sprintf("failed to parse validator votes params. %s", err))
}

voteResponses := k.GetValidatorVotes(ctx, params.ValAddr)
voteResponses := k.GetValidatorVotes(ctx, params.ValidatorAddr)
resp, err := codec.MarshalJSONIndent(types.ModuleCdc, voteResponses)
if err != nil {
return nil, defaultQueryErrJSONMarshal(err)
Expand Down
14 changes: 0 additions & 14 deletions x/staking/types/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,9 @@ const (
QueryDelegator = "delegator"
)

// QueryValidatorVotesParams defines the params for the following queries:
// - 'custom/staking/validatorVotes'
type QueryValidatorVotesParams struct {
ValAddr sdk.ValAddress
}

// NewQueryValidatorVotesParams creates a new instance of QueryValidatorVotesParams
func NewQueryValidatorVotesParams(valAddr sdk.ValAddress) QueryValidatorVotesParams {
return QueryValidatorVotesParams{
valAddr,
}
}

// QueryDelegatorParams defines the params for the following queries:
// - 'custom/staking/delegatorDelegations'
// - 'custom/staking/delegatorUnbondingDelegations'
// - 'custom/staking/delegatorRedelegations'
// - 'custom/staking/delegatorValidators'
type QueryDelegatorParams struct {
DelegatorAddr sdk.AccAddress
Expand Down

0 comments on commit 5157b6c

Please sign in to comment.