Skip to content

Commit

Permalink
Use collections lib for params
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Jun 22, 2023
1 parent abf3ff9 commit 8eb18e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
31 changes: 8 additions & 23 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ import (
"strings"
"time"

"cosmossdk.io/collections"
corestoretypes "cosmossdk.io/core/store"

"github.com/cosmos/cosmos-sdk/runtime"

errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"

"cosmossdk.io/log"
"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"

wasmvm "github.com/CosmWasm/wasmvm"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -107,6 +106,7 @@ type Keeper struct {
maxQueryStackSize uint32
acceptedAccountTypes map[reflect.Type]struct{}
accountPruner AccountPruner
params collections.Item[types.Params]
// the address capable of executing a MsgUpdateParams message. Typically, this
// should be the x/gov module account.
authority string
Expand All @@ -122,31 +122,16 @@ func (k Keeper) getInstantiateAccessConfig(ctx sdk.Context) types.AccessType {

// GetParams returns the total set of wasm parameters.
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
var params types.Params
bz, err := k.storeService.OpenKVStore(ctx).Get(types.ParamsKey)
p, err := k.params.Get(ctx)
if err != nil {
panic(err)
}
if bz == nil {
return params
}

k.cdc.MustUnmarshal(bz, &params)
return params
return p
}

// SetParams sets all wasm parameters.
func (k Keeper) SetParams(ctx sdk.Context, ps types.Params) error {
if err := ps.ValidateBasic(); err != nil {
return err
}

store := k.storeService.OpenKVStore(ctx)
bz, err := k.cdc.Marshal(&ps)
if err != nil {
return err
}
return store.Set(types.ParamsKey, bz)
return k.params.Set(ctx, ps)
}

// GetAuthority returns the x/wasm module's authority.
Expand Down
4 changes: 4 additions & 0 deletions x/wasm/keeper/keeper_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package keeper
import (
"path/filepath"

"cosmossdk.io/collections"

corestoretypes "cosmossdk.io/core/store"

wasmvm "github.com/CosmWasm/wasmvm"
Expand Down Expand Up @@ -40,6 +42,7 @@ func NewKeeper(
panic(err)
}

sb := collections.NewSchemaBuilder(storeService)
keeper := &Keeper{
storeService: storeService,
cdc: cdc,
Expand All @@ -54,6 +57,7 @@ func NewKeeper(
gasRegister: NewDefaultWasmGasRegister(),
maxQueryStackSize: types.DefaultMaxQueryStackSize,
acceptedAccountTypes: defaultAcceptedAccountTypes,
params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)),
authority: authority,
}
keeper.wasmVMQueryHandler = DefaultQueryPlugins(bankKeeper, stakingKeeper, distrKeeper, channelKeeper, keeper)
Expand Down

0 comments on commit 8eb18e8

Please sign in to comment.