-
Notifications
You must be signed in to change notification settings - Fork 224
/
genesis.go
59 lines (49 loc) · 2.02 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
51
52
53
54
55
56
57
58
59
package cronos
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/crypto-org-chain/cronos/v2/x/cronos/keeper"
"github.com/crypto-org-chain/cronos/v2/x/cronos/types"
"github.com/ethereum/go-ethereum/common"
)
// InitGenesis initializes the capability module's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
if err := k.SetParams(ctx, genState.Params); err != nil {
panic(fmt.Sprintf("Invalid cronos module params: %v\n", genState.Params))
}
for _, m := range genState.ExternalContracts {
// Only allowed to bootstrap external token at genesis
if !types.IsValidIBCDenom(m.Denom) && !types.IsValidGravityDenom(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.SetExternalContractForDenom(ctx, m.Denom, common.HexToAddress(m.Contract)); err != nil {
panic(err)
}
}
for _, m := range genState.AutoContracts {
// Only allowed to bootstrap external token at genesis
if !types.IsValidIBCDenom(m.Denom) && !types.IsValidGravityDenom(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))
}
k.SetAutoContractForDenom(ctx, m.Denom, common.HexToAddress(m.Contract))
}
// this line is used by starport scaffolding # genesis/module/init
// this line is used by starport scaffolding # ibc/genesis/init
}
// ExportGenesis returns the capability module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
// this line is used by starport scaffolding # genesis/module/export
// this line is used by starport scaffolding # ibc/genesis/export
return &types.GenesisState{
Params: k.GetParams(ctx),
ExternalContracts: k.GetExternalContracts(ctx),
AutoContracts: k.GetAutoContracts(ctx),
}
}