-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx_event.go
98 lines (85 loc) · 2.34 KB
/
tx_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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
"strings"
)
type TxEvents []TxEvent
type TxEvent struct {
Type string `json:"type,omitempty"`
Attributes []TxEventAttribute `json:"attributes,omitempty"`
}
type TxEventAttribute struct {
Key string `json:"key,omitempty"`
Value string `json:"value,omitempty"`
}
func ConvertTxEvent(events []abci.Event) TxEvents {
var res []TxEvent
for _, event := range events {
var attributes []TxEventAttribute
for _, attr := range event.Attributes {
attributes = append(attributes, TxEventAttribute{
Key: string(attr.Key),
Value: string(attr.Value),
})
}
res = append(res, TxEvent{
Type: event.Type,
Attributes: attributes,
})
}
return res
}
func (m TxEvents) RemoveUnnecessaryEvmTxEvents() TxEvents {
remove := func() TxEvents {
txEventsTruncatedEvm := make([]TxEvent, 0)
for _, event := range m {
// keep only necessary events
if event.Type == EventTypeEthereumTx {
txEventAttrTruncatedEvm := make([]TxEventAttribute, 0)
for _, attribute := range event.Attributes {
if attribute.Key == AttributeKeyEthereumTxFailed {
txEventAttrTruncatedEvm = append(txEventAttrTruncatedEvm, attribute)
}
}
if len(txEventAttrTruncatedEvm) > 0 {
txEventsTruncatedEvm = append(txEventsTruncatedEvm, TxEvent{
Type: EventTypeEthereumTx,
Attributes: txEventAttrTruncatedEvm,
})
}
continue
}
if event.Type == EventTypeTxLog {
continue
}
if event.Type == sdk.EventTypeMessage {
var ignore bool
for _, attribute := range event.Attributes {
if attribute.Key == sdk.AttributeKeyModule && attribute.Value == AttributeValueCategory {
ignore = true
break
} else if attribute.Key == sdk.AttributeKeyAction && strings.HasSuffix(attribute.Value, "MsgEthereumTx") {
ignore = true
break
}
}
if ignore {
continue
}
}
txEventsTruncatedEvm = append(txEventsTruncatedEvm, event)
}
return txEventsTruncatedEvm
}
for _, event := range m {
if event.Type == sdk.EventTypeMessage {
for _, attribute := range event.Attributes {
if attribute.Key == sdk.AttributeKeyAction && strings.HasSuffix(attribute.Value, "MsgEthereumTx") {
return remove()
}
}
}
}
return m
}