/
abci.go
49 lines (43 loc) · 1.38 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
package cfeminter
import (
"time"
"github.com/armon/go-metrics"
"github.com/chain4energy/c4e-chain/x/cfeminter/keeper"
"github.com/chain4energy/c4e-chain/x/cfeminter/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// BeginBlocker mints new tokens for the previous block.
func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
amount, err := k.Mint(ctx)
if err != nil {
k.Logger(ctx).Error("mint error", "error", err.Error())
panic(err)
}
if amount.IsInt64() {
defer telemetry.SetGaugeWithLabels(
[]string{types.ModuleName, "minted_tokens"},
float32(amount.Int64()),
[]metrics.Label{telemetry.NewLabel("denom", k.MintDenom(ctx))},
)
}
inflation, err := k.GetCurrentInflation(ctx)
var inflationStr string
if err != nil {
inflationStr = types.UndefinedInflation
} else {
inflationStr = inflation.String()
}
bondedRatio := k.BondedRatio(ctx).String()
k.Logger(ctx).Debug("minted", "amount", amount, "bondedRatio", bondedRatio, "inflation", inflationStr)
event := &types.EventMint{
BondedRatio: bondedRatio,
Inflation: inflationStr,
Amount: amount.String(),
}
err = ctx.EventManager().EmitTypedEvent(event)
if err != nil {
k.Logger(ctx).Error("mint emit event error", "event", event, "error", err.Error())
}
}