fix: update x/protocolpool to use passed codecs to avoid nil pointer (#24594)

This commit is contained in:
Alex | Interchain Labs 2025-04-28 18:59:28 -04:00 committed by GitHub
parent 8475a2ba1a
commit e1b53c6c9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 25 additions and 28 deletions

View File

@ -108,6 +108,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/auth) [#19239](https://github.com/cosmos/cosmos-sdk/pull/19239) Sets from flag in multi-sign command to avoid no key name provided error.
* (x/auth) [#23741](https://github.com/cosmos/cosmos-sdk/pull/23741) Support legacy global AccountNumber for legacy compatibility.
* (baseapp) [#24526](https://github.com/cosmos/cosmos-sdk/pull/24526) Fix incorrect retention height when `commitHeight` equals `minRetainBlocks`.
* (x/protocolpool) [#24594](https://github.com/cosmos/cosmos-sdk/pull/24594) Fix NPE when initializing module via depinject.
## [v0.50.12](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.12) - 2025-02-20

View File

@ -469,7 +469,7 @@ func NewSimApp(
app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register the governance hooks
// register the governance hooks
),
)
@ -499,7 +499,7 @@ func NewSimApp(
app.EpochsKeeper.SetHooks(
epochstypes.NewMultiEpochHooks(
// insert epoch hooks receivers here
// insert epoch hooks receivers here
),
)
@ -528,8 +528,8 @@ func NewSimApp(
nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
circuit.NewAppModule(appCodec, app.CircuitKeeper),
epochs.NewAppModule(appCodec, app.EpochsKeeper),
protocolpool.NewAppModule(appCodec, app.ProtocolPoolKeeper, app.AccountKeeper, app.BankKeeper),
epochs.NewAppModule(app.EpochsKeeper),
protocolpool.NewAppModule(app.ProtocolPoolKeeper, app.AccountKeeper, app.BankKeeper),
)
// BasicModuleManager defines the module BasicManager is in charge of setting up basic,

View File

@ -45,7 +45,7 @@ type ModuleOutputs struct {
func ProvideModule(in ModuleInputs) ModuleOutputs {
k := keeper.NewKeeper(in.StoreService, in.Cdc)
m := NewAppModule(in.Cdc, k)
m := NewAppModule(k)
return ModuleOutputs{EpochKeeper: k, Module: m}
}

View File

@ -33,14 +33,12 @@ const ConsensusVersion = 1
// AppModule implements the AppModule interface for the epochs module.
type AppModule struct {
cdc codec.Codec
keeper keeper.Keeper
}
// NewAppModule creates a new AppModule object.
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule {
func NewAppModule(keeper keeper.Keeper) AppModule {
return AppModule{
cdc: cdc,
keeper: keeper,
}
}
@ -73,8 +71,8 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
}
// DefaultGenesis returns the epochs module's default genesis state.
func (am AppModule) DefaultGenesis(_ codec.JSONCodec) json.RawMessage {
data, err := am.cdc.MarshalJSON(types.DefaultGenesis())
func (am AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
data, err := cdc.MarshalJSON(types.DefaultGenesis())
if err != nil {
panic(err)
}
@ -82,9 +80,9 @@ func (am AppModule) DefaultGenesis(_ codec.JSONCodec) json.RawMessage {
}
// ValidateGenesis performs genesis state validation for the epochs module.
func (am AppModule) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
func (am AppModule) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
var gs types.GenesisState
if err := am.cdc.UnmarshalJSON(bz, &gs); err != nil {
if err := cdc.UnmarshalJSON(bz, &gs); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
@ -92,9 +90,9 @@ func (am AppModule) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConfig
}
// InitGenesis performs the epochs module's genesis initialization
func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, bz json.RawMessage) {
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) {
var gs types.GenesisState
err := am.cdc.UnmarshalJSON(bz, &gs)
err := cdc.UnmarshalJSON(bz, &gs)
if err != nil {
panic(fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err))
}
@ -105,13 +103,13 @@ func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, bz json.RawM
}
// ExportGenesis returns the epochs module's exported genesis state as raw JSON bytes.
func (am AppModule) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) json.RawMessage {
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
gs, err := am.keeper.ExportGenesis(ctx)
if err != nil {
panic(err)
}
bz, err := am.cdc.MarshalJSON(gs)
bz, err := cdc.MarshalJSON(gs)
if err != nil {
panic(err)
}

View File

@ -57,7 +57,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
}
k := keeper.NewKeeper(in.Codec, in.StoreService, in.AccountKeeper, in.BankKeeper, authorityAddr)
m := NewAppModule(in.Codec, k, in.AccountKeeper, in.BankKeeper)
m := NewAppModule(k, in.AccountKeeper, in.BankKeeper)
return ModuleOutputs{
Keeper: k,

View File

@ -36,18 +36,16 @@ var (
// AppModule implements an application module for the pool module
type AppModule struct {
cdc codec.Codec
keeper keeper.Keeper
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
}
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper,
func NewAppModule(keeper keeper.Keeper,
accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper,
) AppModule {
return AppModule{
cdc: cdc,
keeper: keeper,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
@ -84,8 +82,8 @@ func (am AppModule) RegisterServices(configurator module.Configurator) {
}
// DefaultGenesis returns default genesis state as raw bytes for the protocolpool module.
func (am AppModule) DefaultGenesis(_ codec.JSONCodec) json.RawMessage {
data, err := am.cdc.MarshalJSON(types.DefaultGenesisState())
func (am AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
data, err := cdc.MarshalJSON(types.DefaultGenesisState())
if err != nil {
panic(err)
}
@ -93,9 +91,9 @@ func (am AppModule) DefaultGenesis(_ codec.JSONCodec) json.RawMessage {
}
// ValidateGenesis performs genesis state validation for the protocolpool module.
func (am AppModule) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
func (am AppModule) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
var data types.GenesisState
if err := am.cdc.UnmarshalJSON(bz, &data); err != nil {
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
@ -103,9 +101,9 @@ func (am AppModule) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConfig
}
// InitGenesis performs genesis initialization for the protocolpool module.
func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMessage) {
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) {
var genesisState types.GenesisState
am.cdc.MustUnmarshalJSON(data, &genesisState)
cdc.MustUnmarshalJSON(data, &genesisState)
if err := am.keeper.InitGenesis(ctx, &genesisState); err != nil {
panic(fmt.Errorf("failed to init genesis state: %w", err))
@ -113,12 +111,12 @@ func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.Ra
}
// ExportGenesis returns the exported genesis state as raw bytes for the protocolpool module.
func (am AppModule) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) json.RawMessage {
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
gs, err := am.keeper.ExportGenesis(ctx)
if err != nil {
panic(fmt.Errorf("failed to export genesis state: %w", err))
}
return am.cdc.MustMarshalJSON(gs)
return cdc.MustMarshalJSON(gs)
}
// BeginBlock implements appmodule.HasBeginBlocker.