Skip to content

Commit

Permalink
refactor(mint)!: move x/param to x/mint state
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Mar 29, 2023
1 parent f44d280 commit fe7c618
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
46 changes: 33 additions & 13 deletions x/mint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,45 @@ 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
}

// 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,
Expand Down Expand Up @@ -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, &params)
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
return params
}
k.cdc.MustUnmarshal(bz, &params)
return params
}

// SetParams sets the total set of minting parameters.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, &params)
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(&params)
if err != nil {
return err
}
store.Set(types.ParamsKey, bz)
return nil
}

// TokenSupply implements an alias call to the underlying bank keeper's
Expand Down
1 change: 1 addition & 0 deletions x/mint/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit fe7c618

Please sign in to comment.