-
Notifications
You must be signed in to change notification settings - Fork 180
/
genesis.go
39 lines (32 loc) · 1.07 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
package erc20
import (
"fmt"
"github.com/ethereum/go-ethereum/common"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
abci "github.com/okex/exchain/libs/tendermint/abci/types"
"github.com/okex/exchain/x/erc20/types"
)
// InitGenesis initializes genesis state based on exported genesis
func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) []abci.ValidatorUpdate {
k.SetParams(ctx, data.Params)
for _, m := range data.TokenMappings {
if !types.IsValidIBCDenom(m.Denom) {
panic(fmt.Sprintf("Invalid denom to map to contract: %s", m.Denom))
}
if !common.IsHexAddress(m.Contract) {
panic(fmt.Sprintf("Invalid contract address: %s", m.Contract))
}
if err := k.SetContractForDenom(ctx, m.Denom, common.HexToAddress(m.Contract)); err != nil {
panic(err)
}
}
k.InitInternalTemplateContract(ctx)
return []abci.ValidatorUpdate{}
}
// ExportGenesis exports genesis state of the erc20 module
func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState {
return GenesisState{
Params: k.GetParams(ctx),
TokenMappings: k.GetContracts(ctx),
}
}