-
Notifications
You must be signed in to change notification settings - Fork 0
/
abci.go
61 lines (51 loc) · 1.71 KB
/
abci.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 pre_staking
import (
sdk "github.com/ci123chain/ci123chain/pkg/abci/types"
"github.com/ci123chain/ci123chain/pkg/pre_staking/keeper"
"github.com/ci123chain/ci123chain/pkg/pre_staking/types"
"math/big"
)
const (
CheckRecordWindow = 20000
baseMonth = 720
)
func BeginBlock() {}
func EndBlock(ctx sdk.Context, k keeper.PreStakingKeeper) {
UpdateDeadlineRecord(ctx, k)
}
func UpdateDeadlineRecord(ctx sdk.Context, ps keeper.PreStakingKeeper) {
iterator := ps.Iter(ctx)
prune := ctx.BlockHeight()%CheckRecordWindow == 0
for ; iterator.Valid(); iterator.Next() {
v := iterator.Value()
if v != nil {
sv := ps.UnmarshalStakingVault(iterator.Value())
if sv.EndTime.Before(ctx.BlockTime()) && !sv.Processed {
amount, err := ps.RemoveDeadlineDelegationAndWithdraw(ctx, sv.Validator, sv.Delegator, sv.Amount)
if err != nil {
panic(err)
}
moduleAcc := ps.SupplyKeeper.GetModuleAccount(ctx, types.ModuleName)
err = ps.AccountKeeper.Transfer(ctx, moduleAcc.GetAddress(), sv.Delegator, sdk.NewCoins(sdk.NewChainCoin(amount)))
if err != nil {
panic(err)
}
var z = sv.Amount.Amount.BigInt()
base := int64(sv.StorageTime.Hours()) / baseMonth
burnTokens := z.Mul(z, big.NewInt(base))
if tokenmanager := ps.GetTokenManager(ctx); len(tokenmanager) > 0 {
err = ps.SupplyKeeper.BurnEVMCoin(ctx, types.ModuleName, sdk.HexToAddress(tokenmanager), sv.Delegator, burnTokens)
if err != nil {
ctx.Logger().Warn("Burn evm coin failed")
}
} else {
ctx.Logger().Warn("StakingToken Address not set")
}
ps.UpdateStakingRecordProcessed(ctx, iterator.Key())
}
if prune && sv.Processed{
ps.DeleteStakingVault(ctx, iterator.Key())
}
}
}
}