/
genesis.go
50 lines (43 loc) · 1.2 KB
/
genesis.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package cosmwasmpool
import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/osmosis-labs/osmosis/v17/x/cosmwasmpool/types"
)
// InitGenesis initializes the store state from a genesis state.
func (k *Keeper) InitGenesis(ctx sdk.Context, gen *types.GenesisState, unpacker codectypes.AnyUnpacker) {
k.SetParams(ctx, gen.Params)
// Add each genesis state pool to the x/cosmwasmpool module's state
for _, any := range gen.Pools {
var pool types.CosmWasmExtension
err := unpacker.UnpackAny(any, &pool)
if err != nil {
panic(err)
}
k.SetPool(ctx, pool)
}
}
// ExportGenesis returns the cosmwasm pool's exported genesis.
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
params := k.GetParams(ctx)
pools, err := k.GetPools(ctx)
if err != nil {
panic(err)
}
poolAnys := []*codectypes.Any{}
for _, poolI := range pools {
cosmwasmPool, ok := poolI.(types.CosmWasmExtension)
if !ok {
panic("invalid pool type")
}
any, err := codectypes.NewAnyWithValue(cosmwasmPool)
if err != nil {
panic(err)
}
poolAnys = append(poolAnys, any)
}
return &types.GenesisState{
Params: params,
Pools: poolAnys,
}
}