-
Notifications
You must be signed in to change notification settings - Fork 5
/
utils.go
71 lines (59 loc) · 2.14 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
package reactions
import (
"context"
juno "github.com/forbole/juno/v5/types"
"github.com/forbole/juno/v5/node/remote"
reactionstypes "github.com/desmos-labs/desmos/v6/x/reactions/types"
"github.com/desmos-labs/athena/types"
)
func (m *Module) GetReactionID(tx *juno.Tx, index int) (uint32, error) {
event, err := tx.FindEventByType(index, reactionstypes.EventTypeAddReaction)
if err != nil {
return 0, err
}
reactionIDStr, err := tx.FindAttributeByKey(event, reactionstypes.AttributeKeyReactionID)
if err != nil {
return 0, err
}
return reactionstypes.ParseReactionID(reactionIDStr)
}
func (m *Module) GetReaction(height int64, subspaceID uint64, postID uint64, reactionID uint32) (types.Reaction, error) {
res, err := m.client.Reaction(
remote.GetHeightRequestContext(context.Background(), height),
&reactionstypes.QueryReactionRequest{
SubspaceId: subspaceID,
PostId: postID,
ReactionId: reactionID,
},
)
if err != nil {
return types.Reaction{}, err
}
return types.NewReaction(res.Reaction, height), nil
}
// updateRegisteredReaction updates the stored data about the given registered reaction at the specified height
func (m *Module) updateRegisteredReaction(height int64, subspaceID uint64, reactionID uint32) error {
// Get the registered reaction
res, err := m.client.RegisteredReaction(
remote.GetHeightRequestContext(context.Background(), height),
&reactionstypes.QueryRegisteredReactionRequest{SubspaceId: subspaceID, ReactionId: reactionID},
)
if err != nil {
return err
}
// Save the registered reaction
return m.db.SaveRegisteredReaction(types.NewRegisteredReaction(res.RegisteredReaction, height))
}
// updateReactionParams updates the stored data about the given reaction params at the specified height
func (m *Module) updateReactionParams(height int64, subspaceID uint64) error {
// Get the params
res, err := m.client.ReactionsParams(
remote.GetHeightRequestContext(context.Background(), height),
&reactionstypes.QueryReactionsParamsRequest{SubspaceId: subspaceID},
)
if err != nil {
return err
}
// Save the params
return m.db.SaveReactionParams(types.NewReactionParams(res.Params, height))
}