forked from forbole/callisto
-
Notifications
You must be signed in to change notification settings - Fork 1
/
handle_block.go
39 lines (32 loc) · 1008 Bytes
/
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
package gov
import (
"fmt"
juno "github.com/forbole/juno/v2/types"
tmctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/rs/zerolog/log"
)
// HandleBlock implements modules.BlockModule
func (m *Module) HandleBlock(
b *tmctypes.ResultBlock, _ *tmctypes.ResultBlockResults, _ []*juno.Tx, vals *tmctypes.ResultValidators,
) error {
err := m.updateProposals(b.Block.Height, vals)
if err != nil {
log.Error().Str("module", "gov").Int64("height", b.Block.Height).
Err(err).Msg("error while updating proposals")
}
return nil
}
// updateProposals updates the proposals
func (m *Module) updateProposals(height int64, blockVals *tmctypes.ResultValidators) error {
ids, err := m.db.GetOpenProposalsIds()
if err != nil {
log.Error().Err(err).Str("module", "gov").Msg("error while getting open ids")
}
for _, id := range ids {
err = m.UpdateProposal(height, blockVals, id)
if err != nil {
return fmt.Errorf("error while updating proposal: %s", err)
}
}
return nil
}