feat: allow custom authority and inflation function when using app-wiring (#12660)
This commit is contained in:
+59
-50
@@ -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()},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user