-
Notifications
You must be signed in to change notification settings - Fork 5
/
hooks.go
82 lines (67 loc) · 2.67 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package types
import (
time "time"
sdk "github.com/cosmos/cosmos-sdk/types"
)
type IncentiveHooks interface {
AfterCreateGauge(ctx sdk.Context, gaugeId uint64)
AfterAddToGauge(ctx sdk.Context, gaugeId uint64)
AfterStartDistribution(ctx sdk.Context, gaugeId uint64)
AfterFinishDistribution(ctx sdk.Context, gaugeId uint64)
AfterEpochDistribution(ctx sdk.Context)
AfterAddTokensToStake(ctx sdk.Context, address sdk.AccAddress, stakeID uint64, amount sdk.Coins)
OnTokenStaked(ctx sdk.Context, address sdk.AccAddress, stakeID uint64, amount sdk.Coins, unstakeTime time.Time)
OnTokenUnstaked(ctx sdk.Context, address sdk.AccAddress, stakeID uint64, amount sdk.Coins, unstakeTime time.Time)
}
var _ IncentiveHooks = MultiIncentiveHooks{}
// MultiIncentiveHooks combines multiple incentive hooks. All hook functions are run in array sequence.
type MultiIncentiveHooks []IncentiveHooks
// NewMultiIncentiveHooks combines multiple incentive hooks into a single IncentiveHooks array.
func NewMultiIncentiveHooks(hooks ...IncentiveHooks) MultiIncentiveHooks {
return hooks
}
func (h MultiIncentiveHooks) AfterCreateGauge(ctx sdk.Context, gaugeID uint64) {
for i := range h {
h[i].AfterCreateGauge(ctx, gaugeID)
}
}
func (h MultiIncentiveHooks) AfterAddToGauge(ctx sdk.Context, gaugeID uint64) {
for i := range h {
h[i].AfterAddToGauge(ctx, gaugeID)
}
}
func (h MultiIncentiveHooks) AfterStartDistribution(ctx sdk.Context, gaugeID uint64) {
for i := range h {
h[i].AfterStartDistribution(ctx, gaugeID)
}
}
func (h MultiIncentiveHooks) AfterFinishDistribution(ctx sdk.Context, gaugeID uint64) {
for i := range h {
h[i].AfterFinishDistribution(ctx, gaugeID)
}
}
func (h MultiIncentiveHooks) AfterEpochDistribution(ctx sdk.Context) {
for i := range h {
h[i].AfterEpochDistribution(ctx)
}
}
func (h MultiIncentiveHooks) AfterAddTokensToStake(ctx sdk.Context, address sdk.AccAddress, stakeID uint64, amount sdk.Coins) {
for i := range h {
h[i].AfterAddTokensToStake(ctx, address, stakeID, amount)
}
}
func (h MultiIncentiveHooks) OnTokenStaked(ctx sdk.Context, address sdk.AccAddress, stakeID uint64, amount sdk.Coins, unstakeTime time.Time) {
for i := range h {
h[i].OnTokenStaked(ctx, address, stakeID, amount, unstakeTime)
}
}
func (h MultiIncentiveHooks) OnTokenUnstaked(ctx sdk.Context, address sdk.AccAddress, stakeID uint64, amount sdk.Coins, unstakeTime time.Time) {
for i := range h {
h[i].OnTokenUnstaked(ctx, address, stakeID, amount, unstakeTime)
}
}
// func (h MultiIncentiveHooks) OnStakeupExtend(ctx sdk.Context, stakeID uint64, prevDuration, newDuration time.Duration) {
// for i := range h {
// h[i].OnStakeupExtend(ctx, stakeID, prevDuration, newDuration)
// }
// }