/
store.go
33 lines (29 loc) · 1.02 KB
/
store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package cosmwasmpool
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/osmosis-labs/osmosis/osmoutils"
"github.com/osmosis-labs/osmosis/v15/x/cosmwasmpool/model"
"github.com/osmosis-labs/osmosis/v15/x/cosmwasmpool/types"
)
// SetPool stores the given pool in state.
func (k Keeper) SetPool(ctx sdk.Context, pool types.CosmWasmExtension) {
store := ctx.KVStore(k.storeKey)
osmoutils.MustSet(store, types.FormatPoolsPrefix(pool.GetId()), pool.GetStoreModel())
}
// GetPoolById returns a CosmWasmExtension that corresponds to the requested pool id. Returns error if pool id is not found.
func (k Keeper) GetPoolById(ctx sdk.Context, poolId uint64) (types.CosmWasmExtension, error) {
store := ctx.KVStore(k.storeKey)
pool := model.CosmWasmPool{}
key := types.FormatPoolsPrefix(poolId)
found, err := osmoutils.Get(store, key, &pool)
if err != nil {
panic(err)
}
if !found {
return nil, types.PoolNotFoundError{PoolId: poolId}
}
return &model.Pool{
CosmWasmPool: pool,
WasmKeeper: k.wasmKeeper,
}, nil
}