diff --git a/app/app.go b/app/app.go index 31dbd476..7d72e103 100644 --- a/app/app.go +++ b/app/app.go @@ -410,7 +410,7 @@ func New( app.MintKeeper = mintkeeper.NewKeeper( appCodec, keys[minttypes.StoreKey], - app.GetSubspace(minttypes.ModuleName), + authtypes.NewModuleAddress(govtypes.ModuleName), &stakingKeeper, app.AccountKeeper, app.BankKeeper, diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go index 316698e6..ab0beedc 100644 --- a/x/mint/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -7,15 +7,15 @@ import ( "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/okp4/okp4d/x/mint/types" ) // Keeper of the mint store. type Keeper struct { - cdc codec.BinaryCodec - storeKey storetypes.StoreKey - paramSpace paramtypes.Subspace + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + // the address capable of executing a MsgUpdateParams message. Typically, this should be the x/gov module account. + authority sdk.AccAddress stakingKeeper types.StakingKeeper bankKeeper types.BankKeeper feeCollectorName string @@ -23,24 +23,29 @@ type Keeper struct { // NewKeeper creates a new mint Keeper instance. func NewKeeper( - cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace, - sk types.StakingKeeper, ak types.AccountKeeper, bk types.BankKeeper, + cdc codec.BinaryCodec, + key storetypes.StoreKey, + authority sdk.AccAddress, + sk types.StakingKeeper, + ak types.AccountKeeper, + bk types.BankKeeper, feeCollectorName string, + ) Keeper { // ensure mint module account is set if addr := ak.GetModuleAddress(types.ModuleName); addr == nil { panic("the mint module account has not been set") } - // set KeyTable if it has not already been set - if !paramSpace.HasKeyTable() { - paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) + // ensure gov module account is set and is not nil + if err := sdk.VerifyAddressFormat(authority); err != nil { + panic(err) } return Keeper{ cdc: cdc, storeKey: key, - paramSpace: paramSpace, + authority: authority, stakingKeeper: sk, bankKeeper: bk, feeCollectorName: feeCollectorName, @@ -73,13 +78,28 @@ func (k Keeper) SetMinter(ctx sdk.Context, minter types.Minter) { // GetParams returns the total set of minting parameters. func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { - k.paramSpace.GetParamSet(ctx, ¶ms) + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParamsKey) + if bz == nil { + return params + } + k.cdc.MustUnmarshal(bz, ¶ms) return params } // SetParams sets the total set of minting parameters. -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { - k.paramSpace.SetParamSet(ctx, ¶ms) +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { + if err := params.Validate(); err != nil { + return err + } + + store := ctx.KVStore(k.storeKey) + bz, err := k.cdc.Marshal(¶ms) + if err != nil { + return err + } + store.Set(types.ParamsKey, bz) + return nil } // TokenSupply implements an alias call to the underlying bank keeper's diff --git a/x/mint/types/keys.go b/x/mint/types/keys.go index cbfbb30e..67556f1e 100644 --- a/x/mint/types/keys.go +++ b/x/mint/types/keys.go @@ -2,6 +2,7 @@ package types // MinterKey is the key to use for the keeper store. var MinterKey = []byte{0x00} +var ParamsKey = []byte{0x01} const ( // module name.