From ba737f1c554dda2bf18c8c772663fbf36ac63b64 Mon Sep 17 00:00:00 2001 From: orngefrost Date: Sun, 18 Oct 2020 23:30:50 +0900 Subject: [PATCH] fix(x/gamm): resolve red-army --- x/gamm/module.go | 27 ++++++++------------------ x/gamm/types/codec.go | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 19 deletions(-) create mode 100644 x/gamm/types/codec.go diff --git a/x/gamm/module.go b/x/gamm/module.go index f36e728a026..3ad6be28bd9 100644 --- a/x/gamm/module.go +++ b/x/gamm/module.go @@ -2,7 +2,6 @@ package gamm import ( "encoding/json" - "fmt" "math/rand" "github.com/cosmos/cosmos-sdk/client" @@ -44,17 +43,12 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { // DefaultGenesis returns default genesis state as raw bytes for the bank // module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) + return nil } // ValidateGenesis performs genesis state validation for the bank module. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config client.TxEncodingConfig, bz json.RawMessage) error { - var data types.GenesisState - if err := cdc.UnmarshalJSON(bz, &data); err != nil { - return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) - } - - return types.ValidateGenesis(data) + return nil } //--------------------------------------- @@ -87,7 +81,7 @@ type AppModule struct { } func (am AppModule) RegisterQueryService(server grpc.Server) { - types.RegisterQueryServer(server, am.keeper) + return } func NewAppModule(cdc codec.Marshaler, keeper keeper.Keeper) AppModule { @@ -99,7 +93,7 @@ func NewAppModule(cdc codec.Marshaler, keeper keeper.Keeper) AppModule { // RegisterInvariants registers the bank module invariants. func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { - keeper.RegisterInvariants(ir, am.keeper) + return } // Route returns the message routing key for the bank module. @@ -112,24 +106,19 @@ func (AppModule) QuerierRoute() string { return types.RouterKey } // LegacyQuerierHandler returns the bank module sdk.Querier. func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { - return keeper.NewQuerier(am.keeper, legacyQuerierCdc) + return nil } // InitGenesis performs genesis initialization for the bank module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState types.GenesisState - - cdc.MustUnmarshalJSON(data, &genesisState) - am.keeper.InitGenesis(ctx, genesisState) - return []abci.ValidatorUpdate{} + return nil } // ExportGenesis returns the exported genesis state as raw bytes for the bank // module. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { - gs := am.keeper.ExportGenesis(ctx) - return cdc.MustMarshalJSON(gs) + return nil } // BeginBlock performs a no-op. @@ -162,7 +151,7 @@ func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { // RegisterStoreDecoder registers a decoder for supply module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { - sdr[types.StoreKey] = simulation.NewDecodeStore(am.keeper) + return } // WeightedOperations returns the all the gov module operations with their respective weights. diff --git a/x/gamm/types/codec.go b/x/gamm/types/codec.go new file mode 100644 index 00000000000..bb15e0abffe --- /dev/null +++ b/x/gamm/types/codec.go @@ -0,0 +1,45 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// RegisterLegacyAminoCodec registers the necessary x/bank interfaces and concrete types +// on the provided LegacyAmino codec. These types are used for Amino JSON serialization. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgCreatePool{}, "osmosis/gamm/create-pool", nil) + cdc.RegisterConcrete(&MsgJoinPool{}, "osmosis/gamm/join-pool", nil) + cdc.RegisterConcrete(&MsgExitPool{}, "osmosis/gamm/exit-pool", nil) + cdc.RegisterConcrete(&MsgSwapExactAmountIn{}, "osmosis/gamm/swap-exact-amount-in", nil) + cdc.RegisterConcrete(&MsgSwapExactAmountOut{}, "osmosis/gamm/swap-exact-amount-out", nil) +} + +func RegisterInterfaces(registry types.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgCreatePool{}, + &MsgJoinPool{}, + &MsgExitPool{}, + &MsgSwapExactAmountIn{}, + &MsgSwapExactAmountOut{}, + ) +} + +var ( + amino = codec.NewLegacyAmino() + + // ModuleCdc references the global x/bank module codec. Note, the codec should + // ONLY be used in certain instances of tests and for JSON encoding as Amino is + // still used for that purpose. + // + // The actual codec used for serialization should be provided to x/staking and + // defined at the application level. + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + amino.Seal() +}