-
Notifications
You must be signed in to change notification settings - Fork 0
/
abci.go
43 lines (34 loc) · 1.6 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
/*
Copyright [2019] - [2021], PERSISTENCE TECHNOLOGIES PTE. LTD. and the persistenceCore contributors
SPDX-License-Identifier: Apache-2.0
*/
package halving
import (
"fmt"
"strconv"
sdk "github.com/cosmos/cosmos-sdk/types"
mintTypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/incubus-network/fanfury-sdk/v2/x/halving/types"
)
func EndBlocker(ctx sdk.Context, k Keeper) {
params := k.GetParams(ctx)
if params.BlockHeight != 0 && uint64(ctx.BlockHeight())%params.BlockHeight == 0 {
mintParams := k.GetMintingParams(ctx)
newMaxInflation := mintParams.InflationMax.QuoTruncate(sdk.NewDecFromInt(Factor))
newMinInflation := mintParams.InflationMin.QuoTruncate(sdk.NewDecFromInt(Factor))
if newMaxInflation.Sub(newMinInflation).LT(sdk.ZeroDec()) {
panic(fmt.Sprintf("max inflation (%s) must be greater than or equal to min inflation (%s)", newMaxInflation.String(), newMinInflation.String()))
}
updatedParams := mintTypes.NewParams(mintParams.MintDenom, newMaxInflation.Sub(newMinInflation), newMaxInflation, newMinInflation, mintParams.GoalBonded, mintParams.BlocksPerYear)
k.SetMintingParams(ctx, updatedParams)
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeHalving,
sdk.NewAttribute(types.AttributeKeyBlockHeight, strconv.FormatInt(ctx.BlockHeight(), 10)),
sdk.NewAttribute(types.AttributeKeyNewInflationMax, updatedParams.InflationMax.String()),
sdk.NewAttribute(types.AttributeKeyNewInflationMin, updatedParams.InflationMin.String()),
sdk.NewAttribute(types.AttributeKeyNewInflationRateChange, updatedParams.InflationRateChange.String()),
),
)
}
}