-
Notifications
You must be signed in to change notification settings - Fork 2
/
end_blocker.go
67 lines (55 loc) · 1.53 KB
/
end_blocker.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
package bank
import (
"context"
"encoding/base64"
"strconv"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/bro-n-bro/spacebox-crawler/modules/utils"
"github.com/bro-n-bro/spacebox-crawler/types"
)
var (
base64KeyProposalID = base64.StdEncoding.EncodeToString([]byte(govtypes.AttributeKeyProposalID))
)
func (m *Module) HandleEndBlocker(ctx context.Context, eventsMap types.BlockerEvents, height int64) error {
events, ok := eventsMap[govtypes.EventTypeActiveProposal]
if !ok {
return nil
}
for _, event := range events {
if len(event.Attributes) < 1 {
m.log.Warn().
Int64("height", height).
Str("handler", "HandleEndBlocker").
Msg("not enough attributes in event")
continue
}
for _, attr := range event.Attributes {
if attr.Key == govtypes.AttributeKeyProposalID && attr.Key != base64KeyProposalID {
continue
}
// try to decode value if needed
if attr.Key == base64KeyProposalID {
var err error
attr.Value, err = utils.DecodeToString(attr.Value)
if err != nil {
return err
}
}
pID, err := strconv.ParseUint(attr.Value, 10, 64)
if err != nil {
m.log.Error().Err(err).Str("handler", "HandleEndBlocker").Msg("parse uint error")
return err
}
if err = m.getAndPublishProposal(ctx, pID, ""); err != nil {
m.log.Error().
Err(err).
Int64("height", height).
Str("handler", "HandleEndBlocker").
Msg("get and publish proposal error")
return err
}
return m.getAndPublishTallyResult(ctx, pID, height)
}
}
return nil
}