-
Notifications
You must be signed in to change notification settings - Fork 0
/
abci.go
74 lines (64 loc) · 2.62 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
62
63
64
65
66
67
68
69
70
71
72
73
74
package mint
import (
sdk "github.com/ci123chain/ci123chain/pkg/abci/types"
"github.com/ci123chain/ci123chain/pkg/mint/keeper"
"github.com/ci123chain/ci123chain/pkg/mint/types"
)
func BeginBlocker(ctx sdk.Context, k keeper.MinterKeeper) {
// fetch stored minter & params
minter := k.GetMinter(ctx)
params := k.GetParams(ctx)
// recalculate inflation rate
totalStakingSupply := k.StakingTokenSupply(ctx)
bondedRatio := k.BondedRatio(ctx)
minter.Inflation = minter.NextInflationRate(params, bondedRatio)
/*fmt.Printf("bonded ratio = %s\n", bondedRatio.String())
fmt.Printf("minter.Inflation = %s\n", minter.Inflation.String())*/
minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalStakingSupply)
//fmt.Printf("minter.AnnualProvisions = %s\n", minter.AnnualProvisions.String())
k.SetMinter(ctx, minter)
// mint coins, update supply
mintedCoin := minter.BlockProvision(params)
//mintedCoins := sdk.NewCoins(mintedCoin)
//fmt.Printf("mintedCoin = %v\n", mintedCoin.Amount.Uint64())
err := k.MintCoins(ctx, sdk.NewCoins(mintedCoin))
if err != nil {
panic(err)
}
// send the minted coins to the fee collator account
err = k.AddCollectedFees(ctx, mintedCoin)
if err != nil {
panic(err)
}
k.SetLatestMintedCoin(ctx, mintedCoin)
//ctx.EventManager().EmitEvent(
// sdk.NewEvent(
// types.EventTypeMint,
// sdk.NewAttribute(types.AttributeKeyBondedRatio, bondedRatio.String()),
// sdk.NewAttribute(types.AttributeKeyInflation, minter.Inflation.String()),
// sdk.NewAttribute(types.AttributeKeyAnnualProvisions, minter.AnnualProvisions.String()),
// sdk.NewAttribute(sdk.AttributeKeyAmount, mintedCoin.Amount.String()),
// ),
//)
}
func EndBlocker(ctx sdk.Context, k keeper.MinterKeeper) {
latestMintedCoin := k.GetLatestMintedCoin(ctx)
//events := make([]abci.Event, 0)
totalStakingSupply := k.StakingTokenSupply(ctx)
allbonded := k.AllBonded(ctx)
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeMint,
sdk.NewAttribute([]byte(sdk.AttributeKeyTotalSupply), []byte(totalStakingSupply.String())),
sdk.NewAttribute([]byte(types.AttributeKeyLatestMinted), []byte(latestMintedCoin.Amount.String())),
sdk.NewAttribute([]byte(types.AttributeAllBonded), []byte(allbonded.Amount.String())),
))
//event := abci.Event(sdk.NewEvent(
// types.EventTypeMint,
// sdk.NewAttribute([]byte(sdk.AttributeKeyTotalSupply), []byte(totalStakingSupply.String())),
// sdk.NewAttribute([]byte(types.AttributeKeyLatestMinted), []byte(latestMintedCoin.Amount.String())),
// sdk.NewAttribute([]byte(types.AttributeAllBonded), []byte(allbonded.Amount.String())),
//))
//events = append(events, event)
//return events
}