Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(x/gamm): resolve red-army #7

Merged
merged 1 commit into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions x/gamm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gamm

import (
"encoding/json"
"fmt"
"math/rand"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -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
}

//---------------------------------------
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
45 changes: 45 additions & 0 deletions x/gamm/types/codec.go
Original file line number Diff line number Diff line change
@@ -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()
}