-
Notifications
You must be signed in to change notification settings - Fork 52
/
hooks.go
45 lines (37 loc) · 1.29 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
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/commitment/types"
)
var _ types.CommitmentHooks = MultiCommitmentHooks{}
// combine multiple commitment hooks, all hook functions are run in array sequence
type MultiCommitmentHooks []types.CommitmentHooks
func NewMultiEpochHooks(hooks ...types.CommitmentHooks) MultiCommitmentHooks {
return hooks
}
// Committed is called when staker committed his token
func (mh MultiCommitmentHooks) CommitmentChanged(ctx sdk.Context, creator string, amount sdk.Coins) {
for i := range mh {
mh[i].CommitmentChanged(ctx, creator, amount)
}
}
// Committed is called when staker committed his token
func (mh MultiCommitmentHooks) EdenUncommitted(ctx sdk.Context, creator string, amount sdk.Coin) {
for i := range mh {
mh[i].EdenUncommitted(ctx, creator, amount)
}
}
// Committed executes the indicated for committed hook
func (k Keeper) AfterCommitmentChange(ctx sdk.Context, creator string, amount sdk.Coins) {
if k.hooks == nil {
return
}
k.hooks.CommitmentChanged(ctx, creator, amount)
}
// Committed executes the indicated for committed hook
func (k Keeper) EdenUncommitted(ctx sdk.Context, creator string, amount sdk.Coin) {
if k.hooks == nil {
return
}
k.hooks.EdenUncommitted(ctx, creator, amount)
}