Merge PR #5248: Ensure all the empty arrays return an empty slice
This commit is contained in:
parent
4f3273ca52
commit
5af6bd77aa
|
@ -37,7 +37,12 @@ func queryBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, sdk
|
|||
return nil, sdk.ErrInternal(fmt.Sprintf("failed to parse params: %s", err))
|
||||
}
|
||||
|
||||
bz, err := codec.MarshalJSONIndent(types.ModuleCdc, k.GetCoins(ctx, params.Address))
|
||||
coins := k.GetCoins(ctx, params.Address)
|
||||
if coins == nil {
|
||||
coins = sdk.NewCoins()
|
||||
}
|
||||
|
||||
bz, err := codec.MarshalJSONIndent(types.ModuleCdc, coins)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err.Error()))
|
||||
}
|
||||
|
|
|
@ -85,7 +85,11 @@ func queryValidatorOutstandingRewards(ctx sdk.Context, path []string, req abci.R
|
|||
if err != nil {
|
||||
return nil, sdk.ErrUnknownRequest(sdk.AppendMsgToErr("incorrectly formatted request data", err.Error()))
|
||||
}
|
||||
bz, err := codec.MarshalJSONIndent(k.cdc, k.GetValidatorOutstandingRewards(ctx, params.ValidatorAddress))
|
||||
rewards := k.GetValidatorOutstandingRewards(ctx, params.ValidatorAddress)
|
||||
if rewards == nil {
|
||||
rewards = sdk.DecCoins{}
|
||||
}
|
||||
bz, err := codec.MarshalJSONIndent(k.cdc, rewards)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err.Error()))
|
||||
}
|
||||
|
@ -99,6 +103,9 @@ func queryValidatorCommission(ctx sdk.Context, path []string, req abci.RequestQu
|
|||
return nil, sdk.ErrUnknownRequest(sdk.AppendMsgToErr("incorrectly formatted request data", err.Error()))
|
||||
}
|
||||
commission := k.GetValidatorAccumulatedCommission(ctx, params.ValidatorAddress)
|
||||
if commission == nil {
|
||||
commission = sdk.DecCoins{}
|
||||
}
|
||||
bz, err := codec.MarshalJSONIndent(k.cdc, commission)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err.Error()))
|
||||
|
@ -150,6 +157,9 @@ func queryDelegationRewards(ctx sdk.Context, _ []string, req abci.RequestQuery,
|
|||
|
||||
endingPeriod := k.incrementValidatorPeriod(ctx, val)
|
||||
rewards := k.calculateDelegationRewards(ctx, val, del, endingPeriod)
|
||||
if rewards == nil {
|
||||
rewards = sdk.DecCoins{}
|
||||
}
|
||||
|
||||
bz, err := codec.MarshalJSONIndent(k.cdc, rewards)
|
||||
if err != nil {
|
||||
|
@ -242,7 +252,11 @@ func queryDelegatorWithdrawAddress(ctx sdk.Context, _ []string, req abci.Request
|
|||
}
|
||||
|
||||
func queryCommunityPool(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper) ([]byte, sdk.Error) {
|
||||
bz, err := k.cdc.MarshalJSON(k.GetFeePoolCommunityCoins(ctx))
|
||||
pool := k.GetFeePoolCommunityCoins(ctx)
|
||||
if pool == nil {
|
||||
pool = sdk.DecCoins{}
|
||||
}
|
||||
bz, err := k.cdc.MarshalJSON(pool)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err.Error()))
|
||||
}
|
||||
|
|
|
@ -130,6 +130,9 @@ func queryDeposits(ctx sdk.Context, path []string, req abci.RequestQuery, keeper
|
|||
}
|
||||
|
||||
deposits := keeper.GetDeposits(ctx, params.ProposalID)
|
||||
if deposits == nil {
|
||||
deposits = types.Deposits{}
|
||||
}
|
||||
|
||||
bz, err := codec.MarshalJSONIndent(keeper.cdc, deposits)
|
||||
if err != nil {
|
||||
|
@ -182,6 +185,9 @@ func queryVotes(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Ke
|
|||
}
|
||||
|
||||
votes := keeper.GetVotes(ctx, params.ProposalID)
|
||||
if votes == nil {
|
||||
votes = types.Votes{}
|
||||
}
|
||||
|
||||
bz, err := codec.MarshalJSONIndent(keeper.cdc, votes)
|
||||
if err != nil {
|
||||
|
@ -198,7 +204,12 @@ func queryProposals(ctx sdk.Context, _ []string, req abci.RequestQuery, keeper K
|
|||
return nil, sdk.ErrUnknownRequest(sdk.AppendMsgToErr("failed to parse params", err.Error()))
|
||||
}
|
||||
|
||||
bz, err := codec.MarshalJSONIndent(keeper.cdc, keeper.GetProposalsFiltered(ctx, params))
|
||||
proposals := keeper.GetProposalsFiltered(ctx, params)
|
||||
if proposals == nil {
|
||||
proposals = types.Proposals{}
|
||||
}
|
||||
|
||||
bz, err := codec.MarshalJSONIndent(keeper.cdc, proposals)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("failed to JSON marshal result: %s", err.Error()))
|
||||
}
|
||||
|
|
|
@ -115,6 +115,10 @@ func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper)
|
|||
return nil, sdk.ErrInternal(err.Error())
|
||||
}
|
||||
|
||||
if delegationResps == nil {
|
||||
delegationResps = types.DelegationResponses{}
|
||||
}
|
||||
|
||||
res, err := codec.MarshalJSONIndent(types.ModuleCdc, delegationResps)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("failed to marshal result to JSON", err.Error()))
|
||||
|
@ -132,6 +136,9 @@ func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery,
|
|||
}
|
||||
|
||||
unbonds := k.GetUnbondingDelegationsFromValidator(ctx, params.ValidatorAddr)
|
||||
if unbonds == nil {
|
||||
unbonds = types.UnbondingDelegations{}
|
||||
}
|
||||
|
||||
res, err := codec.MarshalJSONIndent(types.ModuleCdc, unbonds)
|
||||
if err != nil {
|
||||
|
@ -155,6 +162,10 @@ func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper)
|
|||
return nil, sdk.ErrInternal(err.Error())
|
||||
}
|
||||
|
||||
if delegationResps == nil {
|
||||
delegationResps = types.DelegationResponses{}
|
||||
}
|
||||
|
||||
res, err := codec.MarshalJSONIndent(types.ModuleCdc, delegationResps)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("failed to marshal result to JSON", err.Error()))
|
||||
|
@ -172,6 +183,9 @@ func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery,
|
|||
}
|
||||
|
||||
unbondingDelegations := k.GetAllUnbondingDelegations(ctx, params.DelegatorAddr)
|
||||
if unbondingDelegations == nil {
|
||||
unbondingDelegations = types.UnbondingDelegations{}
|
||||
}
|
||||
|
||||
res, err := codec.MarshalJSONIndent(types.ModuleCdc, unbondingDelegations)
|
||||
if err != nil {
|
||||
|
@ -192,6 +206,9 @@ func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper)
|
|||
}
|
||||
|
||||
validators := k.GetDelegatorValidators(ctx, params.DelegatorAddr, stakingParams.MaxValidators)
|
||||
if validators == nil {
|
||||
validators = types.Validators{}
|
||||
}
|
||||
|
||||
res, err := codec.MarshalJSONIndent(types.ModuleCdc, validators)
|
||||
if err != nil {
|
||||
|
@ -298,6 +315,10 @@ func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byt
|
|||
return nil, sdk.ErrInternal(err.Error())
|
||||
}
|
||||
|
||||
if redelResponses == nil {
|
||||
redelResponses = types.RedelegationResponses{}
|
||||
}
|
||||
|
||||
res, err := codec.MarshalJSONIndent(types.ModuleCdc, redelResponses)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("failed to marshal result to JSON", err.Error()))
|
||||
|
|
Loading…
Reference in New Issue