/
genesis.go
48 lines (42 loc) · 1.4 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
package keeper
import (
"math/big"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/irisnet/erc721-bridge/x/converter/types"
)
func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) {
// ensure erc721 module account is set on genesis
if acc := k.accountKeeper.GetModuleAccount(ctx, types.ModuleName); acc == nil {
// NOTE: shouldn't occur
panic("the erc721 module account has not been set")
}
for _, classCollection := range data.ClassCollections {
classPair := classCollection.GetClassPair()
id := classPair.GetID()
k.SetClassPair(ctx, classPair)
k.SetClassMap(ctx, classPair.ClassId, id)
k.SetERC721Map(ctx, classPair.GetERC721Contract(), id)
for _, tokenPair := range classCollection.Tokens {
erc721TokenId, ok := new(big.Int).SetString(tokenPair.TokenId, 10)
if !ok {
panic("")
}
k.SetNativeNftIdMap(ctx,
classPair.ClassId, tokenPair.TokenId, erc721TokenId)
k.SetERC721TokenIdMap(ctx,
common.HexToAddress(classPair.ContractAddress),
erc721TokenId, tokenPair.TokenId)
}
}
erc721Keeper := k.ERC721Keeper()
for _, trace := range data.ClassTraces {
erc721Keeper.SetClassTrace(ctx, trace)
}
}
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
return &types.GenesisState{
ClassCollections: k.GetClassCollections(ctx),
ClassTraces: k.ERC721Keeper().GetClassTrace(ctx),
}
}