-
Notifications
You must be signed in to change notification settings - Fork 40
/
utils.go
48 lines (40 loc) · 1.02 KB
/
utils.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
package common
import (
"strconv"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// EvMap is a type alias for SDK events mapping from Attr.Key to the list of values.
type EvMap map[string][]string
// JsDict is a type alias for JSON dictionary.
type JsDict map[string]interface{}
// Message is a simple wrapper data type for each message published to Kafka.
type Message struct {
Key string
Value JsDict
}
// Atoi converts the given string into an int64. Panics on errors.
func Atoi(val string) int64 {
res, err := strconv.ParseInt(val, 10, 64)
if err != nil {
panic(err)
}
return res
}
// Atoui converts the given string into an uint64. Panics on errors.
func Atoui(val string) uint64 {
res, err := strconv.ParseUint(val, 10, 64)
if err != nil {
panic(err)
}
return res
}
func ParseEvents(events sdk.StringEvents) EvMap {
evMap := make(EvMap)
for _, event := range events {
for _, kv := range event.Attributes {
key := event.Type + "." + kv.Key
evMap[key] = append(evMap[key], kv.Value)
}
}
return evMap
}