Skip to content

Commit

Permalink
fix validators query to use power index at bonded validator query (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 authored Jun 1, 2024
1 parent 85707ca commit 9e37292
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions x/mstaking/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,22 @@ func (q Querier) Validators(ctx context.Context, req *types.QueryValidatorsReque
return nil, status.Errorf(codes.InvalidArgument, "invalid validator status %s", req.Status)
}

validators, pageRes, err := query.CollectionFilteredPaginate(ctx, q.Keeper.Validators, req.Pagination, func(valAddr []byte, val types.Validator) (include bool, err error) {
return (req.Status == "" || strings.EqualFold(val.GetStatus().String(), req.Status)), nil
}, func(valAddr []byte, val types.Validator) (types.Validator, error) {
return val, nil
})
var validators []types.Validator
var pageRes *query.PageResponse
var err error

if req.Status == types.Bonded.String() {
validators, pageRes, err = query.CollectionPaginate(ctx, q.Keeper.ValidatorsByConsPowerIndex, req.Pagination, func(key collections.Pair[int64, []byte], _ bool) (types.Validator, error) {
valAddr := key.K2()
return q.Keeper.Validators.Get(ctx, valAddr)
})
} else {
validators, pageRes, err = query.CollectionFilteredPaginate(ctx, q.Keeper.Validators, req.Pagination, func(valAddr []byte, val types.Validator) (include bool, err error) {
return (req.Status == "" || strings.EqualFold(val.GetStatus().String(), req.Status)), nil
}, func(valAddr []byte, val types.Validator) (types.Validator, error) {
return val, nil
})
}
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down

0 comments on commit 9e37292

Please sign in to comment.