mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-29 17:55:19 +00:00
46 lines
923 B
Go
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, ¶ms)
|
|
|
|
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(¶ms)
|
|
|
|
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
|
|
}
|