0g-chain/x/community/keeper/params.go
2024-07-30 21:46:39 +08:00

46 lines
923 B
Go

package keeper
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/0glabs/0g-chain/x/community/types"
)
// GetParams returns the params from the store
func (k Keeper) GetParams(ctx sdk.Context) (types.Params, bool) {
store := ctx.KVStore(k.key)
bz := store.Get(types.ParamsKey)
if bz == nil {
return types.Params{}, false
}
params := types.Params{}
k.cdc.MustUnmarshal(bz, &params)
return params, true
}
// SetParams sets params on the store
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
if err := params.Validate(); err != nil {
panic(fmt.Sprintf("invalid params: %s", err))
}
store := ctx.KVStore(k.key)
bz := k.cdc.MustMarshal(&params)
store.Set(types.ParamsKey, bz)
}
func (k Keeper) mustGetParams(ctx sdk.Context) types.Params {
params, found := k.GetParams(ctx)
if !found {
panic("invalid state: module parameters not found")
}
return params
}