-
Notifications
You must be signed in to change notification settings - Fork 628
/
genesis.go
49 lines (41 loc) · 1.22 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
package keeper
import (
"context"
wasmvm "github.com/CosmWasm/wasmvm/v2"
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
)
// InitGenesis initializes the 08-wasm module's state from a provided genesis
// state.
func (k Keeper) InitGenesis(ctx context.Context, gs types.GenesisState) error {
storeFn := func(code wasmvm.WasmCode, _ uint64) (wasmvm.Checksum, uint64, error) {
checksum, err := k.GetVM().StoreCodeUnchecked(code)
return checksum, 0, err
}
for _, contract := range gs.Contracts {
_, err := k.storeWasmCode(ctx, contract.CodeBytes, storeFn)
if err != nil {
return err
}
}
return nil
}
// ExportGenesis returns the 08-wasm module's exported genesis. This includes the code
// for all contracts previously stored.
func (k Keeper) ExportGenesis(ctx context.Context) types.GenesisState {
checksums, err := k.GetAllChecksums(ctx)
if err != nil {
panic(err)
}
// Grab code from wasmVM and add to genesis state.
var genesisState types.GenesisState
for _, checksum := range checksums {
code, err := k.GetVM().GetCode(checksum)
if err != nil {
panic(err)
}
genesisState.Contracts = append(genesisState.Contracts, types.Contract{
CodeBytes: code,
})
}
return genesisState
}