-
Notifications
You must be signed in to change notification settings - Fork 2
/
block.go
72 lines (59 loc) · 2.01 KB
/
block.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
package distribution
import (
"context"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/pkg/errors"
grpcClient "github.com/bro-n-bro/spacebox-crawler/client/grpc"
"github.com/bro-n-bro/spacebox-crawler/types"
"github.com/bro-n-bro/spacebox/broker/model"
)
func (m *Module) HandleBlock(ctx context.Context, block *types.Block) error {
// TODO: maybe use consensus client for get correct validators?
// g, ctx := errgroup.WithContext(ctx)
// g.Go(func() error {
// return m.updateParams(ctx, block.Height)
// })
/*
TODO:
UpdateValidatorsCommissionAmounts,
UpdateDelegatorsRewardsAmounts (we need info from some storage for these actions)
*/
// if err := g.Wait(); err != nil {
// return err
// }
res, err := m.client.DistributionQueryClient.CommunityPool(ctx, &distrtypes.QueryCommunityPoolRequest{})
if err != nil {
return errors.Wrap(err, "get CommunityPool error")
}
// TODO: test it
if err := m.broker.PublishCommunityPool(ctx, model.CommunityPool{
Height: block.Height,
Coins: m.tbM.MapCoins(types.NewCoinsFromSDKDec(res.Pool)),
}); err != nil {
return errors.Wrap(err, "publish CommunityPool error")
}
return m.updateParams(ctx, block.Height)
}
func (m *Module) updateParams(ctx context.Context, height int64) error {
res, err := m.client.DistributionQueryClient.Params(
ctx,
&distrtypes.QueryParamsRequest{},
grpcClient.GetHeightRequestHeader(height),
)
if err != nil {
return err
}
if err := m.broker.PublishDistributionParams(ctx, model.DistributionParams{
Height: height,
Params: model.RawDistributionParams{
CommunityTax: res.Params.CommunityTax.MustFloat64(),
BaseProposerReward: res.Params.BaseProposerReward.MustFloat64(), //nolint:staticcheck
BonusProposerReward: res.Params.BonusProposerReward.MustFloat64(), //nolint:staticcheck
WithdrawAddrEnabled: res.Params.WithdrawAddrEnabled,
},
}); err != nil {
m.log.Error().Int64("height", height).Err(err).Msg("PublishDistributionParams error")
return err
}
return nil
}