mukan-ibc/modules/light-clients/08-wasm/keeper/genesis.go
Mukan Erkin Törük 6852832fe8
Some checks failed
CodeQL / Analyze (push) Waiting to run
Docker Build & Push Simapp (main) / docker-build (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Tests / Code Coverage / build (amd64) (push) Waiting to run
Tests / Code Coverage / build (arm64) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[additional-args:-tags="test_e2e" name:e2e path:./e2e]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:08-wasm path:./modules/light-clients/08-wasm]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:ibc-go path:.]) (push) Waiting to run
Deploy to GitHub Pages / Deploy to GitHub Pages (push) Has been cancelled
Buf-Push / push (push) Has been cancelled
initial: sovereign Mukan Network fork
2026-05-11 03:18:28 +03:00

49 lines
1.2 KiB
Go

package keeper
import (
wasmvm "github.com/CosmWasm/wasmvm/v2"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/v10/types"
)
// InitGenesis initializes the 08-wasm module's state from a provided genesis
// state.
func (k Keeper) InitGenesis(ctx sdk.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 sdk.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
}