-
Notifications
You must be signed in to change notification settings - Fork 229
/
handle_block.go
54 lines (43 loc) · 1.6 KB
/
handle_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
package distribution
import (
"context"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/desmos-labs/juno/client"
"github.com/rs/zerolog/log"
tmctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/forbole/bdjuno/types"
"github.com/forbole/bdjuno/database"
distrutils "github.com/forbole/bdjuno/modules/distribution/utils"
"github.com/forbole/bdjuno/types/config"
)
// HandleBlock represents a method that is called each time a new block is created
func HandleBlock(cfg *config.Config, block *tmctypes.ResultBlock, client distrtypes.QueryClient, db *database.Db) error {
go updateParams(block.Block.Height, client, db)
// Update the validator commissions
go distrutils.UpdateValidatorsCommissionAmounts(cfg, block.Block.Height, client, db)
// Update the delegators commissions amounts
go distrutils.UpdateDelegatorsRewardsAmounts(cfg, block.Block.Height, client, db)
return nil
}
func updateParams(height int64, distrClient distrtypes.QueryClient, db *database.Db) {
log.Debug().Str("module", "distribution").Int64("height", height).
Msg("updating params")
res, err := distrClient.Params(
context.Background(),
&distrtypes.QueryParamsRequest{},
client.GetHeightRequestHeader(height),
)
if err != nil {
log.Error().Str("module", "distribution").Err(err).
Int64("height", height).
Msg("error while getting params")
return
}
err = db.SaveDistributionParams(types.NewDistributionParams(res.Params, height))
if err != nil {
log.Error().Str("module", "distribution").Err(err).
Int64("height", height).
Msg("error while saving params")
return
}
}