-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenesis.go
91 lines (74 loc) · 1.81 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package wormhole
import (
"encoding/hex"
"cosmossdk.io/collections"
"cosmossdk.io/core/address"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/noble-assets/wormhole/keeper"
"github.com/noble-assets/wormhole/types"
)
func InitGenesis(ctx sdk.Context, k *keeper.Keeper, cdc address.Codec, genesis types.GenesisState) {
if err := k.Config.Set(ctx, genesis.Config); err != nil {
panic(err)
}
if err := k.WormchainChannel.Set(ctx, genesis.WormchainChannel); err != nil {
panic(err)
}
for index, guardianSet := range genesis.GuardianSets {
if err := k.GuardianSets.Set(ctx, index, guardianSet); err != nil {
panic(err)
}
}
for address, sequence := range genesis.Sequences {
sender := make([]byte, 32)
bz, err := cdc.StringToBytes(address)
if err != nil {
panic(err)
}
copy(sender[12:], bz)
if err := k.Sequences.Set(ctx, sender, sequence); err != nil {
panic(err)
}
}
for hash, id := range genesis.VaaArchive {
bz, err := hex.DecodeString(hash)
if err != nil {
panic(err)
}
if err := k.VAAArchive.Set(ctx, bz, collections.Join(id, true)); err != nil {
panic(err)
}
}
if err := k.BindPort(ctx); err != nil {
panic(err)
}
}
func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) *types.GenesisState {
config, err := k.Config.Get(ctx)
if err != nil {
panic(err)
}
wormchainChannel, err := k.WormchainChannel.Get(ctx)
if err != nil {
panic(err)
}
guardianSets, err := k.GetGuardianSets(ctx)
if err != nil {
panic(err)
}
sequences, err := k.GetSequences(ctx)
if err != nil {
panic(err)
}
vaaArchive, err := k.GetVAAArchive(ctx)
if err != nil {
panic(err)
}
return &types.GenesisState{
Config: config,
WormchainChannel: wormchainChannel,
GuardianSets: guardianSets,
Sequences: sequences,
VaaArchive: vaaArchive,
}
}