-
Notifications
You must be signed in to change notification settings - Fork 52
/
hooks.go
93 lines (81 loc) · 2.32 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
83
84
85
86
87
88
89
90
91
92
93
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 NewMultiCommitmentHooks(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) error {
for i := range mh {
err := mh[i].CommitmentChanged(ctx, creator, amount)
if err != nil {
return err
}
}
return nil
}
// Committed is called when staker committed his token
func (mh MultiCommitmentHooks) EdenUncommitted(ctx sdk.Context, creator string, amount sdk.Coin) error {
for i := range mh {
err := mh[i].EdenUncommitted(ctx, creator, amount)
if err != nil {
return err
}
}
return nil
}
func (mh MultiCommitmentHooks) BeforeEdenInitialCommit(ctx sdk.Context, addr sdk.AccAddress) error {
for i := range mh {
err := mh[i].BeforeEdenInitialCommit(ctx, addr)
if err != nil {
return err
}
}
return nil
}
func (mh MultiCommitmentHooks) BeforeEdenBInitialCommit(ctx sdk.Context, addr sdk.AccAddress) error {
for i := range mh {
err := mh[i].BeforeEdenBInitialCommit(ctx, addr)
if err != nil {
return err
}
}
return nil
}
func (mh MultiCommitmentHooks) BeforeEdenCommitChange(ctx sdk.Context, addr sdk.AccAddress) error {
for i := range mh {
err := mh[i].BeforeEdenCommitChange(ctx, addr)
if err != nil {
return err
}
}
return nil
}
func (mh MultiCommitmentHooks) BeforeEdenBCommitChange(ctx sdk.Context, addr sdk.AccAddress) error {
for i := range mh {
err := mh[i].BeforeEdenBCommitChange(ctx, addr)
if err != nil {
return err
}
}
return nil
}
// Committed executes the indicated for committed hook
func (k Keeper) CommitmentChanged(ctx sdk.Context, creator string, amount sdk.Coins) error {
if k.hooks == nil {
return 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) error {
if k.hooks == nil {
return nil
}
return k.hooks.EdenUncommitted(ctx, creator, amount)
}