chore(wip): update module definition in module.go

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2024-11-28 11:25:01 +01:00
parent 8a8f35e9ad
commit 1d89241599
No known key found for this signature in database
GPG Key ID: FA5EE906EB55316A
4 changed files with 60 additions and 46 deletions

View File

@ -552,7 +552,7 @@ func New(
authtypes.NewModuleAddress(govtypes.ModuleName).String(), authtypes.NewModuleAddress(govtypes.ModuleName).String(),
homePath, homePath,
) )
machineModule := machinemodule.NewAppModule(appCodec, app.MachineKeeper, app.AccountKeeper, app.BankKeeper) machineModule := machinemodule.NewAppModule(appCodec, app.MachineKeeper, app.AccountKeeper, app.BankKeeper, interfaceRegistry)
app.AssetKeeper = *assetmodulekeeper.NewKeeper( app.AssetKeeper = *assetmodulekeeper.NewKeeper(
appCodec, appCodec,

View File

@ -11,10 +11,15 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
abci "github.com/cometbft/cometbft/abci/types" abci "github.com/cometbft/cometbft/abci/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types" cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/types/module"
"github.com/planetmint/planetmint-go/x/machine/client/cli" "github.com/planetmint/planetmint-go/x/machine/client/cli"
@ -27,6 +32,12 @@ var (
_ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleBasic = AppModuleBasic{}
) )
// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
func (am AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// AppModuleBasic // AppModuleBasic
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -96,6 +107,7 @@ type AppModule struct {
keeper keeper.Keeper keeper keeper.Keeper
accountKeeper types.AccountKeeper accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper bankKeeper types.BankKeeper
registry cdctypes.InterfaceRegistry
} }
func NewAppModule( func NewAppModule(
@ -103,12 +115,14 @@ func NewAppModule(
keeper keeper.Keeper, keeper keeper.Keeper,
accountKeeper types.AccountKeeper, accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper, bankKeeper types.BankKeeper,
registry cdctypes.InterfaceRegistry,
) AppModule { ) AppModule {
return AppModule{ return AppModule{
AppModuleBasic: NewAppModuleBasic(cdc), AppModuleBasic: NewAppModuleBasic(cdc),
keeper: keeper, keeper: keeper,
accountKeeper: accountKeeper, accountKeeper: accountKeeper,
bankKeeper: bankKeeper, bankKeeper: bankKeeper,
registry: registry,
} }
} }
@ -160,3 +174,47 @@ func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {
func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
return []abci.ValidatorUpdate{} return []abci.ValidatorUpdate{}
} }
//
// App Wiring Setup
//
func init() {
appmodule.Register(
&types.Module{},
appmodule.Provide(ProvideModule),
)
}
type MachineInputs struct {
depinject.In
Config *types.Module
Key *store.KVStoreKey
Cdc codec.Codec
AccountKeeper types.AccountKeeper
BankKeeper types.BankKeeper
Registry cdctypes.InterfaceRegistry
MsgServiceRouter *baseapp.MsgServiceRouter
storeKey store.StoreKey
taIndexStoreKey store.StoreKey
issuerPlanetmintIndexStoreKey store.StoreKey
issuerLiquidIndexStoreKey store.StoreKey
taStoreKey store.StoreKey
addressIndexStoreKey store.StoreKey
memKey store.StoreKey
paramstore paramtypes.Subspace
authority string
rootDir string
}
type MachineOutputs struct {
depinject.Out
MachineKeeper keeper.Keeper
Module appmodule.AppModule
}
func ProvideModule(in MachineInputs) MachineOutputs {
k := keeper.NewKeeper(in.Cdc, in.storeKey, in.taIndexStoreKey, in.issuerPlanetmintIndexStoreKey, in.issuerLiquidIndexStoreKey, in.taStoreKey, in.addressIndexStoreKey, in.memKey, in.paramstore, in.authority, in.rootDir)
m := NewAppModule(in.Cdc, *k, in.AccountKeeper, in.BankKeeper, in.Registry)
return MachineOutputs{MachineKeeper: *k, Module: m}
}

View File

@ -1,45 +0,0 @@
package module
// import (
// "cosmossdk.io/core/appmodule"
// "cosmossdk.io/depinject"
// "github.com/cosmos/cosmos-sdk/baseapp"
// "github.com/cosmos/cosmos-sdk/x/group"
// "github.com/gogo/protobuf/codec"
// "github.com/planetmint/planetmint-go/x/machine/keeper"
// modulev1 "github.com/planetmint/planetmint-go/x/machine/types"
// )
// func init() {
// appmodule.Register(
// &modulev1.Module{},
// appmodule.Provide(ProvideModule),
// )
// }
// type MachineInputs struct {
// depinject.In
// Config *modulev1.Module
// Key *store.KVStoreKey
// Cdc codec.Codec
// AccountKeeper machine.AccountKeeper
// BankKeeper machine.BankKeeper
// Registry cdctypes.InterfaceRegistry
// MsgServiceRouter *baseapp.MsgServiceRouter
// }
// type MachineOutputs struct {
// depinject.Out
// MachineKeeper keeper.Keeper
// Module appmodule.AppModule
// }
// func ProvideModule(in MachineInputs) MachineOutputs {
// /*
// Example of setting machine params:
// in.Config.MaxMetadataLen = 1000
// in.Config.MaxExecutionPeriod = "1209600s"
// */
// k := keeper.NewKeeper(in.Key, in.Cdc, in.MsgServiceRouter, in.AccountKeeper, group.Config{MaxExecutionPeriod: in.Config.MaxExecutionPeriod.AsDuration(), MaxMetadataLen: in.Config.MaxMetadataLen})
// m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.Registry)
// return MachineOutputs{MachineKeeper: k, Module: m}
// }

View File

@ -11,6 +11,7 @@ import (
_ "github.com/cosmos/cosmos-sdk/x/params" _ "github.com/cosmos/cosmos-sdk/x/params"
_ "github.com/cosmos/cosmos-sdk/x/slashing" _ "github.com/cosmos/cosmos-sdk/x/slashing"
_ "github.com/cosmos/cosmos-sdk/x/staking" _ "github.com/cosmos/cosmos-sdk/x/staking"
_ "github.com/planetmint/planetmint-go/x/machine"
"cosmossdk.io/core/appconfig" "cosmossdk.io/core/appconfig"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"