-
Notifications
You must be signed in to change notification settings - Fork 5
/
handle_genesis.go
59 lines (48 loc) · 1.44 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
package subspaces
import (
"encoding/json"
"github.com/desmos-labs/athena/v2/types"
tmtypes "github.com/cometbft/cometbft/types"
subspacestypes "github.com/desmos-labs/desmos/v7/x/subspaces/types"
)
// HandleGenesis implements modules.GenesisModule
func (m *Module) HandleGenesis(doc *tmtypes.GenesisDoc, appState map[string]json.RawMessage) error {
var genState subspacestypes.GenesisState
m.cdc.MustUnmarshalJSON(appState[subspacestypes.ModuleName], &genState)
// Save subspaces
for _, subspace := range genState.Subspaces {
err := m.db.SaveSubspace(types.NewSubspace(subspace, doc.InitialHeight))
if err != nil {
return err
}
}
// Save sections
for _, section := range genState.Sections {
err := m.db.SaveSection(types.NewSection(section, doc.InitialHeight))
if err != nil {
return err
}
}
// Save user permissions
for _, permission := range genState.UserPermissions {
err := m.db.SaveUserPermission(types.NewUserPermission(permission, doc.InitialHeight))
if err != nil {
return err
}
}
// Save user groups
for _, group := range genState.UserGroups {
err := m.db.SaveUserGroup(types.NewUserGroup(group, doc.InitialHeight))
if err != nil {
return err
}
}
// Save user group members
for _, entry := range genState.UserGroupsMembers {
err := m.db.AddUserToGroup(types.NewUserGroupMember(entry.SubspaceID, entry.GroupID, entry.User, doc.InitialHeight))
if err != nil {
return err
}
}
return nil
}