diff --git a/simapp/app.go b/simapp/app.go index 34432a1aac..b0689eaf7d 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -193,8 +193,22 @@ func NewSimApp( app = &SimApp{} appBuilder *runtime.AppBuilder - // merge the app.yaml and the appOpts in one config - appConfig = depinject.Configs(AppConfig, depinject.Supply(appOpts)) + // merge the AppConfig and other configuration in one config + appConfig = depinject.Configs( + AppConfig, + depinject.Supply( + // supply the application options + appOpts, + + // for providing a custom inflaction function for x/mint + // add here your custom function that implements the minttypes.InflationCalculationFn interface. + + // for providing a custom authority to a module simply add it below. By default the governance module is the default authority. + // map[string]sdk.AccAddress{ + // minttypes.ModuleName: authtypes.NewModuleAddress(authtypes.ModuleName), + // }, + ), + ) ) if err := depinject.Inject(appConfig, diff --git a/x/bank/module.go b/x/bank/module.go index 647671b392..a25dcfbb32 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -228,12 +228,13 @@ func provideModuleBasic() runtime.AppModuleBasicWrapper { type bankInputs struct { depinject.In - Config *modulev1.Module - Cdc codec.Codec - Key *store.KVStoreKey + ModuleKey depinject.OwnModuleKey + Config *modulev1.Module + Cdc codec.Codec + Key *store.KVStoreKey AccountKeeper types.AccountKeeper - Authority types.BankAuthority `optional:"true"` + Authority map[string]sdk.AccAddress `optional:"true"` // LegacySubspace is used solely for migration of x/params managed parameters LegacySubspace exported.Subspace @@ -263,10 +264,10 @@ func provideModule(in bankInputs) bankOutputs { } } - authority := in.Authority - if authority == nil || len(authority) == 0 { + authority, ok := in.Authority[depinject.ModuleKey(in.ModuleKey).Name()] + if !ok { // default to governance authority if not provided - authority = types.BankAuthority(authtypes.NewModuleAddress(govtypes.ModuleName)) + authority = authtypes.NewModuleAddress(govtypes.ModuleName) } bankKeeper := keeper.NewBaseKeeper( diff --git a/x/bank/types/authority.go b/x/bank/types/authority.go deleted file mode 100644 index 0be8913462..0000000000 --- a/x/bank/types/authority.go +++ /dev/null @@ -1,11 +0,0 @@ -package types - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" -) - -type BankAuthority sdk.AccAddress - -func (a BankAuthority) String() string { - return sdk.AccAddress(a).String() -} diff --git a/x/crisis/module.go b/x/crisis/module.go index 0df2d64d90..0bf0e49bbc 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -197,10 +197,12 @@ func init() { type crisisInputs struct { depinject.In - Config *modulev1.Module - Key *store.KVStoreKey - Cdc codec.Codec - AppOpts servertypes.AppOptions `optional:"true"` + ModuleKey depinject.OwnModuleKey + Config *modulev1.Module + Key *store.KVStoreKey + Cdc codec.Codec + AppOpts servertypes.AppOptions `optional:"true"` + Authority map[string]sdk.AccAddress `optional:"true"` BankKeeper types.SupplyKeeper @@ -227,13 +229,19 @@ func provideModule(in crisisInputs) crisisOutputs { feeCollectorName = authtypes.FeeCollectorName } + authority, ok := in.Authority[depinject.ModuleKey(in.ModuleKey).Name()] + if !ok { + // default to governance authority if not provided + authority = authtypes.NewModuleAddress(govtypes.ModuleName) + } + k := keeper.NewKeeper( in.Cdc, in.Key, invalidCheckPeriod, in.BankKeeper, feeCollectorName, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + authority.String(), ) skipGenesisInvariants := cast.ToBool(in.AppOpts.Get(FlagSkipGenesisInvariants)) diff --git a/x/distribution/module.go b/x/distribution/module.go index 6f4b9f84ae..5b5eb0ac02 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -237,9 +237,11 @@ func provideModuleBasic() runtime.AppModuleBasicWrapper { type distrInputs struct { depinject.In - Config *modulev1.Module - Key *store.KVStoreKey - Cdc codec.Codec + ModuleKey depinject.OwnModuleKey + Config *modulev1.Module + Key *store.KVStoreKey + Cdc codec.Codec + Authority map[string]sdk.AccAddress `optional:"true"` AccountKeeper types.AccountKeeper BankKeeper types.BankKeeper @@ -264,6 +266,12 @@ func provideModule(in distrInputs) distrOutputs { feeCollectorName = authtypes.FeeCollectorName } + authority, ok := in.Authority[depinject.ModuleKey(in.ModuleKey).Name()] + if !ok { + // default to governance authority if not provided + authority = authtypes.NewModuleAddress(govtypes.ModuleName) + } + k := keeper.NewKeeper( in.Cdc, in.Key, @@ -271,7 +279,7 @@ func provideModule(in distrInputs) distrOutputs { in.BankKeeper, in.StakingKeeper, feeCollectorName, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + authority.String(), ) m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.StakingKeeper, in.LegacySubspace) diff --git a/x/mint/module.go b/x/mint/module.go index dbd91bac8c..4d9781f3d4 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -236,9 +236,12 @@ func provideModuleBasic() runtime.AppModuleBasicWrapper { type mintInputs struct { depinject.In - Config *modulev1.Module - Key *store.KVStoreKey - Cdc codec.Codec + ModuleKey depinject.OwnModuleKey + Config *modulev1.Module + Key *store.KVStoreKey + Cdc codec.Codec + Authority map[string]sdk.AccAddress `optional:"true"` + InflationCalculationFn types.InflationCalculationFn `optional:"true"` // LegacySubspace is used solely for migration of x/params managed parameters LegacySubspace exported.Subspace @@ -261,6 +264,12 @@ func provideModule(in mintInputs) mintOutputs { feeCollectorName = authtypes.FeeCollectorName } + authority, ok := in.Authority[depinject.ModuleKey(in.ModuleKey).Name()] + if !ok { + // default to governance authority if not provided + authority = authtypes.NewModuleAddress(govtypes.ModuleName) + } + k := keeper.NewKeeper( in.Cdc, in.Key, @@ -268,11 +277,11 @@ func provideModule(in mintInputs) mintOutputs { in.AccountKeeper, in.BankKeeper, feeCollectorName, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + authority.String(), ) - // TODO: allow to set inflation calculation function - m := NewAppModule(in.Cdc, k, in.AccountKeeper, nil, in.LegacySubspace) + // 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)} } diff --git a/x/slashing/module.go b/x/slashing/module.go index 773b920f55..d554ff32e8 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -184,56 +184,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { BeginBlocker(ctx, req, am.keeper) } -// _____________________________________________________________________________________ - -func init() { - appmodule.Register( - &modulev1.Module{}, - appmodule.Provide( - provideModuleBasic, - provideModule, - ), - ) -} - -func provideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - -type slashingInputs struct { - depinject.In - - Key *store.KVStoreKey - Cdc codec.Codec - LegacyAmino *codec.LegacyAmino - AccountKeeper types.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper"` - BankKeeper types.BankKeeper `key:"cosmos.bank.v1.Keeper"` - StakingKeeper types.StakingKeeper `key:"cosmos.staking.v1.Keeper"` - - // LegacySubspace is used solely for migration of x/params managed parameters - LegacySubspace exported.Subspace -} - -type slashingOutputs struct { - depinject.Out - - Keeper keeper.Keeper - Module runtime.AppModuleWrapper - Hooks staking.StakingHooksWrapper -} - -func provideModule(in slashingInputs) slashingOutputs { - k := keeper.NewKeeper(in.Cdc, in.LegacyAmino, in.Key, in.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String()) - m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.StakingKeeper, in.LegacySubspace) - return slashingOutputs{ - Keeper: k, - Module: runtime.WrapAppModule(m), - Hooks: staking.StakingHooksWrapper{StakingHooks: k.Hooks()}, - } -} - -// _____________________________________________________________________________________ - // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the slashing module. @@ -263,3 +213,62 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp am.accountKeeper, am.bankKeeper, am.keeper, am.stakingKeeper, ) } + +// ============================================================================ +// New App Wiring Setup +// ============================================================================ + +func init() { + appmodule.Register( + &modulev1.Module{}, + appmodule.Provide( + provideModuleBasic, + provideModule, + ), + ) +} + +func provideModuleBasic() runtime.AppModuleBasicWrapper { + return runtime.WrapAppModuleBasic(AppModuleBasic{}) +} + +type slashingInputs struct { + depinject.In + + ModuleKey depinject.OwnModuleKey + Key *store.KVStoreKey + Cdc codec.Codec + LegacyAmino *codec.LegacyAmino + Authority map[string]sdk.AccAddress `optional:"true"` + + AccountKeeper types.AccountKeeper + BankKeeper types.BankKeeper + StakingKeeper types.StakingKeeper + + // LegacySubspace is used solely for migration of x/params managed parameters + LegacySubspace exported.Subspace +} + +type slashingOutputs struct { + depinject.Out + + Keeper keeper.Keeper + Module runtime.AppModuleWrapper + Hooks staking.StakingHooksWrapper +} + +func provideModule(in slashingInputs) slashingOutputs { + authority, ok := in.Authority[depinject.ModuleKey(in.ModuleKey).Name()] + if !ok { + // default to governance authority if not provided + authority = authtypes.NewModuleAddress(govtypes.ModuleName) + } + + 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{ + Keeper: k, + Module: runtime.WrapAppModule(m), + Hooks: staking.StakingHooksWrapper{StakingHooks: k.Hooks()}, + } +} diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 011885f0ee..a3138ddf80 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -168,11 +168,13 @@ func provideModuleBasic() runtime.AppModuleBasicWrapper { type upgradeInputs struct { depinject.In - Config *modulev1.Module - Key *store.KVStoreKey - Cdc codec.Codec + ModuleKey depinject.OwnModuleKey + Config *modulev1.Module + Key *store.KVStoreKey + Cdc codec.Codec - AppOpts servertypes.AppOptions `optional:"true"` + AppOpts servertypes.AppOptions `optional:"true"` + Authority map[string]sdk.AccAddress `optional:"true"` } type upgradeOutputs struct { @@ -197,8 +199,14 @@ func provideModule(in upgradeInputs) upgradeOutputs { homePath = cast.ToString(in.AppOpts.Get(flags.FlagHome)) } + authority, ok := in.Authority[depinject.ModuleKey(in.ModuleKey).Name()] + if !ok { + // default to governance authority if not provided + authority = authtypes.NewModuleAddress(govtypes.ModuleName) + } + // set the governance module account as the authority for conducting upgrades - k := keeper.NewKeeper(skipUpgradeHeights, in.Key, in.Cdc, homePath, nil, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + k := keeper.NewKeeper(skipUpgradeHeights, in.Key, in.Cdc, homePath, nil, authority.String()) m := NewAppModule(k) gh := govv1beta1.HandlerRoute{RouteKey: types.RouterKey, Handler: NewSoftwareUpgradeProposalHandler(k)}