-
Notifications
You must be signed in to change notification settings - Fork 5
/
utils.go
78 lines (66 loc) · 2.28 KB
/
utils.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
package subspaces
import (
"context"
"github.com/forbole/juno/v5/node/remote"
subspacestypes "github.com/desmos-labs/desmos/v7/x/subspaces/types"
"github.com/desmos-labs/athena/v2/types"
)
// updateSubspace updates the stored data for the given subspace at the specified height
func (m *Module) updateSubspace(height int64, subspaceID uint64) error {
// Get the subspace
res, err := m.client.Subspace(
remote.GetHeightRequestContext(context.Background(), height),
subspacestypes.NewQuerySubspaceRequest(subspaceID),
)
if err != nil {
return err
}
// Save the subspace
return m.db.SaveSubspace(types.NewSubspace(res.Subspace, height))
}
// updateSection updates the stored data for the given subspace section at the specified height
func (m *Module) updateSection(height int64, subspaceID uint64, sectionID uint32) error {
// Get the subspace
res, err := m.client.Section(
remote.GetHeightRequestContext(context.Background(), height),
subspacestypes.NewQuerySectionRequest(subspaceID, sectionID),
)
if err != nil {
return err
}
// Save the subspace
return m.db.SaveSection(types.NewSection(res.Section, height))
}
// updateUserGroup updates the stored data for the given user group at the specified height
func (m *Module) updateUserGroup(height int64, subspaceID uint64, groupID uint32) error {
// Get the user group
res, err := m.client.UserGroup(
remote.GetHeightRequestContext(context.Background(), height),
subspacestypes.NewQueryUserGroupRequest(subspaceID, groupID),
)
if err != nil {
return err
}
// Save the user group
return m.db.SaveUserGroup(types.NewUserGroup(res.Group, height))
}
// updateUserPermissions updates the stored permissions for the given user at the specified height
func (m *Module) updateUserPermissions(height int64, subspaceID uint64, sectionID uint32, user string) error {
// Get the permissions
res, err := m.client.UserPermissions(
remote.GetHeightRequestContext(context.Background(), height),
&subspacestypes.QueryUserPermissionsRequest{
SubspaceId: subspaceID,
SectionId: sectionID,
User: user,
},
)
if err != nil {
return err
}
// Save the user permissions
return m.db.SaveUserPermission(types.NewUserPermission(
subspacestypes.NewUserPermission(subspaceID, sectionID, user, res.Permissions),
height,
))
}