Skip to content

Commit

Permalink
Fix queryDelegatorTotalRewards (#4078)
Browse files Browse the repository at this point in the history
Return [] instead of null by making the initial
value an empty slice literal opposed to nil.

Closes: #3705
  • Loading branch information
alexanderbez authored and alessio committed Apr 10, 2019
1 parent b50b25d commit 94b7d8f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#3705 Return `[]` instead of `null` when querying delegator rewards.
17 changes: 17 additions & 0 deletions x/distribution/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,21 @@ var (
DefaultGenesisState = types.DefaultGenesisState
ValidateGenesis = types.ValidateGenesis
InitialFeePool = types.InitialFeePool

// Query types
QueryParams = keeper.QueryParams
QueryValidatorOutstandingRewards = keeper.QueryValidatorOutstandingRewards
QueryValidatorCommission = keeper.QueryValidatorCommission
QueryValidatorSlashes = keeper.QueryValidatorSlashes
QueryDelegationRewards = keeper.QueryDelegationRewards
QueryDelegatorTotalRewards = keeper.QueryDelegatorTotalRewards
QueryDelegatorValidators = keeper.QueryDelegatorValidators
QueryWithdrawAddr = keeper.QueryWithdrawAddr
QueryCommunityPool = keeper.QueryCommunityPool

// Param types
ParamCommunityTax = keeper.ParamCommunityTax
ParamBaseProposerReward = keeper.ParamBaseProposerReward
ParamBonusProposerReward = keeper.ParamBonusProposerReward
ParamWithdrawAddrEnabled = keeper.ParamWithdrawAddrEnabled
)
16 changes: 8 additions & 8 deletions x/distribution/client/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ import (

// QueryParams actually queries distribution params.
func QueryParams(cliCtx context.CLIContext, queryRoute string) (PrettyParams, error) {
route := fmt.Sprintf("custom/%s/params/community_tax", queryRoute)
route := fmt.Sprintf("custom/%s/params/%s", queryRoute, distr.ParamCommunityTax)

retCommunityTax, err := cliCtx.QueryWithData(route, []byte{})
if err != nil {
return PrettyParams{}, err
}

route = fmt.Sprintf("custom/%s/params/base_proposer_reward", queryRoute)
route = fmt.Sprintf("custom/%s/params/%s", queryRoute, distr.ParamBaseProposerReward)
retBaseProposerReward, err := cliCtx.QueryWithData(route, []byte{})
if err != nil {
return PrettyParams{}, err
}

route = fmt.Sprintf("custom/%s/params/bonus_proposer_reward", queryRoute)
route = fmt.Sprintf("custom/%s/params/%s", queryRoute, distr.ParamBonusProposerReward)
retBonusProposerReward, err := cliCtx.QueryWithData(route, []byte{})
if err != nil {
return PrettyParams{}, err
}

route = fmt.Sprintf("custom/%s/params/withdraw_addr_enabled", queryRoute)
route = fmt.Sprintf("custom/%s/params/%s", queryRoute, distr.ParamWithdrawAddrEnabled)
retWithdrawAddrEnabled, err := cliCtx.QueryWithData(route, []byte{})
if err != nil {
return PrettyParams{}, err
Expand All @@ -50,7 +50,7 @@ func QueryDelegatorTotalRewards(cliCtx context.CLIContext, cdc *codec.Codec,
}

return cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/delegator_total_rewards", queryRoute),
fmt.Sprintf("custom/%s/%s", queryRoute, distr.QueryDelegatorTotalRewards),
cdc.MustMarshalJSON(distr.NewQueryDelegatorParams(delegatorAddr)),
)
}
Expand All @@ -69,7 +69,7 @@ func QueryDelegationRewards(cliCtx context.CLIContext, cdc *codec.Codec,
}

return cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/delegation_rewards", queryRoute),
fmt.Sprintf("custom/%s/%s", queryRoute, distr.QueryDelegationRewards),
cdc.MustMarshalJSON(distr.NewQueryDelegationRewardsParams(delegatorAddr, validatorAddr)),
)
}
Expand All @@ -80,7 +80,7 @@ func QueryDelegatorValidators(cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute string, delegatorAddr sdk.AccAddress) ([]byte, error) {

return cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/delegator_validators", queryRoute),
fmt.Sprintf("custom/%s/%s", queryRoute, distr.QueryDelegatorValidators),
cdc.MustMarshalJSON(distr.NewQueryDelegatorParams(delegatorAddr)),
)
}
Expand All @@ -90,7 +90,7 @@ func QueryValidatorCommission(cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute string, validatorAddr sdk.ValAddress) ([]byte, error) {

return cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/validator_commission", queryRoute),
fmt.Sprintf("custom/%s/%s", queryRoute, distr.QueryValidatorCommission),
cdc.MustMarshalJSON(distr.NewQueryValidatorCommissionParams(validatorAddr)),
)
}
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func queryDelegatorTotalRewards(ctx sdk.Context, _ []string, req abci.RequestQue
// cache-wrap context as to not persist state changes during querying
ctx, _ = ctx.CacheContext()

var totalRewards sdk.DecCoins
totalRewards := sdk.DecCoins{}

k.stakingKeeper.IterateDelegations(
ctx, params.DelegatorAddress,
Expand Down

0 comments on commit 94b7d8f

Please sign in to comment.