Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix v010 DistQuery::Rewards bug #1094

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go-cosmwasm/types/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ type RewardsQuery struct {

// DelegationResponse is the expected response to DelegationsQuery
type RewardsResponse struct {
Rewards []Rewards `json:"rewards,omitempty"`
Total RewardCoins `json:"total,omitempty"`
Rewards []Rewards `json:"rewards"`
Total RewardCoins `json:"total"`
}

type Rewards struct {
Expand Down
11 changes: 11 additions & 0 deletions x/compute/internal/keeper/query_plugins.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"bytes"
"encoding/json"
"fmt"
"strings"
Expand Down Expand Up @@ -404,6 +405,7 @@ func DistQuerier(keeper distrkeeper.Keeper) func(ctx sdk.Context, request *wasmT
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, err.Error())
}
query = handleRewardsNull(query)

var res wasmTypes.RewardsResponse

Expand Down Expand Up @@ -437,6 +439,15 @@ func DistQuerier(keeper distrkeeper.Keeper) func(ctx sdk.Context, request *wasmT
}
}

// This function handles the case of making a DistQuery::Rewards, where the delegator does not have any pending rewards;
// thus the query returns null for rewards; e.g. {"rewards":null,"total":[]}
// The desired result is to return an empty vector in such a case; e.g. {"rewards":[],"total":[]}
func handleRewardsNull(query []byte) []byte {
query = bytes.Replace(
query, []byte(`"rewards":null`), []byte(`"rewards":[]`), 1)
return query
}

func BankQuerier(bankKeeper bankkeeper.ViewKeeper) func(ctx sdk.Context, request *wasmTypes.BankQuery) ([]byte, error) {
return func(ctx sdk.Context, request *wasmTypes.BankQuery) ([]byte, error) {
if request.AllBalances != nil {
Expand Down