-
Notifications
You must be signed in to change notification settings - Fork 119
/
events.go
37 lines (33 loc) · 972 Bytes
/
events.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
package tendermint
import (
"encoding/base64"
abcitypes "github.com/cometbft/cometbft/abci/types"
)
// AttributeValue returns an event attribute value given the eventType and attribute key tuple.
// In the event of duplicate types and keys, returns the first attribute value found.
// If not found, returns empty string and false.
func AttributeValue(events []abcitypes.Event, eventType, attrKey string) (string, bool) {
for _, event := range events {
if event.Type != eventType {
continue
}
for _, attr := range event.Attributes {
if attr.Key == attrKey {
return attr.Value, true
}
// tendermint < v0.37-alpha returns base64 encoded strings in events.
key, err := base64.StdEncoding.DecodeString(attr.Key)
if err != nil {
continue
}
if string(key) == attrKey {
value, err := base64.StdEncoding.DecodeString(attr.Value)
if err != nil {
continue
}
return string(value), true
}
}
}
return "", false
}