-
Notifications
You must be signed in to change notification settings - Fork 590
/
hooks.go
61 lines (49 loc) · 2.36 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
package types
import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
)
type LockupHooks interface {
AfterAddTokensToLock(ctx sdk.Context, address sdk.AccAddress, lockID uint64, amount sdk.Coins)
OnTokenLocked(ctx sdk.Context, address sdk.AccAddress, lockID uint64, amount sdk.Coins, lockDuration time.Duration, unlockTime time.Time)
OnStartUnlock(ctx sdk.Context, address sdk.AccAddress, lockID uint64, amount sdk.Coins, lockDuration time.Duration, unlockTime time.Time)
OnTokenUnlocked(ctx sdk.Context, address sdk.AccAddress, lockID uint64, amount sdk.Coins, lockDuration time.Duration, unlockTime time.Time)
OnTokenSlashed(ctx sdk.Context, lockID uint64, amount sdk.Coins)
OnLockupExtend(ctx sdk.Context, lockID uint64, prevDuration time.Duration, newDuration time.Duration)
}
var _ LockupHooks = MultiLockupHooks{}
// combine multiple gamm hooks, all hook functions are run in array sequence.
type MultiLockupHooks []LockupHooks
func NewMultiLockupHooks(hooks ...LockupHooks) MultiLockupHooks {
return hooks
}
func (h MultiLockupHooks) AfterAddTokensToLock(ctx sdk.Context, address sdk.AccAddress, lockID uint64, amount sdk.Coins) {
for i := range h {
h[i].AfterAddTokensToLock(ctx, address, lockID, amount)
}
}
func (h MultiLockupHooks) OnTokenLocked(ctx sdk.Context, address sdk.AccAddress, lockID uint64, amount sdk.Coins, lockDuration time.Duration, unlockTime time.Time) {
for i := range h {
h[i].OnTokenLocked(ctx, address, lockID, amount, lockDuration, unlockTime)
}
}
func (h MultiLockupHooks) OnStartUnlock(ctx sdk.Context, address sdk.AccAddress, lockID uint64, amount sdk.Coins, lockDuration time.Duration, unlockTime time.Time) {
for i := range h {
h[i].OnStartUnlock(ctx, address, lockID, amount, lockDuration, unlockTime)
}
}
func (h MultiLockupHooks) OnTokenUnlocked(ctx sdk.Context, address sdk.AccAddress, lockID uint64, amount sdk.Coins, lockDuration time.Duration, unlockTime time.Time) {
for i := range h {
h[i].OnTokenUnlocked(ctx, address, lockID, amount, lockDuration, unlockTime)
}
}
func (h MultiLockupHooks) OnTokenSlashed(ctx sdk.Context, lockID uint64, amount sdk.Coins) {
for i := range h {
h[i].OnTokenSlashed(ctx, lockID, amount)
}
}
func (h MultiLockupHooks) OnLockupExtend(ctx sdk.Context, lockID uint64, prevDuration, newDuration time.Duration) {
for i := range h {
h[i].OnLockupExtend(ctx, lockID, prevDuration, newDuration)
}
}