-
Notifications
You must be signed in to change notification settings - Fork 1
/
epochs.go
50 lines (37 loc) · 1.15 KB
/
epochs.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
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
appparams "github.com/celinium-network/celinium/app/params"
epochstypes "github.com/celinium-network/celinium/x/epochs/types"
)
type Hooks struct {
k Keeper
}
// AfterEpochEnd implements types.EpochHooks
func (Hooks) AfterEpochEnd(_ sdk.Context, _ string, _ int64) {
}
// BeforeEpochStart implements types.EpochHooks
func (h Hooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) {
if epochNumber < 0 {
return
}
epoch := uint64(epochNumber)
switch epochIdentifier {
case appparams.DelegationEpochIdentifier:
h.k.CreateProxyDelegationForEpoch(ctx, epoch)
proxyDelegations := h.k.GetAllProxyDelegation(ctx)
h.k.ProcessProxyDelegation(ctx, epoch, proxyDelegations)
h.k.UpdateRedeemRate(ctx, proxyDelegations)
case appparams.UndelegationEpochIdentifier:
h.k.CreateProxyUnbondingForEpoch(ctx, epoch)
h.k.ProcessUndelegationEpoch(ctx, epoch)
case appparams.ReinvestEpochIdentifier:
h.k.SetDistriWithdrawAddress(ctx)
h.k.StartReinvest(ctx)
default:
}
}
var _ epochstypes.EpochHooks = Hooks{}
func (k Keeper) Hooks() Hooks {
return Hooks{k}
}