-
Notifications
You must be signed in to change notification settings - Fork 41
/
event.go
35 lines (31 loc) · 976 Bytes
/
event.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
package helpers
import (
"github.com/tendermint/tendermint/abci/types"
)
type HumanReadableEventAttribute struct {
Key string `json:"key"`
Value string `json:"value"`
Index bool `json:"index,omitempty"`
}
type HumanReadableEvent struct {
Type string `json:"type"`
Attributes []HumanReadableEventAttribute `json:"attributes"`
}
func ReadableEvents(events []types.Event) []HumanReadableEvent {
readableEvents := make([]HumanReadableEvent, len(events))
for _, event := range events {
readableAttributes := make([]HumanReadableEventAttribute, len(event.Attributes))
for i, attribute := range event.Attributes {
readableAttributes[i] = HumanReadableEventAttribute{
Key: string(attribute.Key),
Value: string(attribute.Value),
Index: attribute.Index,
}
}
readableEvents = append(readableEvents, HumanReadableEvent{
Type: event.Type,
Attributes: readableAttributes,
})
}
return readableEvents
}