From f3a558c6b473d5205445105f8a7e641dd1c78f1e Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 10 Oct 2022 16:27:44 -0400 Subject: [PATCH] refactor!: require exported app wiring providers (#13292) --- baseapp/block_gas_test.go | 1 + runtime/module.go | 59 ++++++++++++++++++------------------- x/auth/module.go | 12 ++++---- x/auth/tx/module/module.go | 12 ++++---- x/auth/vesting/module.go | 12 ++++---- x/authz/module/module.go | 14 ++++----- x/bank/module.go | 21 ++++++------- x/capability/module.go | 17 ++++++----- x/crisis/module.go | 29 +++++++++++------- x/distribution/module.go | 19 ++++++------ x/evidence/module.go | 15 +++++----- x/feegrant/module/module.go | 13 ++++---- x/genutil/module.go | 8 ++--- x/gov/module.go | 20 ++++++------- x/group/module/module.go | 17 ++++++----- x/mint/module.go | 17 ++++++----- x/nft/module/module.go | 12 ++++---- x/params/module.go | 20 ++++++------- x/slashing/module.go | 21 ++++++------- x/staking/module.go | 16 +++++----- x/upgrade/module.go | 12 ++++---- 21 files changed, 190 insertions(+), 177 deletions(-) diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 47f2fbd351ce..f243dd027a07 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -13,6 +13,7 @@ import ( dbm "github.com/tendermint/tm-db" "cosmossdk.io/depinject" + baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" diff --git a/runtime/module.go b/runtime/module.go index 07ff9a430d73..b1bcf77256d6 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -8,6 +8,7 @@ import ( runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -23,29 +24,24 @@ type BaseAppOption func(*baseapp.BaseApp) // IsManyPerContainerType indicates that this is a depinject.ManyPerContainerType. func (b BaseAppOption) IsManyPerContainerType() {} -// appWrapper is used to pass around an instance of *App internally between -// runtime dependency inject providers that is partially constructed (no -// baseapp yet). -type appWrapper *App - func init() { appmodule.Register(&runtimev1alpha1.Module{}, appmodule.Provide( - provideCodecs, - provideAppBuilder, - provideKVStoreKey, - provideTransientStoreKey, - provideMemoryStoreKey, - provideDeliverTx, + ProvideCodecs, + ProvideKVStoreKey, + ProvideTransientStoreKey, + ProvideMemoryStoreKey, + ProvideDeliverTx, ), + appmodule.Invoke(SetupAppBuilder), ) } -func provideCodecs(moduleBasics map[string]AppModuleBasicWrapper) ( +func ProvideCodecs(moduleBasics map[string]AppModuleBasicWrapper) ( codectypes.InterfaceRegistry, codec.Codec, *codec.LegacyAmino, - appWrapper, + *AppBuilder, codec.ProtoCodecMarshaler, *baseapp.MsgServiceRouter, ) { @@ -64,13 +60,15 @@ func provideCodecs(moduleBasics map[string]AppModuleBasicWrapper) ( cdc := codec.NewProtoCodec(interfaceRegistry) msgServiceRouter := baseapp.NewMsgServiceRouter() - app := &App{ - storeKeys: nil, - interfaceRegistry: interfaceRegistry, - cdc: cdc, - amino: amino, - basicManager: basicManager, - msgServiceRouter: msgServiceRouter, + app := &AppBuilder{ + &App{ + storeKeys: nil, + interfaceRegistry: interfaceRegistry, + cdc: cdc, + amino: amino, + basicManager: basicManager, + msgServiceRouter: msgServiceRouter, + }, } return interfaceRegistry, cdc, amino, app, cdc, msgServiceRouter @@ -80,25 +78,24 @@ type appInputs struct { depinject.In Config *runtimev1alpha1.Module - App appWrapper + AppBuilder *AppBuilder Modules map[string]AppModuleWrapper BaseAppOptions []BaseAppOption } -func provideAppBuilder(inputs appInputs) *AppBuilder { +func SetupAppBuilder(inputs appInputs) { mm := &module.Manager{Modules: map[string]module.AppModule{}} for name, wrapper := range inputs.Modules { mm.Modules[name] = wrapper.AppModule } - app := inputs.App + app := inputs.AppBuilder.app app.baseAppOptions = inputs.BaseAppOptions app.config = inputs.Config app.ModuleManager = mm - return &AppBuilder{app: app} } -func registerStoreKey(wrapper appWrapper, key storetypes.StoreKey) { - wrapper.storeKeys = append(wrapper.storeKeys, key) +func registerStoreKey(wrapper *AppBuilder, key storetypes.StoreKey) { + wrapper.app.storeKeys = append(wrapper.app.storeKeys, key) } func storeKeyOverride(config *runtimev1alpha1.Module, moduleName string) *runtimev1alpha1.StoreKeyConfig { @@ -110,7 +107,7 @@ func storeKeyOverride(config *runtimev1alpha1.Module, moduleName string) *runtim return nil } -func provideKVStoreKey(config *runtimev1alpha1.Module, key depinject.ModuleKey, app appWrapper) *storetypes.KVStoreKey { +func ProvideKVStoreKey(config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder) *storetypes.KVStoreKey { override := storeKeyOverride(config, key.Name()) var storeKeyName string @@ -125,20 +122,20 @@ func provideKVStoreKey(config *runtimev1alpha1.Module, key depinject.ModuleKey, return storeKey } -func provideTransientStoreKey(key depinject.ModuleKey, app appWrapper) *storetypes.TransientStoreKey { +func ProvideTransientStoreKey(key depinject.ModuleKey, app *AppBuilder) *storetypes.TransientStoreKey { storeKey := storetypes.NewTransientStoreKey(fmt.Sprintf("transient:%s", key.Name())) registerStoreKey(app, storeKey) return storeKey } -func provideMemoryStoreKey(key depinject.ModuleKey, app appWrapper) *storetypes.MemoryStoreKey { +func ProvideMemoryStoreKey(key depinject.ModuleKey, app *AppBuilder) *storetypes.MemoryStoreKey { storeKey := storetypes.NewMemoryStoreKey(fmt.Sprintf("memory:%s", key.Name())) registerStoreKey(app, storeKey) return storeKey } -func provideDeliverTx(app appWrapper) func(abci.RequestDeliverTx) abci.ResponseDeliverTx { +func ProvideDeliverTx(appBuilder *AppBuilder) func(abci.RequestDeliverTx) abci.ResponseDeliverTx { return func(tx abci.RequestDeliverTx) abci.ResponseDeliverTx { - return app.BaseApp.DeliverTx(tx) + return appBuilder.app.BaseApp.DeliverTx(tx) } } diff --git a/x/auth/module.go b/x/auth/module.go index 35edb7b20971..bb23bfd7718e 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -184,15 +184,15 @@ func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.Weighte func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(provideModuleBasic, provideModule), + appmodule.Provide(ProvideModuleBasic, ProvideModule), ) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type authInputs struct { +type AuthInputs struct { depinject.In Config *modulev1.Module @@ -203,14 +203,14 @@ type authInputs struct { LegacySubspace exported.Subspace `optional:"true"` } -type authOutputs struct { +type AuthOutputs struct { depinject.Out AccountKeeper keeper.AccountKeeper Module runtime.AppModuleWrapper } -func provideModule(in authInputs) authOutputs { +func ProvideModule(in AuthInputs) AuthOutputs { maccPerms := map[string][]string{} for _, permission := range in.Config.ModuleAccountPermissions { maccPerms[permission.Account] = permission.Permissions @@ -219,5 +219,5 @@ func provideModule(in authInputs) authOutputs { k := keeper.NewAccountKeeper(in.Cdc, in.Key, types.ProtoBaseAccount, maccPerms, in.Config.Bech32Prefix, types.NewModuleAddress(govtypes.ModuleName).String()) m := NewAppModule(in.Cdc, k, simulation.RandomGenesisAccounts, in.LegacySubspace) - return authOutputs{AccountKeeper: k, Module: runtime.WrapAppModule(m)} + return AuthOutputs{AccountKeeper: k, Module: runtime.WrapAppModule(m)} } diff --git a/x/auth/tx/module/module.go b/x/auth/tx/module/module.go index b005d6cadc16..a051a3fb4c7b 100644 --- a/x/auth/tx/module/module.go +++ b/x/auth/tx/module/module.go @@ -20,11 +20,11 @@ import ( func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(provideModule), + appmodule.Provide(ProvideModule), ) } -type txInputs struct { +type TxInputs struct { depinject.In Config *modulev1.Module @@ -35,14 +35,14 @@ type txInputs struct { FeeGrantKeeper feegrantkeeper.Keeper `optional:"true"` } -type txOutputs struct { +type TxOutputs struct { depinject.Out TxConfig client.TxConfig BaseAppOption runtime.BaseAppOption } -func provideModule(in txInputs) txOutputs { +func ProvideModule(in TxInputs) TxOutputs { txConfig := tx.NewTxConfig(in.ProtoCodecMarshaler, tx.DefaultSignModes) baseAppOption := func(app *baseapp.BaseApp) { @@ -83,10 +83,10 @@ func provideModule(in txInputs) txOutputs { app.SetTxDecoder(txConfig.TxDecoder()) } - return txOutputs{TxConfig: txConfig, BaseAppOption: baseAppOption} + return TxOutputs{TxConfig: txConfig, BaseAppOption: baseAppOption} } -func newAnteHandler(txConfig client.TxConfig, in txInputs) (sdk.AnteHandler, error) { +func newAnteHandler(txConfig client.TxConfig, in TxInputs) (sdk.AnteHandler, error) { if in.BankKeeper == nil { return nil, fmt.Errorf("both AccountKeeper and BankKeeper are required") } diff --git a/x/auth/vesting/module.go b/x/auth/vesting/module.go index 0fb256467c7a..8dcb4a09ad59 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -116,29 +116,29 @@ func (AppModule) ConsensusVersion() uint64 { return 1 } func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(provideModuleBasic, provideModule), + appmodule.Provide(ProvideModuleBasic, ProvideModule), ) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type vestingInputs struct { +type VestingInputs struct { depinject.In AccountKeeper keeper.AccountKeeper BankKeeper types.BankKeeper } -type vestingOutputs struct { +type VestingOutputs struct { depinject.Out Module runtime.AppModuleWrapper } -func provideModule(in vestingInputs) vestingOutputs { +func ProvideModule(in VestingInputs) VestingOutputs { m := NewAppModule(in.AccountKeeper, in.BankKeeper) - return vestingOutputs{Module: runtime.WrapAppModule(m)} + return VestingOutputs{Module: runtime.WrapAppModule(m)} } diff --git a/x/authz/module/module.go b/x/authz/module/module.go index 9890fed910d2..5ec55203f8e8 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -159,17 +159,17 @@ func init() { appmodule.Register( &modulev1.Module{}, appmodule.Provide( - provideModuleBasic, - provideModule, + ProvideModuleBasic, + ProvideModule, ), ) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type authzInputs struct { +type AuthzInputs struct { depinject.In Key *store.KVStoreKey @@ -180,17 +180,17 @@ type authzInputs struct { MsgServiceRouter *baseapp.MsgServiceRouter } -type authzOutputs struct { +type AuthzOutputs struct { depinject.Out AuthzKeeper keeper.Keeper Module runtime.AppModuleWrapper } -func provideModule(in authzInputs) authzOutputs { +func ProvideModule(in AuthzInputs) AuthzOutputs { k := keeper.NewKeeper(in.Key, in.Cdc, in.MsgServiceRouter, in.AccountKeeper) m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.Registry) - return authzOutputs{AuthzKeeper: k, Module: runtime.WrapAppModule(m)} + return AuthzOutputs{AuthzKeeper: k, Module: runtime.WrapAppModule(m)} } // ____________________________________________________________________________ diff --git a/x/bank/module.go b/x/bank/module.go index 4884b75c5e27..bfb20c8cdc26 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -6,14 +6,15 @@ import ( "fmt" "time" - modulev1 "cosmossdk.io/api/cosmos/bank/module/v1" - "cosmossdk.io/core/appmodule" - "cosmossdk.io/depinject" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" "golang.org/x/exp/maps" + modulev1 "cosmossdk.io/api/cosmos/bank/module/v1" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -196,15 +197,15 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp func init() { appmodule.Register(&modulev1.Module{}, appmodule.Provide( - provideModuleBasic, - provideModule)) + ProvideModuleBasic, + ProvideModule)) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type bankInputs struct { +type BankInputs struct { depinject.In ModuleKey depinject.OwnModuleKey @@ -219,14 +220,14 @@ type bankInputs struct { LegacySubspace exported.Subspace `optional:"true"` } -type bankOutputs struct { +type BankOutputs struct { depinject.Out BankKeeper keeper.BaseKeeper Module runtime.AppModuleWrapper } -func provideModule(in bankInputs) bankOutputs { +func ProvideModule(in BankInputs) BankOutputs { // Configure blocked module accounts. // // Default behavior for blockedAddresses is to regard any module mentioned in @@ -258,5 +259,5 @@ func provideModule(in bankInputs) bankOutputs { ) m := NewAppModule(in.Cdc, bankKeeper, in.AccountKeeper, in.LegacySubspace) - return bankOutputs{BankKeeper: bankKeeper, Module: runtime.WrapAppModule(m)} + return BankOutputs{BankKeeper: bankKeeper, Module: runtime.WrapAppModule(m)} } diff --git a/x/capability/module.go b/x/capability/module.go index f37be6984a78..f0efce7d0075 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -5,10 +5,11 @@ import ( "fmt" "time" - "cosmossdk.io/core/appmodule" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" + "cosmossdk.io/core/appmodule" + abci "github.com/tendermint/tendermint/abci/types" modulev1 "cosmossdk.io/api/cosmos/capability/module/v1" @@ -175,16 +176,16 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp func init() { appmodule.Register(&modulev1.Module{}, appmodule.Provide( - provideModuleBasic, - provideModule, + ProvideModuleBasic, + ProvideModule, )) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type capabilityInputs struct { +type CapabilityInputs struct { depinject.In Config *modulev1.Module @@ -194,18 +195,18 @@ type capabilityInputs struct { Cdc codec.Codec } -type capabilityOutputs struct { +type CapabilityOutputs struct { depinject.Out CapabilityKeeper *keeper.Keeper Module runtime.AppModuleWrapper } -func provideModule(in capabilityInputs) capabilityOutputs { +func ProvideModule(in CapabilityInputs) CapabilityOutputs { k := keeper.NewKeeper(in.Cdc, in.KvStoreKey, in.MemStoreKey) m := NewAppModule(in.Cdc, *k, in.Config.SealKeeper) - return capabilityOutputs{ + return CapabilityOutputs{ CapabilityKeeper: k, Module: runtime.WrapAppModule(m), } diff --git a/x/crisis/module.go b/x/crisis/module.go index 0a0c2fe55824..c885b65cb201 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -5,14 +5,15 @@ import ( "fmt" "time" - modulev1 "cosmossdk.io/api/cosmos/crisis/module/v1" - "cosmossdk.io/core/appmodule" - "cosmossdk.io/depinject" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cast" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + modulev1 "cosmossdk.io/api/cosmos/crisis/module/v1" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -179,11 +180,11 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val func init() { appmodule.Register( &modulev1.Module{}, - appmodule.Provide(provideModuleBasic, provideModule), + appmodule.Provide(ProvideModuleBasic, ProvideModule), ) } -type crisisInputs struct { +type CrisisInputs struct { depinject.In ModuleKey depinject.OwnModuleKey @@ -199,19 +200,22 @@ type crisisInputs struct { LegacySubspace exported.Subspace } -type crisisOutputs struct { +type CrisisOutputs struct { depinject.Out Module runtime.AppModuleWrapper CrisisKeeper *keeper.Keeper } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -func provideModule(in crisisInputs) crisisOutputs { - invalidCheckPeriod := cast.ToUint(in.AppOpts.Get(server.FlagInvCheckPeriod)) +func ProvideModule(in CrisisInputs) CrisisOutputs { + var invalidCheckPeriod uint + if in.AppOpts != nil { + invalidCheckPeriod = cast.ToUint(in.AppOpts.Get(server.FlagInvCheckPeriod)) + } feeCollectorName := in.Config.FeeCollectorName if feeCollectorName == "" { @@ -233,9 +237,12 @@ func provideModule(in crisisInputs) crisisOutputs { authority.String(), ) - skipGenesisInvariants := cast.ToBool(in.AppOpts.Get(FlagSkipGenesisInvariants)) + var skipGenesisInvariants bool + if in.AppOpts != nil { + skipGenesisInvariants = cast.ToBool(in.AppOpts.Get(FlagSkipGenesisInvariants)) + } m := NewAppModule(k, skipGenesisInvariants, in.LegacySubspace) - return crisisOutputs{CrisisKeeper: k, Module: runtime.WrapAppModule(m)} + return CrisisOutputs{CrisisKeeper: k, Module: runtime.WrapAppModule(m)} } diff --git a/x/distribution/module.go b/x/distribution/module.go index 354e85de6a94..4c30e9caf0b6 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -5,13 +5,14 @@ import ( "encoding/json" "fmt" - modulev1 "cosmossdk.io/api/cosmos/distribution/module/v1" - "cosmossdk.io/core/appmodule" - "cosmossdk.io/depinject" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + modulev1 "cosmossdk.io/api/cosmos/distribution/module/v1" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/depinject" + sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -200,15 +201,15 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(provideModuleBasic, provideModule), + appmodule.Provide(ProvideModuleBasic, ProvideModule), ) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type distrInputs struct { +type DistrInputs struct { depinject.In ModuleKey depinject.OwnModuleKey @@ -225,7 +226,7 @@ type distrInputs struct { LegacySubspace exported.Subspace } -type distrOutputs struct { +type DistrOutputs struct { depinject.Out DistrKeeper keeper.Keeper @@ -233,7 +234,7 @@ type distrOutputs struct { Hooks staking.StakingHooksWrapper } -func provideModule(in distrInputs) distrOutputs { +func ProvideModule(in DistrInputs) DistrOutputs { feeCollectorName := in.Config.FeeCollectorName if feeCollectorName == "" { feeCollectorName = authtypes.FeeCollectorName @@ -257,7 +258,7 @@ func provideModule(in distrInputs) distrOutputs { m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.StakingKeeper, in.LegacySubspace) - return distrOutputs{ + return DistrOutputs{ DistrKeeper: k, Module: runtime.WrapAppModule(m), Hooks: staking.StakingHooksWrapper{StakingHooks: k.Hooks()}, diff --git a/x/evidence/module.go b/x/evidence/module.go index 083a29217072..8897c20f5070 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -5,11 +5,12 @@ import ( "encoding/json" "fmt" - "cosmossdk.io/core/appmodule" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/depinject" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -189,15 +190,15 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(provideModuleBasic, provideModule), + appmodule.Provide(ProvideModuleBasic, ProvideModule), ) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type evidenceInputs struct { +type EvidenceInputs struct { depinject.In Key *store.KVStoreKey @@ -207,16 +208,16 @@ type evidenceInputs struct { SlashingKeeper types.SlashingKeeper } -type evidenceOutputs struct { +type EvidenceOutputs struct { depinject.Out EvidenceKeeper keeper.Keeper Module runtime.AppModuleWrapper } -func provideModule(in evidenceInputs) evidenceOutputs { +func ProvideModule(in EvidenceInputs) EvidenceOutputs { k := keeper.NewKeeper(in.Cdc, in.Key, in.StakingKeeper, in.SlashingKeeper) m := NewAppModule(*k) - return evidenceOutputs{EvidenceKeeper: *k, Module: runtime.WrapAppModule(m)} + return EvidenceOutputs{EvidenceKeeper: *k, Module: runtime.WrapAppModule(m)} } diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 6e1ed2e2fbb7..081134f34b25 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -4,11 +4,12 @@ import ( "context" "encoding/json" - "cosmossdk.io/core/appmodule" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + "cosmossdk.io/core/appmodule" + modulev1 "cosmossdk.io/api/cosmos/feegrant/module/v1" "cosmossdk.io/depinject" @@ -171,16 +172,16 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val func init() { appmodule.Register(&modulev1.Module{}, appmodule.Provide( - provideModuleBasic, - provideModule, + ProvideModuleBasic, + ProvideModule, )) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type feegrantInputs struct { +type FeegrantInputs struct { depinject.In Key *store.KVStoreKey @@ -190,7 +191,7 @@ type feegrantInputs struct { Registry cdctypes.InterfaceRegistry } -func provideModule(in feegrantInputs) (keeper.Keeper, runtime.AppModuleWrapper) { +func ProvideModule(in FeegrantInputs) (keeper.Keeper, runtime.AppModuleWrapper) { k := keeper.NewKeeper(in.Cdc, in.Key, in.AccountKeeper) m := NewAppModule(in.Cdc, in.AccountKeeper, in.BankKeeper, k, in.Registry) return k, runtime.WrapAppModule(m) diff --git a/x/genutil/module.go b/x/genutil/module.go index 1bcf702fd4bf..4fea22ca52c3 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -120,15 +120,15 @@ func (AppModule) ConsensusVersion() uint64 { return 1 } func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(provideModuleBasic, provideModule), + appmodule.Provide(ProvideModuleBasic, ProvideModule), ) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type genutilInputs struct { +type GenutilInputs struct { depinject.In AccountKeeper types.AccountKeeper @@ -137,7 +137,7 @@ type genutilInputs struct { Config client.TxConfig } -func provideModule(in genutilInputs) runtime.AppModuleWrapper { +func ProvideModule(in GenutilInputs) runtime.AppModuleWrapper { m := NewAppModule(in.AccountKeeper, in.StakingKeeper, in.DeliverTx, in.Config) return runtime.WrapAppModule(m) } diff --git a/x/gov/module.go b/x/gov/module.go index c984611f2249..754a7734e6a6 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -150,15 +150,15 @@ func NewAppModule( func init() { appmodule.Register( &modulev1.Module{}, - appmodule.Provide(provideModuleBasic, provideModule, provideKeyTable), - appmodule.Invoke(invokeAddRoutes, invokeSetHooks)) + appmodule.Provide(ProvideModuleBasic, ProvideModule, ProvideKeyTable), + appmodule.Invoke(InvokeAddRoutes, InvokeSetHooks)) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type govInputs struct { +type GovInputs struct { depinject.In Config *modulev1.Module @@ -176,7 +176,7 @@ type govInputs struct { LegacySubspace govtypes.ParamSubspace } -type govOutputs struct { +type GovOutputs struct { depinject.Out Module runtime.AppModuleWrapper @@ -184,7 +184,7 @@ type govOutputs struct { HandlerRoute v1beta1.HandlerRoute } -func provideModule(in govInputs) govOutputs { +func ProvideModule(in GovInputs) GovOutputs { kConfig := govtypes.DefaultConfig() if in.Config.MaxMetadataLen != 0 { kConfig.MaxMetadataLen = in.Config.MaxMetadataLen @@ -208,14 +208,14 @@ func provideModule(in govInputs) govOutputs { m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.LegacySubspace) hr := v1beta1.HandlerRoute{Handler: v1beta1.ProposalHandler, RouteKey: govtypes.RouterKey} - return govOutputs{Module: runtime.WrapAppModule(m), Keeper: k, HandlerRoute: hr} + return GovOutputs{Module: runtime.WrapAppModule(m), Keeper: k, HandlerRoute: hr} } -func provideKeyTable() paramtypes.KeyTable { +func ProvideKeyTable() paramtypes.KeyTable { return v1.ParamKeyTable() } -func invokeAddRoutes(keeper *keeper.Keeper, routes []v1beta1.HandlerRoute) { +func InvokeAddRoutes(keeper *keeper.Keeper, routes []v1beta1.HandlerRoute) { if keeper == nil || routes == nil { return } @@ -233,7 +233,7 @@ func invokeAddRoutes(keeper *keeper.Keeper, routes []v1beta1.HandlerRoute) { keeper.SetLegacyRouter(router) } -func invokeSetHooks(keeper *keeper.Keeper, govHooks map[string]govtypes.GovHooksWrapper) error { +func InvokeSetHooks(keeper *keeper.Keeper, govHooks map[string]govtypes.GovHooksWrapper) error { if keeper == nil || govHooks == nil { return nil } diff --git a/x/group/module/module.go b/x/group/module/module.go index 1b0bfb0c6ca0..1679bfa9d781 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -5,11 +5,12 @@ import ( "encoding/json" "fmt" - "cosmossdk.io/core/appmodule" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + "cosmossdk.io/core/appmodule" + modulev1 "cosmossdk.io/api/cosmos/group/module/v1" "cosmossdk.io/depinject" "github.com/cosmos/cosmos-sdk/baseapp" @@ -149,17 +150,17 @@ func init() { appmodule.Register( &modulev1.Module{}, appmodule.Provide( - provideModuleBasic, - provideModule, + ProvideModuleBasic, + ProvideModule, ), ) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type groupInputs struct { +type GroupInputs struct { depinject.In Config *modulev1.Module @@ -171,14 +172,14 @@ type groupInputs struct { MsgServiceRouter *baseapp.MsgServiceRouter } -type groupOutputs struct { +type GroupOutputs struct { depinject.Out GroupKeeper keeper.Keeper Module runtime.AppModuleWrapper } -func provideModule(in groupInputs) groupOutputs { +func ProvideModule(in GroupInputs) GroupOutputs { /* Example of setting group params: in.Config.MaxMetadataLen = 1000 @@ -187,7 +188,7 @@ func provideModule(in groupInputs) groupOutputs { 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 groupOutputs{GroupKeeper: k, Module: runtime.WrapAppModule(m)} + return GroupOutputs{GroupKeeper: k, Module: runtime.WrapAppModule(m)} } // ____________________________________________________________________________ diff --git a/x/mint/module.go b/x/mint/module.go index ef013161427a..e586e699b01e 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -5,12 +5,13 @@ import ( "encoding/json" "fmt" - modulev1 "cosmossdk.io/api/cosmos/mint/module/v1" - "cosmossdk.io/core/appmodule" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + modulev1 "cosmossdk.io/api/cosmos/mint/module/v1" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/depinject" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -202,15 +203,15 @@ func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.Weighte func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(provideModuleBasic, provideModule), + appmodule.Provide(ProvideModuleBasic, ProvideModule), ) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type mintInputs struct { +type MintInputs struct { depinject.In ModuleKey depinject.OwnModuleKey @@ -228,14 +229,14 @@ type mintInputs struct { StakingKeeper types.StakingKeeper } -type mintOutputs struct { +type MintOutputs struct { depinject.Out MintKeeper keeper.Keeper Module runtime.AppModuleWrapper } -func provideModule(in mintInputs) mintOutputs { +func ProvideModule(in MintInputs) MintOutputs { feeCollectorName := in.Config.FeeCollectorName if feeCollectorName == "" { feeCollectorName = authtypes.FeeCollectorName @@ -260,5 +261,5 @@ func provideModule(in mintInputs) mintOutputs { // when no inflation calculation function is provided it will use the default types.DefaultInflationCalculationFn m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.InflationCalculationFn, in.LegacySubspace) - return mintOutputs{MintKeeper: k, Module: runtime.WrapAppModule(m)} + return MintOutputs{MintKeeper: k, Module: runtime.WrapAppModule(m)} } diff --git a/x/nft/module/module.go b/x/nft/module/module.go index c03b535ed227..247de946df92 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -178,15 +178,15 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(provideModuleBasic, provideModule), + appmodule.Provide(ProvideModuleBasic, ProvideModule), ) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type nftInputs struct { +type NftInputs struct { depinject.In Key *store.KVStoreKey @@ -197,16 +197,16 @@ type nftInputs struct { BankKeeper nft.BankKeeper } -type nftOutputs struct { +type NftOutputs struct { depinject.Out NFTKeeper keeper.Keeper Module runtime.AppModuleWrapper } -func provideModule(in nftInputs) nftOutputs { +func ProvideModule(in NftInputs) NftOutputs { k := keeper.NewKeeper(in.Key, in.Cdc, in.AccountKeeper, in.BankKeeper) m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.Registry) - return nftOutputs{NFTKeeper: k, Module: runtime.WrapAppModule(m)} + return NftOutputs{NFTKeeper: k, Module: runtime.WrapAppModule(m)} } diff --git a/x/params/module.go b/x/params/module.go index 5db9addd596d..fed35120c14d 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -135,17 +135,17 @@ func (AppModule) ConsensusVersion() uint64 { return 1 } func init() { appmodule.Register(&modulev1.Module{}, appmodule.Provide( - provideModuleBasic, - provideModule, - provideSubspace, + ProvideModuleBasic, + ProvideModule, + ProvideSubspace, )) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type paramsInputs struct { +type ParamsInputs struct { depinject.In KvStoreKey *store.KVStoreKey @@ -154,7 +154,7 @@ type paramsInputs struct { LegacyAmino *codec.LegacyAmino } -type paramsOutputs struct { +type ParamsOutputs struct { depinject.Out ParamsKeeper keeper.Keeper @@ -162,16 +162,16 @@ type paramsOutputs struct { GovHandler govv1beta1.HandlerRoute } -func provideModule(in paramsInputs) paramsOutputs { +func ProvideModule(in ParamsInputs) ParamsOutputs { k := keeper.NewKeeper(in.Cdc, in.LegacyAmino, in.KvStoreKey, in.TransientStoreKey) m := runtime.WrapAppModule(NewAppModule(k)) govHandler := govv1beta1.HandlerRoute{RouteKey: proposal.RouterKey, Handler: NewParamChangeProposalHandler(k)} - return paramsOutputs{ParamsKeeper: k, Module: m, GovHandler: govHandler} + return ParamsOutputs{ParamsKeeper: k, Module: m, GovHandler: govHandler} } -type subspaceInputs struct { +type SubspaceInputs struct { depinject.In Key depinject.ModuleKey @@ -179,7 +179,7 @@ type subspaceInputs struct { KeyTables map[string]types.KeyTable } -func provideSubspace(in subspaceInputs) types.Subspace { +func ProvideSubspace(in SubspaceInputs) types.Subspace { moduleName := in.Key.Name() kt, exists := in.KeyTables[moduleName] if !exists { diff --git a/x/slashing/module.go b/x/slashing/module.go index a01a8b37deb6..451d4a8bf154 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -5,13 +5,14 @@ import ( "encoding/json" "fmt" - modulev1 "cosmossdk.io/api/cosmos/slashing/module/v1" - "cosmossdk.io/core/appmodule" - "cosmossdk.io/depinject" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + modulev1 "cosmossdk.io/api/cosmos/slashing/module/v1" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -199,17 +200,17 @@ func init() { appmodule.Register( &modulev1.Module{}, appmodule.Provide( - provideModuleBasic, - provideModule, + ProvideModuleBasic, + ProvideModule, ), ) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type slashingInputs struct { +type SlashingInputs struct { depinject.In ModuleKey depinject.OwnModuleKey @@ -226,7 +227,7 @@ type slashingInputs struct { LegacySubspace exported.Subspace } -type slashingOutputs struct { +type SlashingOutputs struct { depinject.Out Keeper keeper.Keeper @@ -234,7 +235,7 @@ type slashingOutputs struct { Hooks staking.StakingHooksWrapper } -func provideModule(in slashingInputs) slashingOutputs { +func ProvideModule(in SlashingInputs) SlashingOutputs { authority, ok := in.Authority[depinject.ModuleKey(in.ModuleKey).Name()] if !ok { // default to governance authority if not provided @@ -243,7 +244,7 @@ func provideModule(in slashingInputs) slashingOutputs { k := keeper.NewKeeper(in.Cdc, in.LegacyAmino, in.Key, in.StakingKeeper, authority.String()) m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.StakingKeeper, in.LegacySubspace) - return slashingOutputs{ + return SlashingOutputs{ Keeper: k, Module: runtime.WrapAppModule(m), Hooks: staking.StakingHooksWrapper{StakingHooks: k.Hooks()}, diff --git a/x/staking/module.go b/x/staking/module.go index 6ffc9bea4110..66deb54e8908 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -187,16 +187,16 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val func init() { appmodule.Register( &modulev1.Module{}, - appmodule.Provide(provideModuleBasic, provideModule), - appmodule.Invoke(invokeSetStakingHooks), + appmodule.Provide(ProvideModuleBasic, ProvideModule), + appmodule.Invoke(InvokeSetStakingHooks), ) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type stakingInputs struct { +type StakingInputs struct { depinject.In Config *modulev1.Module @@ -211,14 +211,14 @@ type stakingInputs struct { } // Dependency Injection Outputs -type stakingOutputs struct { +type StakingOutputs struct { depinject.Out StakingKeeper *keeper.Keeper Module runtime.AppModuleWrapper } -func provideModule(in stakingInputs) stakingOutputs { +func ProvideModule(in StakingInputs) StakingOutputs { authority, ok := in.Authority[depinject.ModuleKey(in.ModuleKey).Name()] if !ok { // default to governance authority if not provided @@ -233,10 +233,10 @@ func provideModule(in stakingInputs) stakingOutputs { authority.String(), ) m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.LegacySubspace) - return stakingOutputs{StakingKeeper: k, Module: runtime.WrapAppModule(m)} + return StakingOutputs{StakingKeeper: k, Module: runtime.WrapAppModule(m)} } -func invokeSetStakingHooks( +func InvokeSetStakingHooks( config *modulev1.Module, keeper *keeper.Keeper, stakingHooks map[string]types.StakingHooksWrapper, diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 24de870db39c..881282a3844e 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -144,15 +144,15 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(provideModuleBasic, provideModule), + appmodule.Provide(ProvideModuleBasic, ProvideModule), ) } -func provideModuleBasic() runtime.AppModuleBasicWrapper { +func ProvideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -type upgradeInputs struct { +type UpgradeInputs struct { depinject.In ModuleKey depinject.OwnModuleKey @@ -164,7 +164,7 @@ type upgradeInputs struct { Authority map[string]sdk.AccAddress `optional:"true"` } -type upgradeOutputs struct { +type UpgradeOutputs struct { depinject.Out UpgradeKeeper keeper.Keeper @@ -172,7 +172,7 @@ type upgradeOutputs struct { GovHandler govv1beta1.HandlerRoute } -func provideModule(in upgradeInputs) upgradeOutputs { +func ProvideModule(in UpgradeInputs) UpgradeOutputs { var ( homePath string skipUpgradeHeights = make(map[int64]bool) @@ -197,5 +197,5 @@ func provideModule(in upgradeInputs) upgradeOutputs { m := NewAppModule(k) gh := govv1beta1.HandlerRoute{RouteKey: types.RouterKey, Handler: NewSoftwareUpgradeProposalHandler(k)} - return upgradeOutputs{UpgradeKeeper: k, Module: runtime.WrapAppModule(m), GovHandler: gh} + return UpgradeOutputs{UpgradeKeeper: k, Module: runtime.WrapAppModule(m), GovHandler: gh} }