From 7fa16fd6898365add692f8941bece1be47527265 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sat, 25 Jul 2020 01:36:36 +0530 Subject: [PATCH 1/9] remove hybrid codec for slashing, staking and upgrade --- x/auth/keeper/querier.go | 16 ++--- x/auth/module.go | 4 +- x/bank/keeper/querier.go | 34 ++++----- x/bank/module.go | 4 +- x/distribution/keeper/querier.go | 68 +++++++++--------- x/distribution/module.go | 4 +- x/params/keeper/querier.go | 11 ++- x/params/module.go | 4 +- x/slashing/keeper/keeper.go | 4 +- x/slashing/keeper/querier.go | 24 +++---- x/slashing/keeper/querier_test.go | 7 +- x/slashing/module.go | 4 +- x/staking/keeper/keeper.go | 4 +- x/staking/keeper/querier.go | 110 +++++++++++++++--------------- x/staking/keeper/querier_test.go | 25 ++++--- x/staking/module.go | 4 +- x/upgrade/keeper/keeper.go | 4 +- x/upgrade/keeper/querier.go | 15 ++-- x/upgrade/module.go | 4 +- 19 files changed, 180 insertions(+), 170 deletions(-) diff --git a/x/auth/keeper/querier.go b/x/auth/keeper/querier.go index 47d4a59227e4..ac2ab398484e 100644 --- a/x/auth/keeper/querier.go +++ b/x/auth/keeper/querier.go @@ -10,14 +10,14 @@ import ( ) // NewQuerier creates a querier for auth REST endpoints -func NewQuerier(k AccountKeeper, cdc codec.JSONMarshaler) sdk.Querier { +func NewQuerier(k AccountKeeper, legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { case types.QueryAccount: - return queryAccount(ctx, req, k, cdc) + return queryAccount(ctx, req, k, legacyQuerierCdc) case types.QueryParams: - return queryParams(ctx, k, cdc) + return queryParams(ctx, k, legacyQuerierCdc) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path: %s", path[0]) @@ -25,9 +25,9 @@ func NewQuerier(k AccountKeeper, cdc codec.JSONMarshaler) sdk.Querier { } } -func queryAccount(ctx sdk.Context, req abci.RequestQuery, k AccountKeeper, cdc codec.JSONMarshaler) ([]byte, error) { +func queryAccount(ctx sdk.Context, req abci.RequestQuery, k AccountKeeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryAccountRequest - if err := cdc.UnmarshalJSON(req.Data, ¶ms); err != nil { + if err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms); err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -36,7 +36,7 @@ func queryAccount(ctx sdk.Context, req abci.RequestQuery, k AccountKeeper, cdc c return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", params.Address) } - bz, err := codec.MarshalJSONIndent(cdc, account) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, account) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -44,10 +44,10 @@ func queryAccount(ctx sdk.Context, req abci.RequestQuery, k AccountKeeper, cdc c return bz, nil } -func queryParams(ctx sdk.Context, k AccountKeeper, cdc codec.JSONMarshaler) ([]byte, error) { +func queryParams(ctx sdk.Context, k AccountKeeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { params := k.GetParams(ctx) - res, err := codec.MarshalJSONIndent(cdc, params) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, params) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/auth/module.go b/x/auth/module.go index 13e6ca5df347..aaef555b7275 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -113,8 +113,8 @@ func (AppModule) QuerierRoute() string { } // LegacyQuerierHandler returns the auth module sdk.Querier. -func (am AppModule) LegacyQuerierHandler(jsonCdc codec.JSONMarshaler) sdk.Querier { - return keeper.NewQuerier(am.accountKeeper, jsonCdc) +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(am.accountKeeper, legacyQuerierCdc) } // RegisterQueryService registers a GRPC query service to respond to the diff --git a/x/bank/keeper/querier.go b/x/bank/keeper/querier.go index 46597bec6d59..50ecd38f0a37 100644 --- a/x/bank/keeper/querier.go +++ b/x/bank/keeper/querier.go @@ -11,20 +11,20 @@ import ( ) // NewQuerier returns a new sdk.Keeper instance. -func NewQuerier(k Keeper, cdc codec.JSONMarshaler) sdk.Querier { +func NewQuerier(k Keeper, legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { case types.QueryBalance: - return queryBalance(ctx, req, k, cdc) + return queryBalance(ctx, req, k, legacyQuerierCdc) case types.QueryAllBalances: - return queryAllBalance(ctx, req, k, cdc) + return queryAllBalance(ctx, req, k, legacyQuerierCdc) case types.QueryTotalSupply: - return queryTotalSupply(ctx, req, k, cdc) + return queryTotalSupply(ctx, req, k, legacyQuerierCdc) case types.QuerySupplyOf: - return querySupplyOf(ctx, req, k, cdc) + return querySupplyOf(ctx, req, k, legacyQuerierCdc) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) @@ -32,16 +32,16 @@ func NewQuerier(k Keeper, cdc codec.JSONMarshaler) sdk.Querier { } } -func queryBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { +func queryBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryBalanceRequest - if err := cdc.UnmarshalJSON(req.Data, ¶ms); err != nil { + if err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms); err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } balance := k.GetBalance(ctx, params.Address, params.Denom) - bz, err := codec.MarshalJSONIndent(cdc, balance) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, balance) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -49,16 +49,16 @@ func queryBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper, cdc codec.JS return bz, nil } -func queryAllBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { +func queryAllBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryAllBalancesRequest - if err := cdc.UnmarshalJSON(req.Data, ¶ms); err != nil { + if err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms); err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } balances := k.GetAllBalances(ctx, params.Address) - bz, err := codec.MarshalJSONIndent(types.ModuleCdc, balances) + bz, err := codec.MarshalJSONIndent(types.ModulelegacyQuerierCdc, balances) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -66,10 +66,10 @@ func queryAllBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper, cdc codec return bz, nil } -func queryTotalSupply(ctx sdk.Context, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { +func queryTotalSupply(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryTotalSupplyParams - err := cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -83,7 +83,7 @@ func queryTotalSupply(ctx sdk.Context, req abci.RequestQuery, k Keeper, cdc code totalSupply = totalSupply[start:end] } - res, err := cdc.MarshalJSON(totalSupply) + res, err := legacyQuerierCdc.MarshalJSON(totalSupply) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -91,10 +91,10 @@ func queryTotalSupply(ctx sdk.Context, req abci.RequestQuery, k Keeper, cdc code return res, nil } -func querySupplyOf(ctx sdk.Context, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { +func querySupplyOf(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QuerySupplyOfParams - err := cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -102,7 +102,7 @@ func querySupplyOf(ctx sdk.Context, req abci.RequestQuery, k Keeper, cdc codec.J amount := k.GetSupply(ctx).GetTotal().AmountOf(params.Denom) supply := sdk.NewCoin(params.Denom, amount) - bz, err := codec.MarshalJSONIndent(cdc, supply) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, supply) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/bank/module.go b/x/bank/module.go index 8452c9a7195f..5af44af91963 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -118,8 +118,8 @@ func (am AppModule) Route() sdk.Route { func (AppModule) QuerierRoute() string { return types.RouterKey } // LegacyQuerierHandler returns the bank module sdk.Querier. -func (am AppModule) LegacyQuerierHandler(jsonCdc codec.JSONMarshaler) sdk.Querier { - return keeper.NewQuerier(am.keeper, jsonCdc) +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(am.keeper, legacyQuerierCdc) } // InitGenesis performs genesis initialization for the bank module. It returns diff --git a/x/distribution/keeper/querier.go b/x/distribution/keeper/querier.go index 1e71beb892e6..78662796cd48 100644 --- a/x/distribution/keeper/querier.go +++ b/x/distribution/keeper/querier.go @@ -12,35 +12,35 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/exported" ) -func NewQuerier(k Keeper, cdc codec.JSONMarshaler) sdk.Querier { +func NewQuerier(k Keeper, legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { case types.QueryParams: - return queryParams(ctx, path[1:], req, k, cdc) + return queryParams(ctx, path[1:], req, k, legacyQuerierCdc) case types.QueryValidatorOutstandingRewards: - return queryValidatorOutstandingRewards(ctx, path[1:], req, k, cdc) + return queryValidatorOutstandingRewards(ctx, path[1:], req, k, legacyQuerierCdc) case types.QueryValidatorCommission: - return queryValidatorCommission(ctx, path[1:], req, k, cdc) + return queryValidatorCommission(ctx, path[1:], req, k, legacyQuerierCdc) case types.QueryValidatorSlashes: - return queryValidatorSlashes(ctx, path[1:], req, k, cdc) + return queryValidatorSlashes(ctx, path[1:], req, k, legacyQuerierCdc) case types.QueryDelegationRewards: - return queryDelegationRewards(ctx, path[1:], req, k, cdc) + return queryDelegationRewards(ctx, path[1:], req, k, legacyQuerierCdc) case types.QueryDelegatorTotalRewards: - return queryDelegatorTotalRewards(ctx, path[1:], req, k, cdc) + return queryDelegatorTotalRewards(ctx, path[1:], req, k, legacyQuerierCdc) case types.QueryDelegatorValidators: - return queryDelegatorValidators(ctx, path[1:], req, k, cdc) + return queryDelegatorValidators(ctx, path[1:], req, k, legacyQuerierCdc) case types.QueryWithdrawAddr: - return queryDelegatorWithdrawAddress(ctx, path[1:], req, k, cdc) + return queryDelegatorWithdrawAddress(ctx, path[1:], req, k, legacyQuerierCdc) case types.QueryCommunityPool: - return queryCommunityPool(ctx, path[1:], req, k, cdc) + return queryCommunityPool(ctx, path[1:], req, k, legacyQuerierCdc) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path: %s", path[0]) @@ -48,10 +48,10 @@ func NewQuerier(k Keeper, cdc codec.JSONMarshaler) sdk.Querier { } } -func queryParams(ctx sdk.Context, _ []string, _ abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { +func queryParams(ctx sdk.Context, _ []string, _ abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { params := k.GetParams(ctx) - res, err := codec.MarshalJSONIndent(cdc, params) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, params) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -59,9 +59,9 @@ func queryParams(ctx sdk.Context, _ []string, _ abci.RequestQuery, k Keeper, cdc return res, nil } -func queryValidatorOutstandingRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { +func queryValidatorOutstandingRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryValidatorOutstandingRewardsParams - err := cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -71,7 +71,7 @@ func queryValidatorOutstandingRewards(ctx sdk.Context, _ []string, req abci.Requ rewards.Rewards = sdk.DecCoins{} } - bz, err := codec.MarshalJSONIndent(cdc, rewards) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, rewards) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -79,9 +79,9 @@ func queryValidatorOutstandingRewards(ctx sdk.Context, _ []string, req abci.Requ return bz, nil } -func queryValidatorCommission(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { +func queryValidatorCommission(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryValidatorCommissionParams - err := cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -91,7 +91,7 @@ func queryValidatorCommission(ctx sdk.Context, _ []string, req abci.RequestQuery commission.Commission = sdk.DecCoins{} } - bz, err := codec.MarshalJSONIndent(cdc, commission) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, commission) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -99,9 +99,9 @@ func queryValidatorCommission(ctx sdk.Context, _ []string, req abci.RequestQuery return bz, nil } -func queryValidatorSlashes(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { +func queryValidatorSlashes(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryValidatorSlashesParams - err := cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -114,7 +114,7 @@ func queryValidatorSlashes(ctx sdk.Context, _ []string, req abci.RequestQuery, k }, ) - bz, err := codec.MarshalJSONIndent(cdc, events) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, events) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -122,9 +122,9 @@ func queryValidatorSlashes(ctx sdk.Context, _ []string, req abci.RequestQuery, k return bz, nil } -func queryDelegationRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { +func queryDelegationRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegationRewardsParams - err := cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -148,7 +148,7 @@ func queryDelegationRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, rewards = sdk.DecCoins{} } - bz, err := codec.MarshalJSONIndent(cdc, rewards) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, rewards) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -156,9 +156,9 @@ func queryDelegationRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, return bz, nil } -func queryDelegatorTotalRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { +func queryDelegatorTotalRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorParams - err := cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -194,9 +194,9 @@ func queryDelegatorTotalRewards(ctx sdk.Context, _ []string, req abci.RequestQue return bz, nil } -func queryDelegatorValidators(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { +func queryDelegatorValidators(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorParams - err := cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -214,7 +214,7 @@ func queryDelegatorValidators(ctx sdk.Context, _ []string, req abci.RequestQuery }, ) - bz, err := codec.MarshalJSONIndent(cdc, validators) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, validators) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -222,9 +222,9 @@ func queryDelegatorValidators(ctx sdk.Context, _ []string, req abci.RequestQuery return bz, nil } -func queryDelegatorWithdrawAddress(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { +func queryDelegatorWithdrawAddress(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorWithdrawAddrParams - err := cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -233,7 +233,7 @@ func queryDelegatorWithdrawAddress(ctx sdk.Context, _ []string, req abci.Request ctx, _ = ctx.CacheContext() withdrawAddr := k.GetDelegatorWithdrawAddr(ctx, params.DelegatorAddress) - bz, err := codec.MarshalJSONIndent(cdc, withdrawAddr) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, withdrawAddr) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -241,13 +241,13 @@ func queryDelegatorWithdrawAddress(ctx sdk.Context, _ []string, req abci.Request return bz, nil } -func queryCommunityPool(ctx sdk.Context, _ []string, _ abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { +func queryCommunityPool(ctx sdk.Context, _ []string, _ abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { pool := k.GetFeePoolCommunityCoins(ctx) if pool == nil { pool = sdk.DecCoins{} } - bz, err := cdc.MarshalJSON(pool) + bz, err := legacyQuerierCdc.MarshalJSON(pool) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/distribution/module.go b/x/distribution/module.go index a0e469df56fb..b0bc8563e310 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -129,8 +129,8 @@ func (AppModule) QuerierRoute() string { } // LegacyQuerierHandler returns the distribution module sdk.Querier. -func (am AppModule) LegacyQuerierHandler(jsonCdc codec.JSONMarshaler) sdk.Querier { - return keeper.NewQuerier(am.keeper, jsonCdc) +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(am.keeper, legacyQuerierCdc) } // RegisterQueryService registers a GRPC query service to respond to the diff --git a/x/params/keeper/querier.go b/x/params/keeper/querier.go index ac218e05e9a9..29a8ab637dc9 100644 --- a/x/params/keeper/querier.go +++ b/x/params/keeper/querier.go @@ -4,7 +4,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/legacy" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/params/types" @@ -12,11 +11,11 @@ import ( ) // NewQuerier returns a new querier handler for the x/params module. -func NewQuerier(k Keeper) sdk.Querier { +func NewQuerier(k Keeper, legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { case types.QueryParams: - return queryParams(ctx, req, k) + return queryParams(ctx, req, k, legacyQuerierCdc) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path: %s", path[0]) @@ -24,10 +23,10 @@ func NewQuerier(k Keeper) sdk.Querier { } } -func queryParams(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryParams(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QuerySubspaceParams - if err := legacy.Cdc.UnmarshalJSON(req.Data, ¶ms); err != nil { + if err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms); err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -39,7 +38,7 @@ func queryParams(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, erro rawValue := ss.GetRaw(ctx, []byte(params.Key)) resp := types.NewSubspaceParamsResponse(params.Subspace, params.Key, string(rawValue)) - bz, err := codec.MarshalJSONIndent(legacy.Cdc, resp) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, resp) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/params/module.go b/x/params/module.go index f813d309c310..cbc701cfd814 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -97,8 +97,8 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {} func (AppModule) QuerierRoute() string { return types.QuerierRoute } // LegacyQuerierHandler returns the x/params querier handler. -func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { - return keeper.NewQuerier(am.keeper) +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc, codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(am.keeper, legacyQuerierCdc) } // RegisterQueryService registers a gRPC query service to respond to the diff --git a/x/slashing/keeper/keeper.go b/x/slashing/keeper/keeper.go index fe1cc14e756a..ee46915b745b 100644 --- a/x/slashing/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -16,13 +16,13 @@ import ( // Keeper of the slashing store type Keeper struct { storeKey sdk.StoreKey - cdc codec.Marshaler + cdc codec.BinaryMarshaler sk types.StakingKeeper paramspace types.ParamSubspace } // NewKeeper creates a slashing keeper -func NewKeeper(cdc codec.Marshaler, key sdk.StoreKey, sk types.StakingKeeper, paramspace types.ParamSubspace) Keeper { +func NewKeeper(cdc codec.BinaryMarshaler, key sdk.StoreKey, sk types.StakingKeeper, paramspace types.ParamSubspace) Keeper { // set KeyTable if it has not already been set if !paramspace.HasKeyTable() { paramspace = paramspace.WithKeyTable(types.ParamKeyTable()) diff --git a/x/slashing/keeper/querier.go b/x/slashing/keeper/querier.go index f44a1639af90..d2eea2fabbb4 100644 --- a/x/slashing/keeper/querier.go +++ b/x/slashing/keeper/querier.go @@ -11,17 +11,17 @@ import ( ) // NewQuerier creates a new querier for slashing clients. -func NewQuerier(k Keeper) sdk.Querier { +func NewQuerier(k Keeper, legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { case types.QueryParameters: - return queryParams(ctx, k) + return queryParams(ctx, k, legacyQuerierCdc) case types.QuerySigningInfo: - return querySigningInfo(ctx, req, k) + return querySigningInfo(ctx, req, k, legacyQuerierCdc) case types.QuerySigningInfos: - return querySigningInfos(ctx, req, k) + return querySigningInfos(ctx, req, k, legacyQuerierCdc) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) @@ -29,10 +29,10 @@ func NewQuerier(k Keeper) sdk.Querier { } } -func queryParams(ctx sdk.Context, k Keeper) ([]byte, error) { +func queryParams(ctx sdk.Context, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { params := k.GetParams(ctx) - res, err := codec.MarshalJSONIndent(types.ModuleCdc, params) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, params) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -40,10 +40,10 @@ func queryParams(ctx sdk.Context, k Keeper) ([]byte, error) { return res, nil } -func querySigningInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func querySigningInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QuerySigningInfoRequest - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -53,7 +53,7 @@ func querySigningInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, return nil, sdkerrors.Wrap(types.ErrNoSigningInfoFound, params.ConsAddress.String()) } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, signingInfo) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, signingInfo) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -61,10 +61,10 @@ func querySigningInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, return res, nil } -func querySigningInfos(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func querySigningInfos(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QuerySigningInfosParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -83,7 +83,7 @@ func querySigningInfos(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte signingInfos = signingInfos[start:end] } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, signingInfos) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, signingInfos) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/slashing/keeper/querier_test.go b/x/slashing/keeper/querier_test.go index 5413ba59949b..1721fe767042 100644 --- a/x/slashing/keeper/querier_test.go +++ b/x/slashing/keeper/querier_test.go @@ -17,8 +17,8 @@ func TestNewQuerier(t *testing.T) { app := simapp.Setup(false) ctx := app.BaseApp.NewContext(false, abci.Header{}) app.SlashingKeeper.SetParams(ctx, keeper.TestParams()) - - querier := keeper.NewQuerier(app.SlashingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.SlashingKeeper, legacyQuerierCdc) query := abci.RequestQuery{ Path: "", @@ -31,11 +31,12 @@ func TestNewQuerier(t *testing.T) { func TestQueryParams(t *testing.T) { cdc := codec.New() + legacyQuerierCdc := codec.NewAminoCodec(cdc) app := simapp.Setup(false) ctx := app.BaseApp.NewContext(false, abci.Header{}) app.SlashingKeeper.SetParams(ctx, keeper.TestParams()) - querier := keeper.NewQuerier(app.SlashingKeeper) + querier := keeper.NewQuerier(app.SlashingKeeper, legacyQuerierCdc) query := abci.RequestQuery{ Path: "", diff --git a/x/slashing/module.go b/x/slashing/module.go index 4eac644fe72e..db802965db72 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -127,8 +127,8 @@ func (AppModule) QuerierRoute() string { } // LegacyQuerierHandler returns the slashing module sdk.Querier. -func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { - return keeper.NewQuerier(am.keeper) +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(am.keeper, legacyQuerierCdc) } // RegisterQueryService registers a GRPC query service to respond to the diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index bc5e1d5c322e..86e32665d11a 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -23,7 +23,7 @@ var _ types.DelegationSet = Keeper{} // keeper of the staking store type Keeper struct { storeKey sdk.StoreKey - cdc codec.Marshaler + cdc codec.BinaryMarshaler authKeeper types.AccountKeeper bankKeeper types.BankKeeper hooks types.StakingHooks @@ -34,7 +34,7 @@ type Keeper struct { // NewKeeper creates a new staking Keeper instance func NewKeeper( - cdc codec.Marshaler, key sdk.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, + cdc codec.BinaryMarshaler, key sdk.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, ps paramtypes.Subspace, ) Keeper { // set KeyTable if it has not already been set diff --git a/x/staking/keeper/querier.go b/x/staking/keeper/querier.go index 309ba0fa0273..2b637e0c507a 100644 --- a/x/staking/keeper/querier.go +++ b/x/staking/keeper/querier.go @@ -14,50 +14,50 @@ import ( ) // creates a querier for staking REST endpoints -func NewQuerier(k Keeper) sdk.Querier { +func NewQuerier(k Keeper, legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { case types.QueryValidators: - return queryValidators(ctx, req, k) + return queryValidators(ctx, req, k, legacyQuerierCdc) case types.QueryValidator: - return queryValidator(ctx, req, k) + return queryValidator(ctx, req, k, legacyQuerierCdc) case types.QueryValidatorDelegations: - return queryValidatorDelegations(ctx, req, k) + return queryValidatorDelegations(ctx, req, k, legacyQuerierCdc) case types.QueryValidatorUnbondingDelegations: - return queryValidatorUnbondingDelegations(ctx, req, k) + return queryValidatorUnbondingDelegations(ctx, req, k, legacyQuerierCdc) case types.QueryDelegation: - return queryDelegation(ctx, req, k) + return queryDelegation(ctx, req, k, legacyQuerierCdc) case types.QueryUnbondingDelegation: - return queryUnbondingDelegation(ctx, req, k) + return queryUnbondingDelegation(ctx, req, k, legacyQuerierCdc) case types.QueryDelegatorDelegations: - return queryDelegatorDelegations(ctx, req, k) + return queryDelegatorDelegations(ctx, req, k, legacyQuerierCdc) case types.QueryDelegatorUnbondingDelegations: - return queryDelegatorUnbondingDelegations(ctx, req, k) + return queryDelegatorUnbondingDelegations(ctx, req, k, legacyQuerierCdc) case types.QueryRedelegations: - return queryRedelegations(ctx, req, k) + return queryRedelegations(ctx, req, k, legacyQuerierCdc) case types.QueryDelegatorValidators: - return queryDelegatorValidators(ctx, req, k) + return queryDelegatorValidators(ctx, req, k, legacyQuerierCdc) case types.QueryDelegatorValidator: - return queryDelegatorValidator(ctx, req, k) + return queryDelegatorValidator(ctx, req, k, legacyQuerierCdc) case types.QueryHistoricalInfo: - return queryHistoricalInfo(ctx, req, k) + return queryHistoricalInfo(ctx, req, k, legacyQuerierCdc) case types.QueryPool: - return queryPool(ctx, k) + return queryPool(ctx, k, legacyQuerierCdc) case types.QueryParameters: - return queryParameters(ctx, k) + return queryParameters(ctx, k, legacyQuerierCdc) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) @@ -65,10 +65,10 @@ func NewQuerier(k Keeper) sdk.Querier { } } -func queryValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryValidatorsParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -89,7 +89,7 @@ func queryValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, filteredVals = filteredVals[start:end] } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, filteredVals) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, filteredVals) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -97,10 +97,10 @@ func queryValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, return res, nil } -func queryValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryValidatorParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -110,7 +110,7 @@ func queryValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, e return nil, types.ErrNoValidatorFound } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, validator) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, validator) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -118,10 +118,10 @@ func queryValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, e return res, nil } -func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryValidatorParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -144,7 +144,7 @@ func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) delegationResps = types.DelegationResponses{} } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, delegationResps) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, delegationResps) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -152,10 +152,10 @@ func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) return res, nil } -func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryValidatorParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -172,7 +172,7 @@ func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, unbonds = unbonds[start:end] } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, unbonds) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, unbonds) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -180,10 +180,10 @@ func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, return res, nil } -func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -199,7 +199,7 @@ func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) delegationResps = types.DelegationResponses{} } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, delegationResps) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, delegationResps) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -207,10 +207,10 @@ func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) return res, nil } -func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -220,7 +220,7 @@ func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, unbondingDelegations = types.UnbondingDelegations{} } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, unbondingDelegations) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, unbondingDelegations) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -228,12 +228,12 @@ func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, return res, nil } -func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorParams stakingParams := k.GetParams(ctx) - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -243,7 +243,7 @@ func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper) validators = types.Validators{} } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, validators) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, validators) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -251,10 +251,10 @@ func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper) return res, nil } -func queryDelegatorValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryDelegatorValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorValidatorRequest - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -264,7 +264,7 @@ func queryDelegatorValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper) ( return nil, err } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, validator) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, validator) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -272,10 +272,10 @@ func queryDelegatorValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper) ( return res, nil } -func queryDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorValidatorRequest - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -290,7 +290,7 @@ func queryDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, return nil, err } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, delegationResp) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, delegationResp) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -298,10 +298,10 @@ func queryDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, return res, nil } -func queryUnbondingDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryUnbondingDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorValidatorRequest - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -311,7 +311,7 @@ func queryUnbondingDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper) return nil, types.ErrNoUnbondingDelegation } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, unbond) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, unbond) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -319,10 +319,10 @@ func queryUnbondingDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper) return res, nil } -func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryRedelegationParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -352,7 +352,7 @@ func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byt redelResponses = types.RedelegationResponses{} } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, redelResponses) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, redelResponses) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -360,10 +360,10 @@ func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byt return res, nil } -func queryHistoricalInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryHistoricalInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryHistoricalInfoRequest - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -373,7 +373,7 @@ func queryHistoricalInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]by return nil, types.ErrNoHistoricalInfo } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, hi) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, hi) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -381,7 +381,7 @@ func queryHistoricalInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]by return res, nil } -func queryPool(ctx sdk.Context, k Keeper) ([]byte, error) { +func queryPool(ctx sdk.Context, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { bondDenom := k.BondDenom(ctx) bondedPool := k.GetBondedPool(ctx) notBondedPool := k.GetNotBondedPool(ctx) @@ -395,7 +395,7 @@ func queryPool(ctx sdk.Context, k Keeper) ([]byte, error) { k.bankKeeper.GetBalance(ctx, bondedPool.GetAddress(), bondDenom).Amount, ) - res, err := codec.MarshalJSONIndent(types.ModuleCdc, pool) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, pool) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -403,10 +403,10 @@ func queryPool(ctx sdk.Context, k Keeper) ([]byte, error) { return res, nil } -func queryParameters(ctx sdk.Context, k Keeper) ([]byte, error) { +func queryParameters(ctx sdk.Context, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { params := k.GetParams(ctx) - res, err := codec.MarshalJSONIndent(types.ModuleCdc, params) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, params) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/staking/keeper/querier_test.go b/x/staking/keeper/querier_test.go index 63cce0a2b8e5..5a2e6de58e71 100644 --- a/x/staking/keeper/querier_test.go +++ b/x/staking/keeper/querier_test.go @@ -2,6 +2,7 @@ package keeper_test import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec" "testing" "github.com/stretchr/testify/require" @@ -16,6 +17,7 @@ import ( func TestNewQuerier(t *testing.T) { cdc, app, ctx := createTestInput() + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) addrs := simapp.AddTestAddrs(app, ctx, 500, sdk.NewInt(10000)) _, addrAcc2 := addrs[0], addrs[1] @@ -43,7 +45,7 @@ func TestNewQuerier(t *testing.T) { Data: []byte{}, } - querier := keeper.NewQuerier(app.StakingKeeper) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) bz, err := querier(ctx, []string{"other"}, query) require.Error(t, err) @@ -107,7 +109,8 @@ func TestNewQuerier(t *testing.T) { func TestQueryParametersPool(t *testing.T) { cdc, app, ctx := createTestInput() - querier := keeper.NewQuerier(app.StakingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) bondDenom := sdk.DefaultBondDenom @@ -133,7 +136,8 @@ func TestQueryParametersPool(t *testing.T) { func TestQueryValidators(t *testing.T) { cdc, app, ctx := createTestInput() params := app.StakingKeeper.GetParams(ctx) - querier := keeper.NewQuerier(app.StakingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 500, sdk.TokensFromConsensusPower(10000)) @@ -200,7 +204,8 @@ func TestQueryValidators(t *testing.T) { func TestQueryDelegation(t *testing.T) { cdc, app, ctx := createTestInput() params := app.StakingKeeper.GetParams(ctx) - querier := keeper.NewQuerier(app.StakingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] @@ -448,7 +453,8 @@ func TestQueryValidatorDelegations_Pagination(t *testing.T) { } cdc, app, ctx := createTestInput() - querier := keeper.NewQuerier(app.StakingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 100, sdk.TokensFromConsensusPower(10000)) pubKeys := simapp.CreateTestPubKeys(1) @@ -532,7 +538,8 @@ func TestQueryValidatorDelegations_Pagination(t *testing.T) { func TestQueryRedelegations(t *testing.T) { cdc, app, ctx := createTestInput() - querier := keeper.NewQuerier(app.StakingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] @@ -603,7 +610,8 @@ func TestQueryRedelegations(t *testing.T) { func TestQueryUnbondingDelegation(t *testing.T) { cdc, app, ctx := createTestInput() - querier := keeper.NewQuerier(app.StakingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] @@ -698,7 +706,8 @@ func TestQueryUnbondingDelegation(t *testing.T) { func TestQueryHistoricalInfo(t *testing.T) { cdc, app, ctx := createTestInput() - querier := keeper.NewQuerier(app.StakingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] diff --git a/x/staking/module.go b/x/staking/module.go index daca2ec3c66f..1cc38aef612a 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -123,8 +123,8 @@ func (AppModule) QuerierRoute() string { } // LegacyQuerierHandler returns the staking module sdk.Querier. -func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { - return keeper.NewQuerier(am.keeper) +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(am.keeper, legacyQuerierCdc) } // RegisterQueryService registers a GRPC query service to respond to the diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 88efb94a819f..ab85479823f3 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -27,12 +27,12 @@ type Keeper struct { homePath string skipUpgradeHeights map[int64]bool storeKey sdk.StoreKey - cdc codec.Marshaler + cdc codec.BinaryMarshaler upgradeHandlers map[string]types.UpgradeHandler } // NewKeeper constructs an upgrade Keeper -func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.Marshaler, homePath string) Keeper { +func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string) Keeper { return Keeper{ homePath: homePath, skipUpgradeHeights: skipUpgradeHeights, diff --git a/x/upgrade/keeper/querier.go b/x/upgrade/keeper/querier.go index 568a44d537ee..ce080c91feb0 100644 --- a/x/upgrade/keeper/querier.go +++ b/x/upgrade/keeper/querier.go @@ -2,6 +2,7 @@ package keeper import ( "encoding/binary" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -12,15 +13,15 @@ import ( ) // NewQuerier creates a querier for upgrade cli and REST endpoints -func NewQuerier(k Keeper) sdk.Querier { +func NewQuerier(k Keeper, legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { case types.QueryCurrent: - return queryCurrent(ctx, req, k) + return queryCurrent(ctx, req, k, legacyQuerierCdc) case types.QueryApplied: - return queryApplied(ctx, req, k) + return queryApplied(ctx, req, k, legacyQuerierCdc) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) @@ -28,13 +29,13 @@ func NewQuerier(k Keeper) sdk.Querier { } } -func queryCurrent(ctx sdk.Context, _ abci.RequestQuery, k Keeper) ([]byte, error) { +func queryCurrent(ctx sdk.Context, _ abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { plan, has := k.GetUpgradePlan(ctx) if !has { return nil, nil } - res, err := k.cdc.MarshalJSON(&plan) + res, err := legacyQuerierCdc.MarshalJSON(&plan) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -42,10 +43,10 @@ func queryCurrent(ctx sdk.Context, _ abci.RequestQuery, k Keeper) ([]byte, error return res, nil } -func queryApplied(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryApplied(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryAppliedPlanRequest - err := k.cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index ccdada7f217d..314c5c9b7dc7 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -89,8 +89,8 @@ func (AppModule) Route() sdk.Route { return sdk.Route{} } func (AppModule) QuerierRoute() string { return types.QuerierKey } // LegacyQuerierHandler registers a query handler to respond to the module-specific queries -func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { - return keeper.NewQuerier(am.keeper) +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(am.keeper, legacyQuerierCdc) } // RegisterQueryService registers a GRPC query service to respond to the From 91a3351d619971f0471d3227c2ec012034a39159 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sat, 25 Jul 2020 01:58:24 +0530 Subject: [PATCH 2/9] Remove hybridcodec from params and mint --- x/mint/keeper/keeper.go | 4 ++-- x/mint/keeper/querier.go | 20 ++++++++++---------- x/mint/keeper/querier_test.go | 13 +++++++++---- x/mint/module.go | 4 ++-- x/params/keeper/keeper.go | 4 ++-- x/params/module.go | 2 +- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go index 5e37b8704f79..485ac961b1f1 100644 --- a/x/mint/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -13,7 +13,7 @@ import ( // Keeper of the mint store type Keeper struct { - cdc codec.Marshaler + cdc codec.BinaryMarshaler storeKey sdk.StoreKey paramSpace paramtypes.Subspace stakingKeeper types.StakingKeeper @@ -23,7 +23,7 @@ type Keeper struct { // NewKeeper creates a new mint Keeper instance func NewKeeper( - cdc codec.Marshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace, + cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace, sk types.StakingKeeper, ak types.AccountKeeper, bk types.BankKeeper, feeCollectorName string, ) Keeper { diff --git a/x/mint/keeper/querier.go b/x/mint/keeper/querier.go index 7c52ef1001fd..4b88ab6ff249 100644 --- a/x/mint/keeper/querier.go +++ b/x/mint/keeper/querier.go @@ -10,17 +10,17 @@ import ( ) // NewQuerier returns a minting Querier handler. -func NewQuerier(k Keeper) sdk.Querier { +func NewQuerier(k Keeper, legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { return func(ctx sdk.Context, path []string, _ abci.RequestQuery) ([]byte, error) { switch path[0] { case types.QueryParameters: - return queryParams(ctx, k) + return queryParams(ctx, k, legacyQuerierCdc) case types.QueryInflation: - return queryInflation(ctx, k) + return queryInflation(ctx, k, legacyQuerierCdc) case types.QueryAnnualProvisions: - return queryAnnualProvisions(ctx, k) + return queryAnnualProvisions(ctx, k, legacyQuerierCdc) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path: %s", path[0]) @@ -28,10 +28,10 @@ func NewQuerier(k Keeper) sdk.Querier { } } -func queryParams(ctx sdk.Context, k Keeper) ([]byte, error) { +func queryParams(ctx sdk.Context, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { params := k.GetParams(ctx) - res, err := codec.MarshalJSONIndent(k.cdc, params) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, params) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -39,10 +39,10 @@ func queryParams(ctx sdk.Context, k Keeper) ([]byte, error) { return res, nil } -func queryInflation(ctx sdk.Context, k Keeper) ([]byte, error) { +func queryInflation(ctx sdk.Context, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { minter := k.GetMinter(ctx) - res, err := codec.MarshalJSONIndent(k.cdc, minter.Inflation) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, minter.Inflation) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -50,10 +50,10 @@ func queryInflation(ctx sdk.Context, k Keeper) ([]byte, error) { return res, nil } -func queryAnnualProvisions(ctx sdk.Context, k Keeper) ([]byte, error) { +func queryAnnualProvisions(ctx sdk.Context, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { minter := k.GetMinter(ctx) - res, err := codec.MarshalJSONIndent(k.cdc, minter.AnnualProvisions) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, minter.AnnualProvisions) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/mint/keeper/querier_test.go b/x/mint/keeper/querier_test.go index 07c191f1b75f..6ae42adf240b 100644 --- a/x/mint/keeper/querier_test.go +++ b/x/mint/keeper/querier_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "github.com/cosmos/cosmos-sdk/codec" "testing" "github.com/stretchr/testify/require" @@ -14,7 +15,8 @@ import ( func TestNewQuerier(t *testing.T) { app, ctx := createTestApp(true) - querier := keep.NewQuerier(app.MintKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keep.NewQuerier(app.MintKeeper, legacyQuerierCdc) query := abci.RequestQuery{ Path: "", @@ -36,7 +38,8 @@ func TestNewQuerier(t *testing.T) { func TestQueryParams(t *testing.T) { app, ctx := createTestApp(true) - querier := keep.NewQuerier(app.MintKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keep.NewQuerier(app.MintKeeper, legacyQuerierCdc) var params types.Params @@ -51,7 +54,8 @@ func TestQueryParams(t *testing.T) { func TestQueryInflation(t *testing.T) { app, ctx := createTestApp(true) - querier := keep.NewQuerier(app.MintKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keep.NewQuerier(app.MintKeeper, legacyQuerierCdc) var inflation sdk.Dec @@ -66,7 +70,8 @@ func TestQueryInflation(t *testing.T) { func TestQueryAnnualProvisions(t *testing.T) { app, ctx := createTestApp(true) - querier := keep.NewQuerier(app.MintKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keep.NewQuerier(app.MintKeeper, legacyQuerierCdc) var annualProvisions sdk.Dec diff --git a/x/mint/module.go b/x/mint/module.go index b57a9901dba4..28e5b5c695d5 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -112,8 +112,8 @@ func (AppModule) QuerierRoute() string { } // LegacyQuerierHandler returns the mint module sdk.Querier. -func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { - return keeper.NewQuerier(am.keeper) +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(am.keeper, legacyQuerierCdc) } // RegisterQueryService registers a gRPC query service to respond to the diff --git a/x/params/keeper/keeper.go b/x/params/keeper/keeper.go index 628548acb109..8912a981e5e6 100644 --- a/x/params/keeper/keeper.go +++ b/x/params/keeper/keeper.go @@ -13,14 +13,14 @@ import ( // Keeper of the global paramstore type Keeper struct { - cdc codec.Marshaler + cdc codec.BinaryMarshaler key sdk.StoreKey tkey sdk.StoreKey spaces map[string]*types.Subspace } // NewKeeper constructs a params keeper -func NewKeeper(cdc codec.Marshaler, key, tkey sdk.StoreKey) Keeper { +func NewKeeper(cdc codec.BinaryMarshaler, key, tkey sdk.StoreKey) Keeper { return Keeper{ cdc: cdc, key: key, diff --git a/x/params/module.go b/x/params/module.go index cbc701cfd814..662adea4a356 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -97,7 +97,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {} func (AppModule) QuerierRoute() string { return types.QuerierRoute } // LegacyQuerierHandler returns the x/params querier handler. -func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc, codec.JSONMarshaler) sdk.Querier { +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper, legacyQuerierCdc) } From b3548dd5cc93cb967a58b52153f7ff5cce06ede8 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sat, 25 Jul 2020 02:12:52 +0530 Subject: [PATCH 3/9] revert staking --- x/bank/keeper/querier.go | 2 +- x/params/keeper/keeper.go | 4 +- x/staking/keeper/keeper.go | 4 +- x/staking/keeper/querier.go | 110 +++++++++++++++---------------- x/staking/keeper/querier_test.go | 25 +++---- x/staking/module.go | 4 +- 6 files changed, 70 insertions(+), 79 deletions(-) diff --git a/x/bank/keeper/querier.go b/x/bank/keeper/querier.go index 50ecd38f0a37..8acc5a3c5a31 100644 --- a/x/bank/keeper/querier.go +++ b/x/bank/keeper/querier.go @@ -58,7 +58,7 @@ func queryAllBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQue balances := k.GetAllBalances(ctx, params.Address) - bz, err := codec.MarshalJSONIndent(types.ModulelegacyQuerierCdc, balances) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, balances) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/params/keeper/keeper.go b/x/params/keeper/keeper.go index 8912a981e5e6..628548acb109 100644 --- a/x/params/keeper/keeper.go +++ b/x/params/keeper/keeper.go @@ -13,14 +13,14 @@ import ( // Keeper of the global paramstore type Keeper struct { - cdc codec.BinaryMarshaler + cdc codec.Marshaler key sdk.StoreKey tkey sdk.StoreKey spaces map[string]*types.Subspace } // NewKeeper constructs a params keeper -func NewKeeper(cdc codec.BinaryMarshaler, key, tkey sdk.StoreKey) Keeper { +func NewKeeper(cdc codec.Marshaler, key, tkey sdk.StoreKey) Keeper { return Keeper{ cdc: cdc, key: key, diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 86e32665d11a..bc5e1d5c322e 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -23,7 +23,7 @@ var _ types.DelegationSet = Keeper{} // keeper of the staking store type Keeper struct { storeKey sdk.StoreKey - cdc codec.BinaryMarshaler + cdc codec.Marshaler authKeeper types.AccountKeeper bankKeeper types.BankKeeper hooks types.StakingHooks @@ -34,7 +34,7 @@ type Keeper struct { // NewKeeper creates a new staking Keeper instance func NewKeeper( - cdc codec.BinaryMarshaler, key sdk.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, + cdc codec.Marshaler, key sdk.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, ps paramtypes.Subspace, ) Keeper { // set KeyTable if it has not already been set diff --git a/x/staking/keeper/querier.go b/x/staking/keeper/querier.go index 2b637e0c507a..309ba0fa0273 100644 --- a/x/staking/keeper/querier.go +++ b/x/staking/keeper/querier.go @@ -14,50 +14,50 @@ import ( ) // creates a querier for staking REST endpoints -func NewQuerier(k Keeper, legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { +func NewQuerier(k Keeper) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { case types.QueryValidators: - return queryValidators(ctx, req, k, legacyQuerierCdc) + return queryValidators(ctx, req, k) case types.QueryValidator: - return queryValidator(ctx, req, k, legacyQuerierCdc) + return queryValidator(ctx, req, k) case types.QueryValidatorDelegations: - return queryValidatorDelegations(ctx, req, k, legacyQuerierCdc) + return queryValidatorDelegations(ctx, req, k) case types.QueryValidatorUnbondingDelegations: - return queryValidatorUnbondingDelegations(ctx, req, k, legacyQuerierCdc) + return queryValidatorUnbondingDelegations(ctx, req, k) case types.QueryDelegation: - return queryDelegation(ctx, req, k, legacyQuerierCdc) + return queryDelegation(ctx, req, k) case types.QueryUnbondingDelegation: - return queryUnbondingDelegation(ctx, req, k, legacyQuerierCdc) + return queryUnbondingDelegation(ctx, req, k) case types.QueryDelegatorDelegations: - return queryDelegatorDelegations(ctx, req, k, legacyQuerierCdc) + return queryDelegatorDelegations(ctx, req, k) case types.QueryDelegatorUnbondingDelegations: - return queryDelegatorUnbondingDelegations(ctx, req, k, legacyQuerierCdc) + return queryDelegatorUnbondingDelegations(ctx, req, k) case types.QueryRedelegations: - return queryRedelegations(ctx, req, k, legacyQuerierCdc) + return queryRedelegations(ctx, req, k) case types.QueryDelegatorValidators: - return queryDelegatorValidators(ctx, req, k, legacyQuerierCdc) + return queryDelegatorValidators(ctx, req, k) case types.QueryDelegatorValidator: - return queryDelegatorValidator(ctx, req, k, legacyQuerierCdc) + return queryDelegatorValidator(ctx, req, k) case types.QueryHistoricalInfo: - return queryHistoricalInfo(ctx, req, k, legacyQuerierCdc) + return queryHistoricalInfo(ctx, req, k) case types.QueryPool: - return queryPool(ctx, k, legacyQuerierCdc) + return queryPool(ctx, k) case types.QueryParameters: - return queryParameters(ctx, k, legacyQuerierCdc) + return queryParameters(ctx, k) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) @@ -65,10 +65,10 @@ func NewQuerier(k Keeper, legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { } } -func queryValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { +func queryValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { var params types.QueryValidatorsParams - err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) + err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -89,7 +89,7 @@ func queryValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQue filteredVals = filteredVals[start:end] } - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, filteredVals) + res, err := codec.MarshalJSONIndent(types.ModuleCdc, filteredVals) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -97,10 +97,10 @@ func queryValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQue return res, nil } -func queryValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { +func queryValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { var params types.QueryValidatorParams - err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) + err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -110,7 +110,7 @@ func queryValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuer return nil, types.ErrNoValidatorFound } - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, validator) + res, err := codec.MarshalJSONIndent(types.ModuleCdc, validator) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -118,10 +118,10 @@ func queryValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuer return res, nil } -func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { +func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { var params types.QueryValidatorParams - err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) + err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -144,7 +144,7 @@ func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, delegationResps = types.DelegationResponses{} } - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, delegationResps) + res, err := codec.MarshalJSONIndent(types.ModuleCdc, delegationResps) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -152,10 +152,10 @@ func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, return res, nil } -func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { +func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { var params types.QueryValidatorParams - err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) + err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -172,7 +172,7 @@ func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, unbonds = unbonds[start:end] } - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, unbonds) + res, err := codec.MarshalJSONIndent(types.ModuleCdc, unbonds) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -180,10 +180,10 @@ func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, return res, nil } -func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { +func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { var params types.QueryDelegatorParams - err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) + err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -199,7 +199,7 @@ func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, delegationResps = types.DelegationResponses{} } - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, delegationResps) + res, err := codec.MarshalJSONIndent(types.ModuleCdc, delegationResps) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -207,10 +207,10 @@ func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, return res, nil } -func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { +func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { var params types.QueryDelegatorParams - err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) + err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -220,7 +220,7 @@ func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, unbondingDelegations = types.UnbondingDelegations{} } - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, unbondingDelegations) + res, err := codec.MarshalJSONIndent(types.ModuleCdc, unbondingDelegations) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -228,12 +228,12 @@ func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, return res, nil } -func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { +func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { var params types.QueryDelegatorParams stakingParams := k.GetParams(ctx) - err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) + err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -243,7 +243,7 @@ func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper, validators = types.Validators{} } - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, validators) + res, err := codec.MarshalJSONIndent(types.ModuleCdc, validators) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -251,10 +251,10 @@ func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper, return res, nil } -func queryDelegatorValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { +func queryDelegatorValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { var params types.QueryDelegatorValidatorRequest - err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) + err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -264,7 +264,7 @@ func queryDelegatorValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper, l return nil, err } - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, validator) + res, err := codec.MarshalJSONIndent(types.ModuleCdc, validator) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -272,10 +272,10 @@ func queryDelegatorValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper, l return res, nil } -func queryDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { +func queryDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { var params types.QueryDelegatorValidatorRequest - err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) + err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -290,7 +290,7 @@ func queryDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQue return nil, err } - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, delegationResp) + res, err := codec.MarshalJSONIndent(types.ModuleCdc, delegationResp) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -298,10 +298,10 @@ func queryDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQue return res, nil } -func queryUnbondingDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { +func queryUnbondingDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { var params types.QueryDelegatorValidatorRequest - err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) + err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -311,7 +311,7 @@ func queryUnbondingDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper, return nil, types.ErrNoUnbondingDelegation } - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, unbond) + res, err := codec.MarshalJSONIndent(types.ModuleCdc, unbond) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -319,10 +319,10 @@ func queryUnbondingDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper, return res, nil } -func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { +func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { var params types.QueryRedelegationParams - err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) + err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -352,7 +352,7 @@ func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacy redelResponses = types.RedelegationResponses{} } - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, redelResponses) + res, err := codec.MarshalJSONIndent(types.ModuleCdc, redelResponses) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -360,10 +360,10 @@ func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacy return res, nil } -func queryHistoricalInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { +func queryHistoricalInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { var params types.QueryHistoricalInfoRequest - err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) + err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -373,7 +373,7 @@ func queryHistoricalInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper, legac return nil, types.ErrNoHistoricalInfo } - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, hi) + res, err := codec.MarshalJSONIndent(types.ModuleCdc, hi) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -381,7 +381,7 @@ func queryHistoricalInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper, legac return res, nil } -func queryPool(ctx sdk.Context, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { +func queryPool(ctx sdk.Context, k Keeper) ([]byte, error) { bondDenom := k.BondDenom(ctx) bondedPool := k.GetBondedPool(ctx) notBondedPool := k.GetNotBondedPool(ctx) @@ -395,7 +395,7 @@ func queryPool(ctx sdk.Context, k Keeper, legacyQuerierCdc codec.JSONMarshaler) k.bankKeeper.GetBalance(ctx, bondedPool.GetAddress(), bondDenom).Amount, ) - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, pool) + res, err := codec.MarshalJSONIndent(types.ModuleCdc, pool) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -403,10 +403,10 @@ func queryPool(ctx sdk.Context, k Keeper, legacyQuerierCdc codec.JSONMarshaler) return res, nil } -func queryParameters(ctx sdk.Context, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { +func queryParameters(ctx sdk.Context, k Keeper) ([]byte, error) { params := k.GetParams(ctx) - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, params) + res, err := codec.MarshalJSONIndent(types.ModuleCdc, params) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/staking/keeper/querier_test.go b/x/staking/keeper/querier_test.go index 5a2e6de58e71..63cce0a2b8e5 100644 --- a/x/staking/keeper/querier_test.go +++ b/x/staking/keeper/querier_test.go @@ -2,7 +2,6 @@ package keeper_test import ( "fmt" - "github.com/cosmos/cosmos-sdk/codec" "testing" "github.com/stretchr/testify/require" @@ -17,7 +16,6 @@ import ( func TestNewQuerier(t *testing.T) { cdc, app, ctx := createTestInput() - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) addrs := simapp.AddTestAddrs(app, ctx, 500, sdk.NewInt(10000)) _, addrAcc2 := addrs[0], addrs[1] @@ -45,7 +43,7 @@ func TestNewQuerier(t *testing.T) { Data: []byte{}, } - querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) + querier := keeper.NewQuerier(app.StakingKeeper) bz, err := querier(ctx, []string{"other"}, query) require.Error(t, err) @@ -109,8 +107,7 @@ func TestNewQuerier(t *testing.T) { func TestQueryParametersPool(t *testing.T) { cdc, app, ctx := createTestInput() - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) - querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) + querier := keeper.NewQuerier(app.StakingKeeper) bondDenom := sdk.DefaultBondDenom @@ -136,8 +133,7 @@ func TestQueryParametersPool(t *testing.T) { func TestQueryValidators(t *testing.T) { cdc, app, ctx := createTestInput() params := app.StakingKeeper.GetParams(ctx) - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) - querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) + querier := keeper.NewQuerier(app.StakingKeeper) addrs := simapp.AddTestAddrs(app, ctx, 500, sdk.TokensFromConsensusPower(10000)) @@ -204,8 +200,7 @@ func TestQueryValidators(t *testing.T) { func TestQueryDelegation(t *testing.T) { cdc, app, ctx := createTestInput() params := app.StakingKeeper.GetParams(ctx) - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) - querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) + querier := keeper.NewQuerier(app.StakingKeeper) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] @@ -453,8 +448,7 @@ func TestQueryValidatorDelegations_Pagination(t *testing.T) { } cdc, app, ctx := createTestInput() - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) - querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) + querier := keeper.NewQuerier(app.StakingKeeper) addrs := simapp.AddTestAddrs(app, ctx, 100, sdk.TokensFromConsensusPower(10000)) pubKeys := simapp.CreateTestPubKeys(1) @@ -538,8 +532,7 @@ func TestQueryValidatorDelegations_Pagination(t *testing.T) { func TestQueryRedelegations(t *testing.T) { cdc, app, ctx := createTestInput() - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) - querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) + querier := keeper.NewQuerier(app.StakingKeeper) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] @@ -610,8 +603,7 @@ func TestQueryRedelegations(t *testing.T) { func TestQueryUnbondingDelegation(t *testing.T) { cdc, app, ctx := createTestInput() - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) - querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) + querier := keeper.NewQuerier(app.StakingKeeper) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] @@ -706,8 +698,7 @@ func TestQueryUnbondingDelegation(t *testing.T) { func TestQueryHistoricalInfo(t *testing.T) { cdc, app, ctx := createTestInput() - legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) - querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) + querier := keeper.NewQuerier(app.StakingKeeper) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] diff --git a/x/staking/module.go b/x/staking/module.go index 1cc38aef612a..daca2ec3c66f 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -123,8 +123,8 @@ func (AppModule) QuerierRoute() string { } // LegacyQuerierHandler returns the staking module sdk.Querier. -func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { - return keeper.NewQuerier(am.keeper, legacyQuerierCdc) +func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(am.keeper) } // RegisterQueryService registers a GRPC query service to respond to the From 1167fc600ec06de851e35cc4b6cbb9973e102bb1 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sat, 25 Jul 2020 02:23:46 +0530 Subject: [PATCH 4/9] Fix gov --- x/capability/keeper/keeper.go | 6 ++-- x/gov/keeper/keeper.go | 4 +-- x/gov/keeper/querier.go | 68 +++++++++++++++++------------------ x/gov/keeper/querier_test.go | 7 ++-- x/gov/module.go | 4 +-- 5 files changed, 45 insertions(+), 44 deletions(-) diff --git a/x/capability/keeper/keeper.go b/x/capability/keeper/keeper.go index b80efc244d2b..cb4d31df0bcf 100644 --- a/x/capability/keeper/keeper.go +++ b/x/capability/keeper/keeper.go @@ -26,7 +26,7 @@ type ( // The keeper allows the ability to create scoped sub-keepers which are tied to // a single specific module. Keeper struct { - cdc codec.Marshaler + cdc codec.BinaryMarshaler storeKey sdk.StoreKey memKey sdk.StoreKey capMap map[uint64]*types.Capability @@ -41,7 +41,7 @@ type ( // by name, in addition to creating new capabilities & authenticating capabilities // passed by other modules. ScopedKeeper struct { - cdc codec.Marshaler + cdc codec.BinaryMarshaler storeKey sdk.StoreKey memKey sdk.StoreKey capMap map[uint64]*types.Capability @@ -49,7 +49,7 @@ type ( } ) -func NewKeeper(cdc codec.Marshaler, storeKey, memKey sdk.StoreKey) *Keeper { +func NewKeeper(cdc codec.BinaryMarshaler, storeKey, memKey sdk.StoreKey) *Keeper { return &Keeper{ cdc: cdc, storeKey: storeKey, diff --git a/x/gov/keeper/keeper.go b/x/gov/keeper/keeper.go index 083711bbdac1..0e999d7f2876 100644 --- a/x/gov/keeper/keeper.go +++ b/x/gov/keeper/keeper.go @@ -27,7 +27,7 @@ type Keeper struct { storeKey sdk.StoreKey // The codec codec for binary encoding/decoding. - cdc codec.Marshaler + cdc codec.BinaryMarshaler // Proposal router router types.Router @@ -41,7 +41,7 @@ type Keeper struct { // // CONTRACT: the parameter Subspace must have the param key table already initialized func NewKeeper( - cdc codec.Marshaler, key sdk.StoreKey, paramSpace types.ParamSubspace, + cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace types.ParamSubspace, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, sk types.StakingKeeper, rtr types.Router, ) Keeper { diff --git a/x/gov/keeper/querier.go b/x/gov/keeper/querier.go index 9545e5e29b83..af1a20270628 100644 --- a/x/gov/keeper/querier.go +++ b/x/gov/keeper/querier.go @@ -11,32 +11,32 @@ import ( ) // NewQuerier creates a new gov Querier instance -func NewQuerier(keeper Keeper) sdk.Querier { +func NewQuerier(keeper Keeper, legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { case types.QueryParams: - return queryParams(ctx, path[1:], req, keeper) + return queryParams(ctx, path[1:], req, keeper, legacyQuerierCdc) case types.QueryProposals: - return queryProposals(ctx, path[1:], req, keeper) + return queryProposals(ctx, path[1:], req, keeper, legacyQuerierCdc) case types.QueryProposal: - return queryProposal(ctx, path[1:], req, keeper) + return queryProposal(ctx, path[1:], req, keeper, legacyQuerierCdc) case types.QueryDeposits: - return queryDeposits(ctx, path[1:], req, keeper) + return queryDeposits(ctx, path[1:], req, keeper, legacyQuerierCdc) case types.QueryDeposit: - return queryDeposit(ctx, path[1:], req, keeper) + return queryDeposit(ctx, path[1:], req, keeper, legacyQuerierCdc) case types.QueryVotes: - return queryVotes(ctx, path[1:], req, keeper) + return queryVotes(ctx, path[1:], req, keeper, legacyQuerierCdc) case types.QueryVote: - return queryVote(ctx, path[1:], req, keeper) + return queryVote(ctx, path[1:], req, keeper, legacyQuerierCdc) case types.QueryTally: - return queryTally(ctx, path[1:], req, keeper) + return queryTally(ctx, path[1:], req, keeper, legacyQuerierCdc) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path: %s", path[0]) @@ -44,24 +44,24 @@ func NewQuerier(keeper Keeper) sdk.Querier { } } -func queryParams(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) ([]byte, error) { +func queryParams(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { switch path[0] { case types.ParamDeposit: - bz, err := codec.MarshalJSONIndent(keeper.cdc, keeper.GetDepositParams(ctx)) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, keeper.GetDepositParams(ctx)) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } return bz, nil case types.ParamVoting: - bz, err := codec.MarshalJSONIndent(keeper.cdc, keeper.GetVotingParams(ctx)) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, keeper.GetVotingParams(ctx)) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } return bz, nil case types.ParamTallying: - bz, err := codec.MarshalJSONIndent(keeper.cdc, keeper.GetTallyParams(ctx)) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, keeper.GetTallyParams(ctx)) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -73,9 +73,9 @@ func queryParams(ctx sdk.Context, path []string, req abci.RequestQuery, keeper K } // nolint: unparam -func queryProposal(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) ([]byte, error) { +func queryProposal(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryProposalParams - err := keeper.cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -85,7 +85,7 @@ func queryProposal(ctx sdk.Context, path []string, req abci.RequestQuery, keeper return nil, sdkerrors.Wrapf(types.ErrUnknownProposal, "%d", params.ProposalID) } - bz, err := codec.MarshalJSONIndent(keeper.cdc, proposal) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, proposal) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -94,15 +94,15 @@ func queryProposal(ctx sdk.Context, path []string, req abci.RequestQuery, keeper } // nolint: unparam -func queryDeposit(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) ([]byte, error) { +func queryDeposit(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDepositParams - err := keeper.cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } deposit, _ := keeper.GetDeposit(ctx, params.ProposalID, params.Depositor) - bz, err := codec.MarshalJSONIndent(keeper.cdc, deposit) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, deposit) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -111,15 +111,15 @@ func queryDeposit(ctx sdk.Context, path []string, req abci.RequestQuery, keeper } // nolint: unparam -func queryVote(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) ([]byte, error) { +func queryVote(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryVoteParams - err := keeper.cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } vote, _ := keeper.GetVote(ctx, params.ProposalID, params.Voter) - bz, err := codec.MarshalJSONIndent(keeper.cdc, vote) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, vote) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -128,9 +128,9 @@ func queryVote(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Kee } // nolint: unparam -func queryDeposits(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) ([]byte, error) { +func queryDeposits(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryProposalParams - err := keeper.cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -140,7 +140,7 @@ func queryDeposits(ctx sdk.Context, path []string, req abci.RequestQuery, keeper deposits = types.Deposits{} } - bz, err := codec.MarshalJSONIndent(keeper.cdc, deposits) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, deposits) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -149,9 +149,9 @@ func queryDeposits(ctx sdk.Context, path []string, req abci.RequestQuery, keeper } // nolint: unparam -func queryTally(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) ([]byte, error) { +func queryTally(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryProposalParams - err := keeper.cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -177,7 +177,7 @@ func queryTally(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Ke _, _, tallyResult = keeper.Tally(ctx, proposal) } - bz, err := codec.MarshalJSONIndent(keeper.cdc, tallyResult) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, tallyResult) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -186,9 +186,9 @@ func queryTally(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Ke } // nolint: unparam -func queryVotes(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) ([]byte, error) { +func queryVotes(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryProposalVotesParams - err := keeper.cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -205,7 +205,7 @@ func queryVotes(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Ke } } - bz, err := codec.MarshalJSONIndent(keeper.cdc, votes) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, votes) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -213,9 +213,9 @@ func queryVotes(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Ke return bz, nil } -func queryProposals(ctx sdk.Context, _ []string, req abci.RequestQuery, keeper Keeper) ([]byte, error) { +func queryProposals(ctx sdk.Context, _ []string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryProposalsParams - err := keeper.cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -225,7 +225,7 @@ func queryProposals(ctx sdk.Context, _ []string, req abci.RequestQuery, keeper K proposals = types.Proposals{} } - bz, err := codec.MarshalJSONIndent(keeper.cdc, proposals) + bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, proposals) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/gov/keeper/querier_test.go b/x/gov/keeper/querier_test.go index f517874244bc..db86e896795a 100644 --- a/x/gov/keeper/querier_test.go +++ b/x/gov/keeper/querier_test.go @@ -147,8 +147,8 @@ func TestQueries(t *testing.T) { app := simapp.Setup(false) ctx := app.BaseApp.NewContext(false, abci.Header{}) appCodec := app.AppCodec() - - querier := keeper.NewQuerier(app.GovKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.GovKeeper, legacyQuerierCdc) TestAddrs := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(20000001)) @@ -317,7 +317,8 @@ func TestPaginatedVotesQuery(t *testing.T) { app.GovKeeper.SetVote(ctx, vote) } - querier := keeper.NewQuerier(app.GovKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.GovKeeper, legacyQuerierCdc) // keeper preserves consistent order for each query, but this is not the insertion order all := getQueriedVotes(t, ctx, appCodec, querier, proposal.ProposalID, 1, 0) diff --git a/x/gov/module.go b/x/gov/module.go index f5b9541b1cd2..ab2745fffa81 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -145,8 +145,8 @@ func (AppModule) QuerierRoute() string { } // LegacyQuerierHandler returns no sdk.Querier. -func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { - return keeper.NewQuerier(am.keeper) +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(am.keeper, legacyQuerierCdc) } // RegisterQueryService registers a GRPC query service to respond to the From 92a9fd1b8643f41671575f8c0d48c6402758ea87 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sat, 25 Jul 2020 02:48:05 +0530 Subject: [PATCH 5/9] Fix ibc and evidence --- x/auth/keeper/querier_test.go | 4 ++-- x/bank/keeper/querier_test.go | 20 ++++++++++---------- x/distribution/keeper/querier_test.go | 4 ++-- x/evidence/keeper/keeper.go | 8 ++++---- x/evidence/keeper/keeper_test.go | 5 ++++- x/evidence/keeper/querier.go | 18 +++++++++--------- x/evidence/module.go | 4 ++-- x/ibc/02-client/exported/exported.go | 14 +++++++------- x/ibc/02-client/keeper/querier.go | 6 +++--- x/ibc/03-connection/keeper/keeper.go | 6 +++--- x/ibc/04-channel/keeper/keeper.go | 4 ++-- x/ibc/04-channel/keeper/querier.go | 6 +++--- x/ibc/07-tendermint/types/client_state.go | 16 ++++++++-------- x/ibc/09-localhost/types/client_state.go | 14 +++++++------- x/ibc/keeper/querier.go | 8 +++++--- x/ibc/module.go | 4 ++-- x/ibc/testing/chain.go | 5 ++++- x/mint/keeper/querier_test.go | 3 ++- x/upgrade/keeper/querier.go | 1 + 19 files changed, 80 insertions(+), 70 deletions(-) diff --git a/x/auth/keeper/querier_test.go b/x/auth/keeper/querier_test.go index 890f71b43241..659f6479bf35 100644 --- a/x/auth/keeper/querier_test.go +++ b/x/auth/keeper/querier_test.go @@ -17,7 +17,7 @@ import ( func TestQueryAccount(t *testing.T) { app, ctx := createTestApp(true) - jsonCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) req := abci.RequestQuery{ Path: "", @@ -25,7 +25,7 @@ func TestQueryAccount(t *testing.T) { } path := []string{types.QueryAccount} - querier := keep.NewQuerier(app.AccountKeeper, jsonCdc) + querier := keep.NewQuerier(app.AccountKeeper, legacyQuerierCdc) bz, err := querier(ctx, []string{"other"}, req) require.Error(t, err) diff --git a/x/bank/keeper/querier_test.go b/x/bank/keeper/querier_test.go index 8926644036ab..791ffc0ce923 100644 --- a/x/bank/keeper/querier_test.go +++ b/x/bank/keeper/querier_test.go @@ -15,14 +15,14 @@ import ( func (suite *IntegrationTestSuite) TestQuerier_QueryBalance() { app, ctx := suite.app, suite.ctx - jsonCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) _, _, addr := testdata.KeyTestPubAddr() req := abci.RequestQuery{ Path: fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryBalance), Data: []byte{}, } - querier := keeper.NewQuerier(app.BankKeeper, jsonCdc) + querier := keeper.NewQuerier(app.BankKeeper, legacyQuerierCdc) res, err := querier(ctx, []string{types.QueryBalance}, req) suite.Require().NotNil(err) @@ -52,14 +52,14 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryBalance() { func (suite *IntegrationTestSuite) TestQuerier_QueryAllBalances() { app, ctx := suite.app, suite.ctx - jsonCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) _, _, addr := testdata.KeyTestPubAddr() req := abci.RequestQuery{ Path: fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryAllBalances), Data: []byte{}, } - querier := keeper.NewQuerier(app.BankKeeper, jsonCdc) + querier := keeper.NewQuerier(app.BankKeeper, legacyQuerierCdc) res, err := querier(ctx, []string{types.QueryAllBalances}, req) suite.Require().NotNil(err) @@ -89,7 +89,7 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryAllBalances() { func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupply() { app, ctx := suite.app, suite.ctx - jsonCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) expectedTotalSupply := types.NewSupply(sdk.NewCoins(sdk.NewInt64Coin("test", 400000000))) app.BankKeeper.SetSupply(ctx, expectedTotalSupply) @@ -98,7 +98,7 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupply() { Data: []byte{}, } - querier := keeper.NewQuerier(app.BankKeeper, jsonCdc) + querier := keeper.NewQuerier(app.BankKeeper, legacyQuerierCdc) res, err := querier(ctx, []string{types.QueryTotalSupply}, req) suite.Require().NotNil(err) @@ -116,7 +116,7 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupply() { func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupplyOf() { app, ctx := suite.app, suite.ctx - jsonCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) test1Supply := sdk.NewInt64Coin("test1", 4000000) test2Supply := sdk.NewInt64Coin("test2", 700000000) @@ -128,7 +128,7 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupplyOf() { Data: []byte{}, } - querier := keeper.NewQuerier(app.BankKeeper, jsonCdc) + querier := keeper.NewQuerier(app.BankKeeper, legacyQuerierCdc) res, err := querier(ctx, []string{types.QuerySupplyOf}, req) suite.Require().NotNil(err) @@ -146,13 +146,13 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupplyOf() { func (suite *IntegrationTestSuite) TestQuerierRouteNotFound() { app, ctx := suite.app, suite.ctx - jsonCdc := codec.NewAminoCodec(app.Codec()) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) req := abci.RequestQuery{ Path: fmt.Sprintf("custom/%s/invalid", types.ModuleName), Data: []byte{}, } - querier := keeper.NewQuerier(app.BankKeeper, jsonCdc) + querier := keeper.NewQuerier(app.BankKeeper, legacyQuerierCdc) _, err := querier(ctx, []string{"invalid"}, req) suite.Error(err) } diff --git a/x/distribution/keeper/querier_test.go b/x/distribution/keeper/querier_test.go index da9fdd53b7fe..5934af6a1b73 100644 --- a/x/distribution/keeper/querier_test.go +++ b/x/distribution/keeper/querier_test.go @@ -113,7 +113,7 @@ func TestQueries(t *testing.T) { cdc := codec.New() types.RegisterCodec(cdc) banktypes.RegisterCodec(cdc) - jsonCdc := codec.NewAminoCodec(cdc) + legacyQuerierCdc := codec.NewAminoCodec(cdc) app := simapp.Setup(false) ctx := app.BaseApp.NewContext(false, abci.Header{}) @@ -122,7 +122,7 @@ func TestQueries(t *testing.T) { valAddrs := simapp.ConvertAddrsToValAddrs(addr) valOpAddr1 := valAddrs[0] - querier := keeper.NewQuerier(app.DistrKeeper, jsonCdc) + querier := keeper.NewQuerier(app.DistrKeeper, legacyQuerierCdc) // test param queries params := types.Params{ diff --git a/x/evidence/keeper/keeper.go b/x/evidence/keeper/keeper.go index ce629ff0bc4d..e0239bba307c 100644 --- a/x/evidence/keeper/keeper.go +++ b/x/evidence/keeper/keeper.go @@ -20,7 +20,7 @@ import ( // managing persistence, state transitions and query handling for the evidence // module. type Keeper struct { - cdc codec.Marshaler + cdc codec.BinaryMarshaler storeKey sdk.StoreKey router types.Router stakingKeeper types.StakingKeeper @@ -28,7 +28,7 @@ type Keeper struct { } func NewKeeper( - cdc codec.Marshaler, storeKey sdk.StoreKey, stakingKeeper types.StakingKeeper, + cdc codec.BinaryMarshaler, storeKey sdk.StoreKey, stakingKeeper types.StakingKeeper, slashingKeeper types.SlashingKeeper, ) *Keeper { @@ -201,13 +201,13 @@ func (k Keeper) MarshalEvidenceJSON(evidence exported.Evidence) ([]byte, error) return nil, err } - return k.cdc.MarshalJSON(any) + return k.cdc.MarshalBinaryBare(any) } // UnmarshalEvidenceJSON returns an Evidence from JSON encoded bytes func (k Keeper) UnmarshalEvidenceJSON(bz []byte) (exported.Evidence, error) { var any codectypes.Any - if err := k.cdc.UnmarshalJSON(bz, &any); err != nil { + if err := k.cdc.UnmarshalBinaryBare(bz, &any); err != nil { return nil, err } diff --git a/x/evidence/keeper/keeper_test.go b/x/evidence/keeper/keeper_test.go index 37236f545217..1aaaca5f38dc 100644 --- a/x/evidence/keeper/keeper_test.go +++ b/x/evidence/keeper/keeper_test.go @@ -6,6 +6,8 @@ import ( "testing" "time" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" @@ -81,6 +83,7 @@ type KeeperTestSuite struct { func (suite *KeeperTestSuite) SetupTest() { checkTx := false app := simapp.Setup(checkTx) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) // recreate keeper in order to use custom testing types evidenceKeeper := keeper.NewKeeper( @@ -93,7 +96,7 @@ func (suite *KeeperTestSuite) SetupTest() { app.EvidenceKeeper = *evidenceKeeper suite.ctx = app.BaseApp.NewContext(checkTx, abci.Header{Height: 1}) - suite.querier = keeper.NewQuerier(*evidenceKeeper) + suite.querier = keeper.NewQuerier(*evidenceKeeper, legacyQuerierCdc) suite.app = app for i, addr := range valAddresses { diff --git a/x/evidence/keeper/querier.go b/x/evidence/keeper/querier.go index 104085cb83b1..a07576b324c3 100644 --- a/x/evidence/keeper/querier.go +++ b/x/evidence/keeper/querier.go @@ -11,7 +11,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" ) -func NewQuerier(k Keeper) sdk.Querier { +func NewQuerier(k Keeper, legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { var ( res []byte @@ -20,10 +20,10 @@ func NewQuerier(k Keeper) sdk.Querier { switch path[0] { case types.QueryEvidence: - res, err = queryEvidence(ctx, req, k) + res, err = queryEvidence(ctx, req, k, legacyQuerierCdc) case types.QueryAllEvidence: - res, err = queryAllEvidence(ctx, req, k) + res, err = queryAllEvidence(ctx, req, k, legacyQuerierCdc) default: err = sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) @@ -33,10 +33,10 @@ func NewQuerier(k Keeper) sdk.Querier { } } -func queryEvidence(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryEvidence(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryEvidenceRequest - err := k.cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -46,7 +46,7 @@ func queryEvidence(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, er return nil, sdkerrors.Wrap(types.ErrNoEvidenceExists, params.EvidenceHash.String()) } - res, err := codec.MarshalJSONIndent(k.cdc, evidence) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, evidence) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -54,10 +54,10 @@ func queryEvidence(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, er return res, nil } -func queryAllEvidence(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryAllEvidence(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryAllEvidenceParams - err := k.cdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -71,7 +71,7 @@ func queryAllEvidence(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, evidence = evidence[start:end] } - res, err := codec.MarshalJSONIndent(k.cdc, evidence) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, evidence) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/evidence/module.go b/x/evidence/module.go index 4f06c3112efd..1e9035c4af1a 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -138,8 +138,8 @@ func (AppModule) QuerierRoute() string { } // LegacyQuerierHandler returns the evidence module's Querier. -func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { - return keeper.NewQuerier(am.keeper) +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(am.keeper, legacyQuerierCdc) } // RegisterQueryService registers a GRPC query service to respond to the diff --git a/x/ibc/02-client/exported/exported.go b/x/ibc/02-client/exported/exported.go index fb8972452aae..306ab65a1047 100644 --- a/x/ibc/02-client/exported/exported.go +++ b/x/ibc/02-client/exported/exported.go @@ -29,7 +29,7 @@ type ClientState interface { VerifyClientConsensusState( store sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, aminoCdc *codec.Codec, root commitmentexported.Root, height uint64, @@ -41,7 +41,7 @@ type ClientState interface { ) error VerifyConnectionState( store sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, height uint64, prefix commitmentexported.Prefix, proof []byte, @@ -51,7 +51,7 @@ type ClientState interface { ) error VerifyChannelState( store sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, height uint64, prefix commitmentexported.Prefix, proof []byte, @@ -62,7 +62,7 @@ type ClientState interface { ) error VerifyPacketCommitment( store sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, height uint64, prefix commitmentexported.Prefix, proof []byte, @@ -74,7 +74,7 @@ type ClientState interface { ) error VerifyPacketAcknowledgement( store sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, height uint64, prefix commitmentexported.Prefix, proof []byte, @@ -86,7 +86,7 @@ type ClientState interface { ) error VerifyPacketAcknowledgementAbsence( store sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, height uint64, prefix commitmentexported.Prefix, proof []byte, @@ -97,7 +97,7 @@ type ClientState interface { ) error VerifyNextSequenceRecv( store sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, height uint64, prefix commitmentexported.Prefix, proof []byte, diff --git a/x/ibc/02-client/keeper/querier.go b/x/ibc/02-client/keeper/querier.go index 7cadac9fe426..416c7e3aeaae 100644 --- a/x/ibc/02-client/keeper/querier.go +++ b/x/ibc/02-client/keeper/querier.go @@ -12,10 +12,10 @@ import ( ) // QuerierClients defines the sdk.Querier to query all the light client states. -func QuerierClients(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func QuerierClients(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryAllClientsParams - if err := k.cdc.UnmarshalJSON(req.Data, ¶ms); err != nil { + if err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms); err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -28,7 +28,7 @@ func QuerierClients(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, e clients = clients[start:end] } - res, err := codec.MarshalJSONIndent(k.cdc, clients) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, clients) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/ibc/03-connection/keeper/keeper.go b/x/ibc/03-connection/keeper/keeper.go index 796139990fda..50614012efc7 100644 --- a/x/ibc/03-connection/keeper/keeper.go +++ b/x/ibc/03-connection/keeper/keeper.go @@ -22,13 +22,13 @@ type Keeper struct { types.QueryServer storeKey sdk.StoreKey - aminoCdc *codec.Codec // amino codec. TODO: remove after clients have been migrated to proto - cdc codec.Marshaler // hybrid codec + aminoCdc *codec.Codec // amino codec. TODO: remove after clients have been migrated to proto + cdc codec.BinaryMarshaler // hybrid codec clientKeeper types.ClientKeeper } // NewKeeper creates a new IBC connection Keeper instance -func NewKeeper(aminoCdc *codec.Codec, cdc codec.Marshaler, key sdk.StoreKey, ck types.ClientKeeper) Keeper { +func NewKeeper(aminoCdc *codec.Codec, cdc codec.BinaryMarshaler, key sdk.StoreKey, ck types.ClientKeeper) Keeper { return Keeper{ storeKey: key, aminoCdc: aminoCdc, diff --git a/x/ibc/04-channel/keeper/keeper.go b/x/ibc/04-channel/keeper/keeper.go index 06fd4a938902..2d220db1acc6 100644 --- a/x/ibc/04-channel/keeper/keeper.go +++ b/x/ibc/04-channel/keeper/keeper.go @@ -23,7 +23,7 @@ type Keeper struct { types.QueryServer storeKey sdk.StoreKey - cdc codec.Marshaler + cdc codec.BinaryMarshaler clientKeeper types.ClientKeeper connectionKeeper types.ConnectionKeeper portKeeper types.PortKeeper @@ -32,7 +32,7 @@ type Keeper struct { // NewKeeper creates a new IBC channel Keeper instance func NewKeeper( - cdc codec.Marshaler, key sdk.StoreKey, + cdc codec.BinaryMarshaler, key sdk.StoreKey, clientKeeper types.ClientKeeper, connectionKeeper types.ConnectionKeeper, portKeeper types.PortKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, ) Keeper { diff --git a/x/ibc/04-channel/keeper/querier.go b/x/ibc/04-channel/keeper/querier.go index 8eaf14cca40a..000f84393d53 100644 --- a/x/ibc/04-channel/keeper/querier.go +++ b/x/ibc/04-channel/keeper/querier.go @@ -13,10 +13,10 @@ import ( // QuerierChannelClientState defines the sdk.Querier to query all the ClientState // associated with a given Channel. -func QuerierChannelClientState(ctx sdk.Context, abciReq abci.RequestQuery, k Keeper) ([]byte, error) { +func QuerierChannelClientState(ctx sdk.Context, abciReq abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var req types.QueryChannelClientStateRequest - if err := k.cdc.UnmarshalJSON(abciReq.Data, &req); err != nil { + if err := legacyQuerierCdc.UnmarshalJSON(abciReq.Data, &req); err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -35,7 +35,7 @@ func QuerierChannelClientState(ctx sdk.Context, abciReq abci.RequestQuery, k Kee return nil, sdkerrors.Wrapf(clienttypes.ErrClientNotFound, connection.ClientID) } - res, err := codec.MarshalJSONIndent(k.cdc, clientState) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, clientState) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/ibc/07-tendermint/types/client_state.go b/x/ibc/07-tendermint/types/client_state.go index 9b2450ef18ff..a9d0e2721988 100644 --- a/x/ibc/07-tendermint/types/client_state.go +++ b/x/ibc/07-tendermint/types/client_state.go @@ -169,7 +169,7 @@ func (cs ClientState) GetProofSpecs() []*ics23.ProofSpec { // Tendermint client stored on the target machine. func (cs ClientState) VerifyClientConsensusState( _ sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, aminoCdc *codec.Codec, provingRoot commitmentexported.Root, height uint64, @@ -206,7 +206,7 @@ func (cs ClientState) VerifyClientConsensusState( // specified connection end stored on the target machine. func (cs ClientState) VerifyConnectionState( _ sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, height uint64, prefix commitmentexported.Prefix, proof []byte, @@ -245,7 +245,7 @@ func (cs ClientState) VerifyConnectionState( // channel end, under the specified port, stored on the target machine. func (cs ClientState) VerifyChannelState( _ sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, height uint64, prefix commitmentexported.Prefix, proof []byte, @@ -285,7 +285,7 @@ func (cs ClientState) VerifyChannelState( // the specified port, specified channel, and specified sequence. func (cs ClientState) VerifyPacketCommitment( _ sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, height uint64, prefix commitmentexported.Prefix, proof []byte, @@ -316,7 +316,7 @@ func (cs ClientState) VerifyPacketCommitment( // acknowledgement at the specified port, specified channel, and specified sequence. func (cs ClientState) VerifyPacketAcknowledgement( _ sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, height uint64, prefix commitmentexported.Prefix, proof []byte, @@ -348,7 +348,7 @@ func (cs ClientState) VerifyPacketAcknowledgement( // specified sequence. func (cs ClientState) VerifyPacketAcknowledgementAbsence( _ sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, height uint64, prefix commitmentexported.Prefix, proof []byte, @@ -378,7 +378,7 @@ func (cs ClientState) VerifyPacketAcknowledgementAbsence( // received of the specified channel at the specified port. func (cs ClientState) VerifyNextSequenceRecv( _ sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, height uint64, prefix commitmentexported.Prefix, proof []byte, @@ -410,7 +410,7 @@ func (cs ClientState) VerifyNextSequenceRecv( // shared between the verification functions and returns the unmarshalled // merkle proof and an error if one occurred. func sanitizeVerificationArgs( - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, cs ClientState, height uint64, prefix commitmentexported.Prefix, diff --git a/x/ibc/09-localhost/types/client_state.go b/x/ibc/09-localhost/types/client_state.go index 92905bd50f04..9fc686e91c16 100644 --- a/x/ibc/09-localhost/types/client_state.go +++ b/x/ibc/09-localhost/types/client_state.go @@ -87,7 +87,7 @@ func (cs ClientState) GetProofSpecs() []*ics23.ProofSpec { // Tendermint client stored on the target machine. func (cs ClientState) VerifyClientConsensusState( store sdk.KVStore, - _ codec.Marshaler, + _ codec.BinaryMarshaler, aminoCdc *codec.Codec, _ commitmentexported.Root, height uint64, @@ -126,7 +126,7 @@ func (cs ClientState) VerifyClientConsensusState( // specified connection end stored locally. func (cs ClientState) VerifyConnectionState( store sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, _ uint64, prefix commitmentexported.Prefix, _ []byte, @@ -164,7 +164,7 @@ func (cs ClientState) VerifyConnectionState( // channel end, under the specified port, stored on the local machine. func (cs ClientState) VerifyChannelState( store sdk.KVStore, - cdc codec.Marshaler, + cdc codec.BinaryMarshaler, _ uint64, prefix commitmentexported.Prefix, _ []byte, @@ -203,7 +203,7 @@ func (cs ClientState) VerifyChannelState( // the specified port, specified channel, and specified sequence. func (cs ClientState) VerifyPacketCommitment( store sdk.KVStore, - _ codec.Marshaler, + _ codec.BinaryMarshaler, _ uint64, prefix commitmentexported.Prefix, _ []byte, @@ -237,7 +237,7 @@ func (cs ClientState) VerifyPacketCommitment( // acknowledgement at the specified port, specified channel, and specified sequence. func (cs ClientState) VerifyPacketAcknowledgement( store sdk.KVStore, - _ codec.Marshaler, + _ codec.BinaryMarshaler, _ uint64, prefix commitmentexported.Prefix, _ []byte, @@ -272,7 +272,7 @@ func (cs ClientState) VerifyPacketAcknowledgement( // specified sequence. func (cs ClientState) VerifyPacketAcknowledgementAbsence( store sdk.KVStore, - _ codec.Marshaler, + _ codec.BinaryMarshaler, _ uint64, prefix commitmentexported.Prefix, _ []byte, @@ -298,7 +298,7 @@ func (cs ClientState) VerifyPacketAcknowledgementAbsence( // received of the specified channel at the specified port. func (cs ClientState) VerifyNextSequenceRecv( store sdk.KVStore, - _ codec.Marshaler, + _ codec.BinaryMarshaler, _ uint64, prefix commitmentexported.Prefix, _ []byte, diff --git a/x/ibc/keeper/querier.go b/x/ibc/keeper/querier.go index 025bae1c2ede..6ba0d47ae4d7 100644 --- a/x/ibc/keeper/querier.go +++ b/x/ibc/keeper/querier.go @@ -3,6 +3,8 @@ package keeper import ( abci "github.com/tendermint/tendermint/abci/types" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clientkeeper "github.com/cosmos/cosmos-sdk/x/ibc/02-client/keeper" @@ -13,7 +15,7 @@ import ( ) // NewQuerier creates a querier for the IBC module -func NewQuerier(k Keeper) sdk.Querier { +func NewQuerier(k Keeper, legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { var ( res []byte @@ -24,7 +26,7 @@ func NewQuerier(k Keeper) sdk.Querier { case clienttypes.SubModuleName: switch path[1] { case clienttypes.QueryAllClients: - res, err = clientkeeper.QuerierClients(ctx, req, k.ClientKeeper) + res, err = clientkeeper.QuerierClients(ctx, req, k.ClientKeeper, legacyQuerierCdc) default: err = sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown IBC %s query endpoint", clienttypes.SubModuleName) } @@ -33,7 +35,7 @@ func NewQuerier(k Keeper) sdk.Querier { case channeltypes.SubModuleName: switch path[1] { case channeltypes.QueryChannelClientState: - res, err = channelkeeper.QuerierChannelClientState(ctx, req, k.ChannelKeeper) + res, err = channelkeeper.QuerierChannelClientState(ctx, req, k.ChannelKeeper, legacyQuerierCdc) default: err = sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown IBC %s query endpoint", channeltypes.SubModuleName) } diff --git a/x/ibc/module.go b/x/ibc/module.go index 1655a4382901..d27a883597c7 100644 --- a/x/ibc/module.go +++ b/x/ibc/module.go @@ -120,8 +120,8 @@ func (AppModule) QuerierRoute() string { } // LegacyQuerierHandler returns the ibc module sdk.Querier. -func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { - return keeper.NewQuerier(*am.keeper) +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(*am.keeper, legacyQuerierCdc) } // RegisterQueryService registers the gRPC query service for the ibc module. diff --git a/x/ibc/testing/chain.go b/x/ibc/testing/chain.go index 9e81d9465db5..fb87c694add8 100644 --- a/x/ibc/testing/chain.go +++ b/x/ibc/testing/chain.go @@ -6,6 +6,8 @@ import ( "testing" "time" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" @@ -110,6 +112,7 @@ func NewTestChain(t *testing.T, chainID string) *TestChain { } app := simapp.SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, balance) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) // create current header and call begin block header := abci.Header{ @@ -125,7 +128,7 @@ func NewTestChain(t *testing.T, chainID string) *TestChain { ChainID: chainID, App: app, CurrentHeader: header, - Querier: keeper.NewQuerier(*app.IBCKeeper), + Querier: keeper.NewQuerier(*app.IBCKeeper, legacyQuerierCdc), QueryServer: app.IBCKeeper, TxConfig: txConfig, Vals: valSet, diff --git a/x/mint/keeper/querier_test.go b/x/mint/keeper/querier_test.go index 6ae42adf240b..7ed384178032 100644 --- a/x/mint/keeper/querier_test.go +++ b/x/mint/keeper/querier_test.go @@ -1,9 +1,10 @@ package keeper_test import ( - "github.com/cosmos/cosmos-sdk/codec" "testing" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/upgrade/keeper/querier.go b/x/upgrade/keeper/querier.go index ce080c91feb0..9d0fffa650c0 100644 --- a/x/upgrade/keeper/querier.go +++ b/x/upgrade/keeper/querier.go @@ -2,6 +2,7 @@ package keeper import ( "encoding/binary" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/upgrade/types" From 06756e0b9d42c6e7cfd5f086f5c5a21a09b72e74 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sat, 25 Jul 2020 02:54:18 +0530 Subject: [PATCH 6/9] Fix ibc-transfer --- x/ibc-transfer/keeper/keeper.go | 4 ++-- x/ibc/03-connection/simulation/decoder.go | 2 +- x/ibc/04-channel/simulation/decoder.go | 2 +- x/ibc/keeper/keeper.go | 6 +++--- x/ibc/keeper/keeper_test.go | 3 ++- x/ibc/simulation/decoder.go | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/x/ibc-transfer/keeper/keeper.go b/x/ibc-transfer/keeper/keeper.go index 8c028cbb5fa2..c9ede680091d 100644 --- a/x/ibc-transfer/keeper/keeper.go +++ b/x/ibc-transfer/keeper/keeper.go @@ -20,7 +20,7 @@ import ( // Keeper defines the IBC fungible transfer keeper type Keeper struct { storeKey sdk.StoreKey - cdc codec.Marshaler + cdc codec.BinaryMarshaler channelKeeper types.ChannelKeeper portKeeper types.PortKeeper @@ -31,7 +31,7 @@ type Keeper struct { // NewKeeper creates a new IBC transfer Keeper instance func NewKeeper( - cdc codec.Marshaler, key sdk.StoreKey, + cdc codec.BinaryMarshaler, key sdk.StoreKey, channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, ) Keeper { diff --git a/x/ibc/03-connection/simulation/decoder.go b/x/ibc/03-connection/simulation/decoder.go index 94e7edff5e9e..c80a987b6fd8 100644 --- a/x/ibc/03-connection/simulation/decoder.go +++ b/x/ibc/03-connection/simulation/decoder.go @@ -13,7 +13,7 @@ import ( // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's // Value to the corresponding connection type. -func NewDecodeStore(cdc codec.Marshaler, kvA, kvB tmkv.Pair) (string, bool) { +func NewDecodeStore(cdc codec.BinaryMarshaler, kvA, kvB tmkv.Pair) (string, bool) { switch { case bytes.HasPrefix(kvA.Key, host.KeyClientStorePrefix) && bytes.HasSuffix(kvA.Key, host.KeyConnectionPrefix): var clientConnectionsA, clientConnectionsB types.ClientPaths diff --git a/x/ibc/04-channel/simulation/decoder.go b/x/ibc/04-channel/simulation/decoder.go index 4f08728f24ab..9d5b88670c4a 100644 --- a/x/ibc/04-channel/simulation/decoder.go +++ b/x/ibc/04-channel/simulation/decoder.go @@ -14,7 +14,7 @@ import ( // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's // Value to the corresponding channel type. -func NewDecodeStore(cdc codec.Marshaler, kvA, kvB tmkv.Pair) (string, bool) { +func NewDecodeStore(cdc codec.BinaryMarshaler, kvA, kvB tmkv.Pair) (string, bool) { switch { case bytes.HasPrefix(kvA.Key, []byte(host.KeyChannelPrefix)): var channelA, channelB types.Channel diff --git a/x/ibc/keeper/keeper.go b/x/ibc/keeper/keeper.go index b113553e41b3..759d402bdf23 100644 --- a/x/ibc/keeper/keeper.go +++ b/x/ibc/keeper/keeper.go @@ -21,7 +21,7 @@ type Keeper struct { types.QueryServer aminoCdc *codec.Codec - cdc codec.Marshaler + cdc codec.BinaryMarshaler ClientKeeper clientkeeper.Keeper ConnectionKeeper connectionkeeper.Keeper @@ -32,7 +32,7 @@ type Keeper struct { // NewKeeper creates a new ibc Keeper func NewKeeper( - aminoCdc *codec.Codec, cdc codec.Marshaler, key sdk.StoreKey, stakingKeeper clienttypes.StakingKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, + aminoCdc *codec.Codec, cdc codec.BinaryMarshaler, key sdk.StoreKey, stakingKeeper clienttypes.StakingKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, ) *Keeper { clientKeeper := clientkeeper.NewKeeper(aminoCdc, key, stakingKeeper) connectionKeeper := connectionkeeper.NewKeeper(aminoCdc, cdc, key, clientKeeper) @@ -50,7 +50,7 @@ func NewKeeper( } // Codecs returns the IBC module codec. -func (k Keeper) Codecs() (codec.Marshaler, *codec.Codec) { +func (k Keeper) Codecs() (codec.BinaryMarshaler, *codec.Codec) { return k.cdc, k.aminoCdc } diff --git a/x/ibc/keeper/keeper_test.go b/x/ibc/keeper/keeper_test.go index c5b7aa70887a..941b20eb7845 100644 --- a/x/ibc/keeper/keeper_test.go +++ b/x/ibc/keeper/keeper_test.go @@ -25,11 +25,12 @@ type KeeperTestSuite struct { func (suite *KeeperTestSuite) SetupTest() { isCheckTx := false app := simapp.Setup(isCheckTx) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) suite.cdc = app.Codec() suite.ctx = app.BaseApp.NewContext(isCheckTx, abci.Header{}) suite.keeper = app.IBCKeeper - suite.querier = keeper.NewQuerier(*app.IBCKeeper) + suite.querier = keeper.NewQuerier(*app.IBCKeeper, legacyQuerierCdc) } func TestKeeperTestSuite(t *testing.T) { diff --git a/x/ibc/simulation/decoder.go b/x/ibc/simulation/decoder.go index ddff3da4f29e..cb8a3d1ee763 100644 --- a/x/ibc/simulation/decoder.go +++ b/x/ibc/simulation/decoder.go @@ -14,7 +14,7 @@ import ( // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's // Value to the corresponding ibc type. -func NewDecodeStore(cdc codec.Marshaler, aminoCdc *codec.Codec) func(kvA, kvB tmkv.Pair) string { +func NewDecodeStore(cdc codec.BinaryMarshaler, aminoCdc *codec.Codec) func(kvA, kvB tmkv.Pair) string { return func(kvA, kvB tmkv.Pair) string { if res, found := clientsim.NewDecodeStore(aminoCdc, kvA, kvB); found { return res From b819cc3670e128d837093a21f4252acd77582fcc Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sat, 25 Jul 2020 03:01:48 +0530 Subject: [PATCH 7/9] Fix staking --- x/staking/keeper/keeper.go | 4 +- x/staking/keeper/querier.go | 110 ++++++++++++++--------------- x/staking/keeper/querier_test.go | 25 ++++--- x/staking/module.go | 4 +- x/staking/types/delegation.go | 18 ++--- x/staking/types/historical_info.go | 6 +- x/staking/types/validator.go | 6 +- 7 files changed, 91 insertions(+), 82 deletions(-) diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index bc5e1d5c322e..86e32665d11a 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -23,7 +23,7 @@ var _ types.DelegationSet = Keeper{} // keeper of the staking store type Keeper struct { storeKey sdk.StoreKey - cdc codec.Marshaler + cdc codec.BinaryMarshaler authKeeper types.AccountKeeper bankKeeper types.BankKeeper hooks types.StakingHooks @@ -34,7 +34,7 @@ type Keeper struct { // NewKeeper creates a new staking Keeper instance func NewKeeper( - cdc codec.Marshaler, key sdk.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, + cdc codec.BinaryMarshaler, key sdk.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, ps paramtypes.Subspace, ) Keeper { // set KeyTable if it has not already been set diff --git a/x/staking/keeper/querier.go b/x/staking/keeper/querier.go index 309ba0fa0273..2b637e0c507a 100644 --- a/x/staking/keeper/querier.go +++ b/x/staking/keeper/querier.go @@ -14,50 +14,50 @@ import ( ) // creates a querier for staking REST endpoints -func NewQuerier(k Keeper) sdk.Querier { +func NewQuerier(k Keeper, legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { case types.QueryValidators: - return queryValidators(ctx, req, k) + return queryValidators(ctx, req, k, legacyQuerierCdc) case types.QueryValidator: - return queryValidator(ctx, req, k) + return queryValidator(ctx, req, k, legacyQuerierCdc) case types.QueryValidatorDelegations: - return queryValidatorDelegations(ctx, req, k) + return queryValidatorDelegations(ctx, req, k, legacyQuerierCdc) case types.QueryValidatorUnbondingDelegations: - return queryValidatorUnbondingDelegations(ctx, req, k) + return queryValidatorUnbondingDelegations(ctx, req, k, legacyQuerierCdc) case types.QueryDelegation: - return queryDelegation(ctx, req, k) + return queryDelegation(ctx, req, k, legacyQuerierCdc) case types.QueryUnbondingDelegation: - return queryUnbondingDelegation(ctx, req, k) + return queryUnbondingDelegation(ctx, req, k, legacyQuerierCdc) case types.QueryDelegatorDelegations: - return queryDelegatorDelegations(ctx, req, k) + return queryDelegatorDelegations(ctx, req, k, legacyQuerierCdc) case types.QueryDelegatorUnbondingDelegations: - return queryDelegatorUnbondingDelegations(ctx, req, k) + return queryDelegatorUnbondingDelegations(ctx, req, k, legacyQuerierCdc) case types.QueryRedelegations: - return queryRedelegations(ctx, req, k) + return queryRedelegations(ctx, req, k, legacyQuerierCdc) case types.QueryDelegatorValidators: - return queryDelegatorValidators(ctx, req, k) + return queryDelegatorValidators(ctx, req, k, legacyQuerierCdc) case types.QueryDelegatorValidator: - return queryDelegatorValidator(ctx, req, k) + return queryDelegatorValidator(ctx, req, k, legacyQuerierCdc) case types.QueryHistoricalInfo: - return queryHistoricalInfo(ctx, req, k) + return queryHistoricalInfo(ctx, req, k, legacyQuerierCdc) case types.QueryPool: - return queryPool(ctx, k) + return queryPool(ctx, k, legacyQuerierCdc) case types.QueryParameters: - return queryParameters(ctx, k) + return queryParameters(ctx, k, legacyQuerierCdc) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) @@ -65,10 +65,10 @@ func NewQuerier(k Keeper) sdk.Querier { } } -func queryValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryValidatorsParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -89,7 +89,7 @@ func queryValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, filteredVals = filteredVals[start:end] } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, filteredVals) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, filteredVals) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -97,10 +97,10 @@ func queryValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, return res, nil } -func queryValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryValidatorParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -110,7 +110,7 @@ func queryValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, e return nil, types.ErrNoValidatorFound } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, validator) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, validator) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -118,10 +118,10 @@ func queryValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, e return res, nil } -func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryValidatorParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -144,7 +144,7 @@ func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) delegationResps = types.DelegationResponses{} } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, delegationResps) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, delegationResps) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -152,10 +152,10 @@ func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) return res, nil } -func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryValidatorParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -172,7 +172,7 @@ func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, unbonds = unbonds[start:end] } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, unbonds) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, unbonds) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -180,10 +180,10 @@ func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, return res, nil } -func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -199,7 +199,7 @@ func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) delegationResps = types.DelegationResponses{} } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, delegationResps) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, delegationResps) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -207,10 +207,10 @@ func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) return res, nil } -func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -220,7 +220,7 @@ func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, unbondingDelegations = types.UnbondingDelegations{} } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, unbondingDelegations) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, unbondingDelegations) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -228,12 +228,12 @@ func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, return res, nil } -func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorParams stakingParams := k.GetParams(ctx) - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -243,7 +243,7 @@ func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper) validators = types.Validators{} } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, validators) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, validators) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -251,10 +251,10 @@ func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper) return res, nil } -func queryDelegatorValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryDelegatorValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorValidatorRequest - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -264,7 +264,7 @@ func queryDelegatorValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper) ( return nil, err } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, validator) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, validator) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -272,10 +272,10 @@ func queryDelegatorValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper) ( return res, nil } -func queryDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorValidatorRequest - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -290,7 +290,7 @@ func queryDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, return nil, err } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, delegationResp) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, delegationResp) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -298,10 +298,10 @@ func queryDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, return res, nil } -func queryUnbondingDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryUnbondingDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorValidatorRequest - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -311,7 +311,7 @@ func queryUnbondingDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper) return nil, types.ErrNoUnbondingDelegation } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, unbond) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, unbond) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -319,10 +319,10 @@ func queryUnbondingDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper) return res, nil } -func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryRedelegationParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -352,7 +352,7 @@ func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byt redelResponses = types.RedelegationResponses{} } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, redelResponses) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, redelResponses) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -360,10 +360,10 @@ func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byt return res, nil } -func queryHistoricalInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryHistoricalInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryHistoricalInfoRequest - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -373,7 +373,7 @@ func queryHistoricalInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]by return nil, types.ErrNoHistoricalInfo } - res, err := codec.MarshalJSONIndent(types.ModuleCdc, hi) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, hi) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -381,7 +381,7 @@ func queryHistoricalInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]by return res, nil } -func queryPool(ctx sdk.Context, k Keeper) ([]byte, error) { +func queryPool(ctx sdk.Context, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { bondDenom := k.BondDenom(ctx) bondedPool := k.GetBondedPool(ctx) notBondedPool := k.GetNotBondedPool(ctx) @@ -395,7 +395,7 @@ func queryPool(ctx sdk.Context, k Keeper) ([]byte, error) { k.bankKeeper.GetBalance(ctx, bondedPool.GetAddress(), bondDenom).Amount, ) - res, err := codec.MarshalJSONIndent(types.ModuleCdc, pool) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, pool) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -403,10 +403,10 @@ func queryPool(ctx sdk.Context, k Keeper) ([]byte, error) { return res, nil } -func queryParameters(ctx sdk.Context, k Keeper) ([]byte, error) { +func queryParameters(ctx sdk.Context, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) { params := k.GetParams(ctx) - res, err := codec.MarshalJSONIndent(types.ModuleCdc, params) + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, params) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/staking/keeper/querier_test.go b/x/staking/keeper/querier_test.go index 63cce0a2b8e5..dcf772d2812b 100644 --- a/x/staking/keeper/querier_test.go +++ b/x/staking/keeper/querier_test.go @@ -2,6 +2,7 @@ package keeper_test import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec" "testing" "github.com/stretchr/testify/require" @@ -43,7 +44,8 @@ func TestNewQuerier(t *testing.T) { Data: []byte{}, } - querier := keeper.NewQuerier(app.StakingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) bz, err := querier(ctx, []string{"other"}, query) require.Error(t, err) @@ -107,7 +109,8 @@ func TestNewQuerier(t *testing.T) { func TestQueryParametersPool(t *testing.T) { cdc, app, ctx := createTestInput() - querier := keeper.NewQuerier(app.StakingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) bondDenom := sdk.DefaultBondDenom @@ -133,7 +136,8 @@ func TestQueryParametersPool(t *testing.T) { func TestQueryValidators(t *testing.T) { cdc, app, ctx := createTestInput() params := app.StakingKeeper.GetParams(ctx) - querier := keeper.NewQuerier(app.StakingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 500, sdk.TokensFromConsensusPower(10000)) @@ -200,7 +204,8 @@ func TestQueryValidators(t *testing.T) { func TestQueryDelegation(t *testing.T) { cdc, app, ctx := createTestInput() params := app.StakingKeeper.GetParams(ctx) - querier := keeper.NewQuerier(app.StakingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] @@ -448,7 +453,8 @@ func TestQueryValidatorDelegations_Pagination(t *testing.T) { } cdc, app, ctx := createTestInput() - querier := keeper.NewQuerier(app.StakingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 100, sdk.TokensFromConsensusPower(10000)) pubKeys := simapp.CreateTestPubKeys(1) @@ -532,7 +538,8 @@ func TestQueryValidatorDelegations_Pagination(t *testing.T) { func TestQueryRedelegations(t *testing.T) { cdc, app, ctx := createTestInput() - querier := keeper.NewQuerier(app.StakingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] @@ -603,7 +610,8 @@ func TestQueryRedelegations(t *testing.T) { func TestQueryUnbondingDelegation(t *testing.T) { cdc, app, ctx := createTestInput() - querier := keeper.NewQuerier(app.StakingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] @@ -698,7 +706,8 @@ func TestQueryUnbondingDelegation(t *testing.T) { func TestQueryHistoricalInfo(t *testing.T) { cdc, app, ctx := createTestInput() - querier := keeper.NewQuerier(app.StakingKeeper) + legacyQuerierCdc := codec.NewAminoCodec(app.Codec()) + querier := keeper.NewQuerier(app.StakingKeeper, legacyQuerierCdc) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] diff --git a/x/staking/module.go b/x/staking/module.go index daca2ec3c66f..1cc38aef612a 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -123,8 +123,8 @@ func (AppModule) QuerierRoute() string { } // LegacyQuerierHandler returns the staking module sdk.Querier. -func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { - return keeper.NewQuerier(am.keeper) +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(am.keeper, legacyQuerierCdc) } // RegisterQueryService registers a GRPC query service to respond to the diff --git a/x/staking/types/delegation.go b/x/staking/types/delegation.go index 40dfc368cbfb..260789fc0076 100644 --- a/x/staking/types/delegation.go +++ b/x/staking/types/delegation.go @@ -38,13 +38,13 @@ func NewDelegation(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress, s } // MustMarshalDelegation returns the delegation bytes. Panics if fails -func MustMarshalDelegation(cdc codec.Marshaler, delegation Delegation) []byte { +func MustMarshalDelegation(cdc codec.BinaryMarshaler, delegation Delegation) []byte { return cdc.MustMarshalBinaryBare(&delegation) } // MustUnmarshalDelegation return the unmarshaled delegation from bytes. // Panics if fails. -func MustUnmarshalDelegation(cdc codec.Marshaler, value []byte) Delegation { +func MustUnmarshalDelegation(cdc codec.BinaryMarshaler, value []byte) Delegation { delegation, err := UnmarshalDelegation(cdc, value) if err != nil { panic(err) @@ -54,7 +54,7 @@ func MustUnmarshalDelegation(cdc codec.Marshaler, value []byte) Delegation { } // return the delegation -func UnmarshalDelegation(cdc codec.Marshaler, value []byte) (delegation Delegation, err error) { +func UnmarshalDelegation(cdc codec.BinaryMarshaler, value []byte) (delegation Delegation, err error) { err = cdc.UnmarshalBinaryBare(value, &delegation) return delegation, err } @@ -126,12 +126,12 @@ func (ubd *UnbondingDelegation) RemoveEntry(i int64) { } // return the unbonding delegation -func MustMarshalUBD(cdc codec.Marshaler, ubd UnbondingDelegation) []byte { +func MustMarshalUBD(cdc codec.BinaryMarshaler, ubd UnbondingDelegation) []byte { return cdc.MustMarshalBinaryBare(&ubd) } // unmarshal a unbonding delegation from a store value -func MustUnmarshalUBD(cdc codec.Marshaler, value []byte) UnbondingDelegation { +func MustUnmarshalUBD(cdc codec.BinaryMarshaler, value []byte) UnbondingDelegation { ubd, err := UnmarshalUBD(cdc, value) if err != nil { panic(err) @@ -141,7 +141,7 @@ func MustUnmarshalUBD(cdc codec.Marshaler, value []byte) UnbondingDelegation { } // unmarshal a unbonding delegation from a store value -func UnmarshalUBD(cdc codec.Marshaler, value []byte) (ubd UnbondingDelegation, err error) { +func UnmarshalUBD(cdc codec.BinaryMarshaler, value []byte) (ubd UnbondingDelegation, err error) { err = cdc.UnmarshalBinaryBare(value, &ubd) return ubd, err } @@ -220,12 +220,12 @@ func (red *Redelegation) RemoveEntry(i int64) { } // MustMarshalRED returns the Redelegation bytes. Panics if fails. -func MustMarshalRED(cdc codec.Marshaler, red Redelegation) []byte { +func MustMarshalRED(cdc codec.BinaryMarshaler, red Redelegation) []byte { return cdc.MustMarshalBinaryBare(&red) } // MustUnmarshalRED unmarshals a redelegation from a store value. Panics if fails. -func MustUnmarshalRED(cdc codec.Marshaler, value []byte) Redelegation { +func MustUnmarshalRED(cdc codec.BinaryMarshaler, value []byte) Redelegation { red, err := UnmarshalRED(cdc, value) if err != nil { panic(err) @@ -235,7 +235,7 @@ func MustUnmarshalRED(cdc codec.Marshaler, value []byte) Redelegation { } // UnmarshalRED unmarshals a redelegation from a store value -func UnmarshalRED(cdc codec.Marshaler, value []byte) (red Redelegation, err error) { +func UnmarshalRED(cdc codec.BinaryMarshaler, value []byte) (red Redelegation, err error) { err = cdc.UnmarshalBinaryBare(value, &red) return red, err } diff --git a/x/staking/types/historical_info.go b/x/staking/types/historical_info.go index 77a0663f17c3..7af34d13c5e9 100644 --- a/x/staking/types/historical_info.go +++ b/x/staking/types/historical_info.go @@ -21,12 +21,12 @@ func NewHistoricalInfo(header abci.Header, valSet Validators) HistoricalInfo { } // MustMarshalHistoricalInfo wll marshal historical info and panic on error -func MustMarshalHistoricalInfo(cdc codec.Marshaler, hi HistoricalInfo) []byte { +func MustMarshalHistoricalInfo(cdc codec.BinaryMarshaler, hi HistoricalInfo) []byte { return cdc.MustMarshalBinaryBare(&hi) } // MustUnmarshalHistoricalInfo wll unmarshal historical info and panic on error -func MustUnmarshalHistoricalInfo(cdc codec.Marshaler, value []byte) HistoricalInfo { +func MustUnmarshalHistoricalInfo(cdc codec.BinaryMarshaler, value []byte) HistoricalInfo { hi, err := UnmarshalHistoricalInfo(cdc, value) if err != nil { panic(err) @@ -36,7 +36,7 @@ func MustUnmarshalHistoricalInfo(cdc codec.Marshaler, value []byte) HistoricalIn } // UnmarshalHistoricalInfo will unmarshal historical info and return any error -func UnmarshalHistoricalInfo(cdc codec.Marshaler, value []byte) (hi HistoricalInfo, err error) { +func UnmarshalHistoricalInfo(cdc codec.BinaryMarshaler, value []byte) (hi HistoricalInfo, err error) { err = cdc.UnmarshalBinaryBare(value, &hi) return hi, err diff --git a/x/staking/types/validator.go b/x/staking/types/validator.go index de1adaa49b3e..b18d3eb2ecd9 100644 --- a/x/staking/types/validator.go +++ b/x/staking/types/validator.go @@ -109,12 +109,12 @@ func (v Validators) Swap(i, j int) { } // return the redelegation -func MustMarshalValidator(cdc codec.Marshaler, validator Validator) []byte { +func MustMarshalValidator(cdc codec.BinaryMarshaler, validator Validator) []byte { return cdc.MustMarshalBinaryBare(&validator) } // unmarshal a redelegation from a store value -func MustUnmarshalValidator(cdc codec.Marshaler, value []byte) Validator { +func MustUnmarshalValidator(cdc codec.BinaryMarshaler, value []byte) Validator { validator, err := UnmarshalValidator(cdc, value) if err != nil { panic(err) @@ -124,7 +124,7 @@ func MustUnmarshalValidator(cdc codec.Marshaler, value []byte) Validator { } // unmarshal a redelegation from a store value -func UnmarshalValidator(cdc codec.Marshaler, value []byte) (v Validator, err error) { +func UnmarshalValidator(cdc codec.BinaryMarshaler, value []byte) (v Validator, err error) { err = cdc.UnmarshalBinaryBare(value, &v) return v, err } From 5dfaff9383f09fc6733748576056bf9d4638cb2b Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sat, 25 Jul 2020 05:25:24 +0530 Subject: [PATCH 8/9] remove evidence json marshaling --- x/evidence/keeper/keeper.go | 33 ---------------------------- x/ibc/03-connection/keeper/keeper.go | 4 ++-- x/staking/keeper/querier_test.go | 3 ++- 3 files changed, 4 insertions(+), 36 deletions(-) diff --git a/x/evidence/keeper/keeper.go b/x/evidence/keeper/keeper.go index e0239bba307c..e15cd74c8a07 100644 --- a/x/evidence/keeper/keeper.go +++ b/x/evidence/keeper/keeper.go @@ -3,12 +3,10 @@ package keeper import ( "fmt" - "github.com/gogo/protobuf/proto" tmbytes "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -187,34 +185,3 @@ func (k Keeper) UnmarshalEvidence(bz []byte) (exported.Evidence, error) { return evi, nil } - -// MarshalEvidenceJSON JSON encodes an evidence object implementing the Evidence -// interface. -func (k Keeper) MarshalEvidenceJSON(evidence exported.Evidence) ([]byte, error) { - msg, ok := evidence.(proto.Message) - if !ok { - return nil, fmt.Errorf("cannot proto marshal %T", evidence) - } - - any, err := codectypes.NewAnyWithValue(msg) - if err != nil { - return nil, err - } - - return k.cdc.MarshalBinaryBare(any) -} - -// UnmarshalEvidenceJSON returns an Evidence from JSON encoded bytes -func (k Keeper) UnmarshalEvidenceJSON(bz []byte) (exported.Evidence, error) { - var any codectypes.Any - if err := k.cdc.UnmarshalBinaryBare(bz, &any); err != nil { - return nil, err - } - - var evi exported.Evidence - if err := k.cdc.UnpackAny(&any, &evi); err != nil { - return nil, err - } - - return evi, nil -} diff --git a/x/ibc/03-connection/keeper/keeper.go b/x/ibc/03-connection/keeper/keeper.go index 50614012efc7..1c709f83daab 100644 --- a/x/ibc/03-connection/keeper/keeper.go +++ b/x/ibc/03-connection/keeper/keeper.go @@ -22,8 +22,8 @@ type Keeper struct { types.QueryServer storeKey sdk.StoreKey - aminoCdc *codec.Codec // amino codec. TODO: remove after clients have been migrated to proto - cdc codec.BinaryMarshaler // hybrid codec + aminoCdc *codec.Codec // amino codec. TODO: remove after clients have been migrated to proto + cdc codec.BinaryMarshaler clientKeeper types.ClientKeeper } diff --git a/x/staking/keeper/querier_test.go b/x/staking/keeper/querier_test.go index dcf772d2812b..165589224673 100644 --- a/x/staking/keeper/querier_test.go +++ b/x/staking/keeper/querier_test.go @@ -2,9 +2,10 @@ package keeper_test import ( "fmt" - "github.com/cosmos/cosmos-sdk/codec" "testing" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" From fa49ca76f452f9f4b25ef536105b7f89e54f5b5f Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 24 Jul 2020 20:39:27 -0400 Subject: [PATCH 9/9] Fix tests --- x/auth/keeper/querier_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/auth/keeper/querier_test.go b/x/auth/keeper/querier_test.go index 659f6479bf35..b39d58afd0c1 100644 --- a/x/auth/keeper/querier_test.go +++ b/x/auth/keeper/querier_test.go @@ -39,13 +39,13 @@ func TestQueryAccount(t *testing.T) { require.Error(t, err) require.Nil(t, res) - req.Data = jsonCdc.MustMarshalJSON(types.QueryAccountRequest{Address: []byte("")}) + req.Data = legacyQuerierCdc.MustMarshalJSON(types.QueryAccountRequest{Address: []byte("")}) res, err = querier(ctx, path, req) require.Error(t, err) require.Nil(t, res) _, _, addr := testdata.KeyTestPubAddr() - req.Data = jsonCdc.MustMarshalJSON(types.QueryAccountRequest{Address: addr}) + req.Data = legacyQuerierCdc.MustMarshalJSON(types.QueryAccountRequest{Address: addr}) res, err = querier(ctx, path, req) require.Error(t, err) require.Nil(t, res) @@ -60,6 +60,6 @@ func TestQueryAccount(t *testing.T) { require.NotNil(t, res) var account types.AccountI - err2 := jsonCdc.UnmarshalJSON(res, &account) + err2 := legacyQuerierCdc.UnmarshalJSON(res, &account) require.Nil(t, err2) }