-
Notifications
You must be signed in to change notification settings - Fork 6
/
abci.go
40 lines (34 loc) · 1.3 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
package cfedistributor
import (
"time"
"github.com/chain4energy/c4e-chain/x/cfedistributor/keeper"
"github.com/chain4energy/c4e-chain/x/cfedistributor/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
subDistributors := k.GetParams(ctx).SubDistributors
states := k.GetAllStates(ctx)
for _, subDistributor := range subDistributors {
allCoinsToDistribute := k.PrepareCoinsToDistribute(subDistributor.Sources, ctx, states, subDistributor.Name)
if allCoinsToDistribute.IsZero() {
continue
}
newStates, distributionEvents, burnEvent := k.StartDistributionProcess(ctx, &states, allCoinsToDistribute, subDistributor)
for _, event := range distributionEvents {
err := ctx.EventManager().EmitTypedEvent(event)
if err != nil {
k.Logger(ctx).Error("distributions emit event error", "event", event, "error", err.Error())
}
}
if burnEvent != nil {
err := ctx.EventManager().EmitTypedEvent(burnEvent)
if err != nil {
k.Logger(ctx).Error("distributions emit event error", "distribution_burn", burnEvent, "error", err.Error())
}
}
states = *newStates
}
k.SendCoinsFromStates(ctx, states)
}