-
Notifications
You must be signed in to change notification settings - Fork 2
/
block.go
79 lines (67 loc) · 2.53 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
73
74
75
76
77
78
79
package mint
import (
"context"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/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 {
paramsResp, err := m.client.MintQueryClient.Params(
ctx,
&minttypes.QueryParamsRequest{},
grpcClient.GetHeightRequestHeader(block.Height),
)
if err != nil {
m.log.Error().Err(err).Int64("height", block.Height).Msg("error while getting params")
return err
}
// todo: call panic: invalid Go type types.Dec for field cosmos.mint.v1beta1.QueryInflationResponse.inflation
// inflationResp, err := m.client.MintQueryClient.Inflation(
// ctx,
// &minttypes.QueryInflationRequest{},
// grpcClient.GetHeightRequestHeader(block.Height),
// )
// if err != nil {
// m.log.Error().Err(err).Int64("height", block.Height).Msg("error while getting inflation")
// return err
// }
// _ = inflationResp
// m.client.MintQueryClient.AnnualProvisions()
// TODO: maybe check diff from mongo in my side?
// TODO: test it
if err = m.broker.PublishMintParams(ctx, model.MintParams{
Height: block.Height,
Params: model.RawMintParams{
MintDenom: paramsResp.Params.MintDenom,
InflationRateChange: paramsResp.Params.InflationRateChange.MustFloat64(),
InflationMax: paramsResp.Params.InflationMax.MustFloat64(),
InflationMin: paramsResp.Params.InflationMin.MustFloat64(),
GoalBonded: paramsResp.Params.GoalBonded.MustFloat64(),
BlocksPerYear: paramsResp.Params.BlocksPerYear,
},
}); err != nil {
return errors.Wrap(err, "PublishMintParams error")
}
// TODO: got a panic: invalid Go type types.Dec for field
// cosmos.mint.v1beta1.QueryAnnualProvisionsResponse.annual_provisions
// annualProvResp, err := m.client.MintQueryClient.AnnualProvisions(
// ctx,
// &minttypes.QueryAnnualProvisionsRequest{},
// grpcClient.GetHeightRequestHeader(block.Height),
// )
// if err != nil {
// m.log.Error().Err(err).Int64("height", block.Height).Msg("error while annual provision")
// return err
// }
// var annualProvision float64
// if !annualProvResp.AnnualProvisions.IsNil() {
// annualProvision = annualProvResp.AnnualProvisions.MustFloat64()
// }
// if err := m.broker.PublishAnnualProvision(ctx,
// m.tbM.MapAnnualProvision(block.Height, annualProvision)); err != nil {
// return errors.Wrap(err, "PublishAnnualProvision error")
// }
return nil
}