-
Notifications
You must be signed in to change notification settings - Fork 46
/
hooks.go
68 lines (54 loc) · 2.7 KB
/
hooks.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
package types
// DONTCOVER
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Event Hooks
// These can be utilized to communicate between a reactions keeper and another
// keeper which must take particular actions when reactions change
// state. The second keeper must implement this interface, which then the
// reactions keeper can call.
// ReactionsHooks event hooks for reactions objects (noalias)
type ReactionsHooks interface {
AfterReactionSaved(ctx sdk.Context, subspaceID uint64, reactionID uint32) // Must be called when a reaction is saved
AfterReactionDeleted(ctx sdk.Context, subspaceID uint64, reactionID uint32) // Must be called when a reaction is deleted
AfterRegisteredReactionSaved(ctx sdk.Context, subspaceID uint64, registeredReactionID uint32) // Must be called when a registered reaction is saved
AfterRegisteredReactionDeleted(ctx sdk.Context, subspaceID uint64, registeredReactionID uint32) // Must be called when a registered reaction is deleted
AfterReactionParamsSaved(ctx sdk.Context, subspaceID uint64) // Must be called when some reaction params are saved
}
// --------------------------------------------------------------------------------------------------------------------
// MultiReactionsHooks combines multiple posts hooks, all hook functions are run in array sequence
type MultiReactionsHooks []ReactionsHooks
func NewMultiReactionsHooks(hooks ...ReactionsHooks) MultiReactionsHooks {
return hooks
}
// AfterReactionSaved implements ReactionsHooks
func (h MultiReactionsHooks) AfterReactionSaved(ctx sdk.Context, subspaceID uint64, reactionID uint32) {
for _, hook := range h {
hook.AfterReactionSaved(ctx, subspaceID, reactionID)
}
}
// AfterReactionDeleted implements ReactionsHooks
func (h MultiReactionsHooks) AfterReactionDeleted(ctx sdk.Context, subspaceID uint64, reactionID uint32) {
for _, hook := range h {
hook.AfterReactionDeleted(ctx, subspaceID, reactionID)
}
}
// AfterRegisteredReactionSaved implements ReactionsHooks
func (h MultiReactionsHooks) AfterRegisteredReactionSaved(ctx sdk.Context, subspaceID uint64, registeredReactionID uint32) {
for _, hook := range h {
hook.AfterRegisteredReactionSaved(ctx, subspaceID, registeredReactionID)
}
}
// AfterRegisteredReactionDeleted implements ReactionsHooks
func (h MultiReactionsHooks) AfterRegisteredReactionDeleted(ctx sdk.Context, subspaceID uint64, registeredReactionID uint32) {
for _, hook := range h {
hook.AfterRegisteredReactionDeleted(ctx, subspaceID, registeredReactionID)
}
}
// AfterReactionParamsSaved implements ReactionsHooks
func (h MultiReactionsHooks) AfterReactionParamsSaved(ctx sdk.Context, subspaceID uint64) {
for _, hook := range h {
hook.AfterReactionParamsSaved(ctx, subspaceID)
}
}