-
Notifications
You must be signed in to change notification settings - Fork 5
/
handle_genesis.go
71 lines (57 loc) · 1.7 KB
/
handle_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
package profiles
import (
"encoding/json"
tmtypes "github.com/cometbft/cometbft/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
profilestypes "github.com/desmos-labs/desmos/v7/x/profiles/types"
"github.com/desmos-labs/athena/v2/types"
)
// HandleGenesis implements modules.GenesisModule
func (m *Module) HandleGenesis(doc *tmtypes.GenesisDoc, appState map[string]json.RawMessage) error {
var authGenState authtypes.GenesisState
m.cdc.MustUnmarshalJSON(appState[authtypes.ModuleName], &authGenState)
accounts, err := authtypes.UnpackAccounts(authGenState.Accounts)
if err != nil {
return err
}
// Store the profiles
for _, account := range accounts {
profile, ok := account.(*profilestypes.Profile)
if !ok {
continue
}
err = m.db.SaveProfile(types.NewProfile(profile, doc.InitialHeight))
if err != nil {
return err
}
}
var genState profilestypes.GenesisState
m.cdc.MustUnmarshalJSON(appState[profilestypes.ModuleName], &genState)
// Save DTag transfer requests
for _, request := range genState.DTagTransferRequests {
err = m.db.SaveDTagTransferRequest(types.NewDTagTransferRequest(request, doc.InitialHeight))
if err != nil {
return err
}
}
// Save chain links
for _, link := range genState.ChainLinks {
err = m.db.SaveChainLink(types.NewChainLink(link, doc.InitialHeight))
if err != nil {
return err
}
}
// Save application links
for _, link := range genState.ApplicationLinks {
err = m.db.SaveApplicationLink(types.NewApplicationLink(link, doc.InitialHeight))
if err != nil {
return err
}
}
// Save params
err = m.db.SaveProfilesParams(types.NewProfilesParams(genState.Params, doc.InitialHeight))
if err != nil {
return err
}
return nil
}