Skip to content

Commit

Permalink
appmodule & simapp cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Sep 8, 2024
1 parent 5a331ed commit 6d49de2
Show file tree
Hide file tree
Showing 19 changed files with 538 additions and 746 deletions.
37 changes: 15 additions & 22 deletions modules/apps/27-interchain-accounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

var (
_ module.AppModule = (*AppModule)(nil)
_ module.AppModuleBasic = (*AppModuleBasic)(nil)
_ module.AppModuleBasic = (*AppModule)(nil)
_ module.AppModuleSimulation = (*AppModule)(nil)
_ module.HasGenesis = (*AppModule)(nil)
_ module.HasServices = (*AppModule)(nil)
Expand All @@ -42,13 +42,8 @@ var (
_ porttypes.IBCModule = (*host.IBCModule)(nil)
)

// AppModuleBasic is the IBC interchain accounts AppModuleBasic
type AppModuleBasic struct {
cdc codec.Codec
}

// Name implements AppModuleBasic interface
func (AppModuleBasic) Name() string {
func (AppModule) Name() string {
return types.ModuleName
}

Expand All @@ -58,24 +53,24 @@ func (AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (AppModule) IsAppModule() {}

// RegisterLegacyAminoCodec implements AppModuleBasic.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc registry.AminoRegistrar) {}
// RegisterLegacyAminoCodec implements AppModule.
func (AppModule) RegisterLegacyAminoCodec(cdc registry.AminoRegistrar) {}

// RegisterInterfaces registers module concrete types into protobuf Any
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
controllertypes.RegisterInterfaces(registry)
hosttypes.RegisterInterfaces(registry)
types.RegisterInterfaces(registry)
}

// DefaultGenesis returns default genesis state as raw bytes for the IBC
// interchain accounts module
func (am AppModuleBasic) DefaultGenesis() json.RawMessage {
func (am AppModule) DefaultGenesis() json.RawMessage {
return am.cdc.MustMarshalJSON(genesistypes.DefaultGenesis())
}

// ValidateGenesis performs genesis state validation for the IBC interchain accounts module
func (am AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
func (am AppModule) ValidateGenesis(bz json.RawMessage) error {
var gs genesistypes.GenesisState
if err := am.cdc.UnmarshalJSON(bz, &gs); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
Expand All @@ -85,7 +80,7 @@ func (am AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the interchain accounts module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
err := controllertypes.RegisterQueryHandlerClient(context.Background(), mux, controllertypes.NewQueryClient(clientCtx))
if err != nil {
panic(err)
Expand All @@ -97,29 +92,27 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r
}
}

// GetTxCmd implements AppModuleBasic interface
func (AppModuleBasic) GetTxCmd() *cobra.Command {
// GetTxCmd implements AppModule interface
func (AppModule) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}

// GetQueryCmd implements AppModuleBasic interface
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
// GetQueryCmd implements AppModule interface
func (AppModule) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}

// AppModule is the application module for the IBC interchain accounts module
type AppModule struct {
AppModuleBasic
cdc codec.Codec
controllerKeeper *controllerkeeper.Keeper
hostKeeper *hostkeeper.Keeper
}

// NewAppModule creates a new IBC interchain accounts module
func NewAppModule(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkeeper.Keeper) AppModule {
func NewAppModule(cdc codec.Codec, controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkeeper.Keeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{
cdc: nil,
},
cdc: cdc,
controllerKeeper: controllerKeeper,
hostKeeper: hostKeeper,
}
Expand Down
32 changes: 14 additions & 18 deletions modules/apps/29-fee/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@ var (
_ appmodule.AppModule = (*AppModule)(nil)
)

// AppModuleBasic is the 29-fee AppModuleBasic
type AppModuleBasic struct {
cdc codec.Codec
}

// Name implements AppModuleBasic interface
func (AppModuleBasic) Name() string {
func (AppModule) Name() string {
return types.ModuleName
}

Expand All @@ -46,24 +41,24 @@ func (AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (AppModule) IsAppModule() {}

// RegisterLegacyAminoCodec implements AppModuleBasic interface
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
// RegisterLegacyAminoCodec implements AppModule interface
func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}

// RegisterInterfaces registers module concrete types into protobuf Any.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}

// DefaultGenesis returns default genesis state as raw bytes for the ibc
// 29-fee module.
func (am AppModuleBasic) DefaultGenesis() json.RawMessage {
func (am AppModule) DefaultGenesis() json.RawMessage {
return am.cdc.MustMarshalJSON(types.DefaultGenesisState())
}

// ValidateGenesis performs genesis state validation for the 29-fee module.
func (am AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
func (am AppModule) ValidateGenesis(bz json.RawMessage) error {
var gs types.GenesisState
if err := am.cdc.UnmarshalJSON(bz, &gs); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
Expand All @@ -73,32 +68,33 @@ func (am AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for ics29 fee module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err != nil {
panic(err)
}
}

// GetTxCmd implements AppModuleBasic interface
func (AppModuleBasic) GetTxCmd() *cobra.Command {
// GetTxCmd implements AppModule interface
func (AppModule) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}

// GetQueryCmd implements AppModuleBasic interface
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
// GetQueryCmd implements AppModule interface
func (AppModule) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}

// AppModule represents the AppModule for this module
type AppModule struct {
AppModuleBasic
cdc codec.Codec
keeper keeper.Keeper
}

// NewAppModule creates a new 29-fee module
func NewAppModule(k keeper.Keeper) AppModule {
func NewAppModule(cdc codec.Codec, k keeper.Keeper) AppModule {
return AppModule{
cdc: cdc,
keeper: k,
}
}
Expand Down
20 changes: 2 additions & 18 deletions modules/apps/callbacks/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"

Expand Down Expand Up @@ -184,7 +181,6 @@ type SimApp struct {
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper *crisiskeeper.Keeper
UpgradeKeeper *upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
AuthzKeeper authzkeeper.Keeper
Expand Down Expand Up @@ -296,7 +292,7 @@ func NewSimApp(
bApp.SetTxEncoder(txConfig.TxEncoder())

keys := storetypes.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, crisistypes.StoreKey,
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, group.StoreKey, paramstypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, icacontrollertypes.StoreKey, icahosttypes.StoreKey, capabilitytypes.StoreKey,
Expand Down Expand Up @@ -371,10 +367,6 @@ func NewSimApp(
appCodec, legacyAmino, runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), app.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod))
app.CrisisKeeper = crisiskeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[crisistypes.StoreKey]), invCheckPeriod,
app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AccountKeeper.AddressCodec())

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[feegrant.StoreKey]), app.AccountKeeper)

// register the staking hooks
Expand Down Expand Up @@ -586,10 +578,6 @@ func NewSimApp(

// **** Module Options ****

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
// we prefer to be more strict in what arguments the modules expect.
skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants))

// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
app.ModuleManager = module.NewManager(
Expand All @@ -601,7 +589,6 @@ func NewSimApp(
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)),
Expand Down Expand Up @@ -671,7 +658,6 @@ func NewSimApp(
ibcmock.ModuleName,
)
app.ModuleManager.SetOrderEndBlockers(
crisistypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
ibcexported.ModuleName,
Expand All @@ -695,7 +681,7 @@ func NewSimApp(
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName,
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName,
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName,
ibcexported.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, ibctransfertypes.ModuleName,
icatypes.ModuleName, ibcfeetypes.ModuleName, ibcmock.ModuleName, feegrant.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName,
vestingtypes.ModuleName, group.ModuleName, consensusparamtypes.ModuleName, circuittypes.ModuleName,
Expand All @@ -705,8 +691,6 @@ func NewSimApp(

// Uncomment if you want to set a custom migration order here.
// app.ModuleManager.SetOrderMigrations(custom order)

app.ModuleManager.RegisterInvariants(app.CrisisKeeper)
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
err := app.ModuleManager.RegisterServices(app.configurator)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions modules/apps/callbacks/testing/simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/tx"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
"github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"

cmtcfg "github.com/cometbft/cometbft/config"
Expand Down Expand Up @@ -214,7 +213,6 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, b
}

func addModuleInitFlags(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
}

func queryCommand() *cobra.Command {
Expand Down
34 changes: 15 additions & 19 deletions modules/apps/transfer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

var (
_ module.AppModule = (*AppModule)(nil)
_ module.AppModuleBasic = (*AppModuleBasic)(nil)
_ module.AppModuleBasic = (*AppModule)(nil)
_ module.AppModuleSimulation = (*AppModule)(nil)
_ module.HasGenesis = (*AppModule)(nil)
_ appmodule.HasConsensusVersion = (*AppModule)(nil)
Expand All @@ -39,13 +39,8 @@ var (
_ porttypes.IBCModule = (*IBCModule)(nil)
)

// AppModuleBasic is the IBC Transfer AppModuleBasic
type AppModuleBasic struct {
cdc codec.Codec
}

// Name implements AppModuleBasic interface
func (AppModuleBasic) Name() string {
func (AppModule) Name() string {
return types.ModuleName
}

Expand All @@ -55,24 +50,24 @@ func (AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (AppModule) IsAppModule() {}

// RegisterLegacyAminoCodec implements AppModuleBasic interface
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc registry.AminoRegistrar) {
// RegisterLegacyAminoCodec implements AppModule interface
func (AppModule) RegisterLegacyAminoCodec(cdc registry.AminoRegistrar) {
types.RegisterLegacyAminoCodec(cdc)
}

// RegisterInterfaces registers module concrete types into protobuf Any.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}

// DefaultGenesis returns default genesis state as raw bytes for the ibc
// transfer module.
func (am AppModuleBasic) DefaultGenesis() json.RawMessage {
func (am AppModule) DefaultGenesis() json.RawMessage {
return am.cdc.MustMarshalJSON(types.DefaultGenesisState())
}

// ValidateGenesis performs genesis state validation for the ibc transfer module.
func (am AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
func (am AppModule) ValidateGenesis(bz json.RawMessage) error {
var gs types.GenesisState
if err := am.cdc.UnmarshalJSON(bz, &gs); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
Expand All @@ -82,7 +77,7 @@ func (am AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the ibc-transfer module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
Expand All @@ -92,25 +87,26 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r
}
}

// GetTxCmd implements AppModuleBasic interface
func (AppModuleBasic) GetTxCmd() *cobra.Command {
// GetTxCmd implements AppModule interface
func (AppModule) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}

// GetQueryCmd implements AppModuleBasic interface
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
// GetQueryCmd implements AppModule interface
func (AppModule) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}

// AppModule represents the AppModule for this module
type AppModule struct {
AppModuleBasic
cdc codec.Codec
keeper keeper.Keeper
}

// NewAppModule creates a new 20-transfer module
func NewAppModule(k keeper.Keeper) AppModule {
func NewAppModule(cdc codec.Codec, k keeper.Keeper) AppModule {
return AppModule{
cdc: cdc,
keeper: k,
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/light-clients/07-tendermint/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestCodecTypeRegistration(t *testing.T) {
tc := tc

t.Run(tc.name, func(t *testing.T) {
encodingCfg := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, tendermint.AppModuleBasic{})
encodingCfg := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, tendermint.AppModule{})
msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL)

if tc.expPass {
Expand Down
Loading

0 comments on commit 6d49de2

Please sign in to comment.