From 3bafd8255a502e5a9cee07391cf8261538245dfd Mon Sep 17 00:00:00 2001 From: Anil Kumar Kammari Date: Sat, 25 Jul 2020 13:33:58 +0530 Subject: [PATCH] Remove hybrid codec usage (#6843) * remove hybrid codec for slashing, staking and upgrade * Remove hybridcodec from params and mint * revert staking * Fix gov * Fix ibc and evidence * Fix ibc-transfer * Fix staking * remove evidence json marshaling * Fix tests Co-authored-by: Aaron Craelius Co-authored-by: Aaron Craelius Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> --- x/auth/keeper/querier.go | 16 ++-- x/auth/keeper/querier_test.go | 10 +- x/auth/module.go | 4 +- x/bank/keeper/querier.go | 34 +++---- x/bank/keeper/querier_test.go | 20 ++-- x/bank/module.go | 4 +- x/capability/keeper/keeper.go | 6 +- x/distribution/keeper/querier.go | 68 ++++++------- x/distribution/keeper/querier_test.go | 4 +- x/distribution/module.go | 4 +- x/evidence/keeper/keeper.go | 37 +------- x/evidence/keeper/keeper_test.go | 5 +- x/evidence/keeper/querier.go | 18 ++-- x/evidence/module.go | 4 +- x/gov/keeper/keeper.go | 4 +- x/gov/keeper/querier.go | 68 ++++++------- x/gov/keeper/querier_test.go | 7 +- x/gov/module.go | 4 +- x/ibc-transfer/keeper/keeper.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/03-connection/simulation/decoder.go | 2 +- x/ibc/04-channel/keeper/keeper.go | 4 +- x/ibc/04-channel/keeper/querier.go | 6 +- x/ibc/04-channel/simulation/decoder.go | 2 +- x/ibc/07-tendermint/types/client_state.go | 16 ++-- x/ibc/09-localhost/types/client_state.go | 14 +-- x/ibc/keeper/keeper.go | 6 +- x/ibc/keeper/keeper_test.go | 3 +- x/ibc/keeper/querier.go | 8 +- x/ibc/module.go | 4 +- x/ibc/simulation/decoder.go | 2 +- x/ibc/testing/chain.go | 5 +- x/mint/keeper/keeper.go | 4 +- x/mint/keeper/querier.go | 20 ++-- x/mint/keeper/querier_test.go | 14 ++- x/mint/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 | 26 +++-- x/staking/module.go | 4 +- x/staking/types/delegation.go | 18 ++-- x/staking/types/historical_info.go | 6 +- x/staking/types/validator.go | 6 +- x/upgrade/keeper/keeper.go | 4 +- x/upgrade/keeper/querier.go | 16 ++-- x/upgrade/module.go | 4 +- 54 files changed, 354 insertions(+), 359 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/keeper/querier_test.go b/x/auth/keeper/querier_test.go index 890f71b43241..b39d58afd0c1 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) @@ -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) } 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..8acc5a3c5a31 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(legacyQuerierCdc, 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/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/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/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/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/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/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/evidence/keeper/keeper.go b/x/evidence/keeper/keeper.go index ce629ff0bc4d..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" @@ -20,7 +18,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 +26,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 { @@ -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.MarshalJSON(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 { - 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/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/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 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/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..1c709f83daab 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 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/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/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/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/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/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/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/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 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/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..7ed384178032 100644 --- a/x/mint/keeper/querier_test.go +++ b/x/mint/keeper/querier_test.go @@ -3,6 +3,8 @@ package keeper_test import ( "testing" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" @@ -14,7 +16,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 +39,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 +55,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 +71,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/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..662adea4a356 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..165589224673 100644 --- a/x/staking/keeper/querier_test.go +++ b/x/staking/keeper/querier_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -43,7 +45,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 +110,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 +137,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 +205,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 +454,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 +539,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 +611,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 +707,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 } 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..9d0fffa650c0 100644 --- a/x/upgrade/keeper/querier.go +++ b/x/upgrade/keeper/querier.go @@ -3,6 +3,8 @@ package keeper import ( "encoding/binary" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" abci "github.com/tendermint/tendermint/abci/types" @@ -12,15 +14,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 +30,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 +44,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