Skip to content

Commit

Permalink
fix custom staking keeper msg server issue with nil keeper
Browse files Browse the repository at this point in the history
  • Loading branch information
RustNinja committed Dec 16, 2023
1 parent 229a985 commit dc2842b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
8 changes: 4 additions & 4 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appCodec, appKeepers.keys[stakingtypes.StoreKey], appKeepers.AccountKeeper, appKeepers.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.CustomStakingKeeper = customstaking.NewBaseKeeper(
appCodec /*appKeepers.keys[customstakingtypes.StoreKey],*/, *appKeepers.StakingKeeper, appKeepers.AccountKeeper, appKeepers.MintKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.MintKeeper = mintkeeper.NewKeeper(
appCodec, appKeepers.keys[minttypes.StoreKey], appKeepers.StakingKeeper,
appKeepers.AccountKeeper, appKeepers.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.CustomStakingKeeper = customstaking.NewKeeper(
appCodec /*appKeepers.keys[stakingtypes.StoreKey],*/, *appKeepers.StakingKeeper, appKeepers.AccountKeeper, &appKeepers.MintKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.DistrKeeper = distrkeeper.NewKeeper(
appCodec, appKeepers.keys[distrtypes.StoreKey], appKeepers.AccountKeeper, appKeepers.BankKeeper,
appKeepers.StakingKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Expand Down
10 changes: 4 additions & 6 deletions custom/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
accountkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"

Expand All @@ -12,9 +11,8 @@ import (
type Keeper struct {
stakingkeeper.Keeper
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
acck accountkeeper.AccountKeeper
mintkeeper mintkeeper.Keeper
mintkeeper *mintkeeper.Keeper
authority string
}

Expand All @@ -33,19 +31,19 @@ type Keeper struct {
// return keeper
// }

func NewBaseKeeper(
func NewKeeper(
cdc codec.BinaryCodec,
// keys storetypes.StoreKey,
staking stakingkeeper.Keeper,
acck accountkeeper.AccountKeeper,
mintkeeper mintkeeper.Keeper,
mintkeeper *mintkeeper.Keeper,
authority string,
) Keeper {
keeper := Keeper{
Keeper: staking,
acck: acck,
authority: authority,
mintkeeper: mintkeeper,
cdc: cdc,
}
return keeper
}
Expand Down
4 changes: 2 additions & 2 deletions custom/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type msgServer struct {

var _ types.MsgServer = msgServer{}

func NewMsgServerImpl(stakingKeeper stakingkeeper.Keeper) types.MsgServer {
return &msgServer{msgServer: stakingkeeper.NewMsgServerImpl(&stakingKeeper)}
func NewMsgServerImpl(stakingKeeper stakingkeeper.Keeper, customstakingkeeper Keeper) types.MsgServer {
return &msgServer{Keeper: customstakingkeeper, msgServer: stakingkeeper.NewMsgServerImpl(&stakingKeeper)}
}

func (k msgServer) CreateValidator(goCtx context.Context, msg *types.MsgCreateValidator) (*types.MsgCreateValidatorResponse, error) {
Expand Down
2 changes: 1 addition & 1 deletion custom/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewAppModule(cdc codec.Codec, keeper customstakingkeeper.Keeper, accountKee
// when trying to force this custom keeper into a bankkeeper.BaseKeeper
func (am AppModule) RegisterServices(cfg module.Configurator) {
// types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(&am.keeper))
types.RegisterMsgServer(cfg.MsgServer(), customstakingkeeper.NewMsgServerImpl(am.keeper.Keeper))
types.RegisterMsgServer(cfg.MsgServer(), customstakingkeeper.NewMsgServerImpl(am.keeper.Keeper, am.keeper))
querier := keeper.Querier{Keeper: &am.keeper.Keeper}
types.RegisterQueryServer(cfg.QueryServer(), querier)

Expand Down
6 changes: 3 additions & 3 deletions x/mint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (k Keeper) StoreDelegation(ctx sdk.Context, delegation stakingtypes.Delegat

// SetLastTotalPower Set the last total validator power.
func (k Keeper) SetLastTotalPower(ctx sdk.Context, power math.Int) {
// store := ctx.KVStore(k.storeKey)
// bz := k.cdc.MustMarshal(&sdk.IntProto{Int: power})
// store.Set(types.DelegationKey, bz)
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&sdk.IntProto{Int: power})
store.Set(types.DelegationKey, bz)
}

0 comments on commit dc2842b

Please sign in to comment.