@@ -28,11 +28,9 @@ func PatchTxResponses(input []*abci.ExecTxResult) []*abci.ExecTxResult {
2828 panic (err )
2929 }
3030
31- var (
32- anteEvents []abci.Event
33- // if the response data is modified and need to be marshaled back
34- dataDirty bool
35- )
31+ var dataDirty bool
32+ ethTxHashes := make (map [string ]uint64 )
33+
3634 for i , rsp := range txMsgData .MsgResponses {
3735 var response MsgEthereumTxResponse
3836 if rsp .TypeUrl != "/" + proto .MessageName (& response ) {
@@ -43,13 +41,7 @@ func PatchTxResponses(input []*abci.ExecTxResult) []*abci.ExecTxResult {
4341 panic (err )
4442 }
4543
46- anteEvents = append (anteEvents , abci.Event {
47- Type : EventTypeEthereumTx ,
48- Attributes : []abci.EventAttribute {
49- {Key : AttributeKeyEthereumTxHash , Value : response .Hash },
50- {Key : AttributeKeyTxIndex , Value : strconv .FormatUint (txIndex , 10 )},
51- },
52- })
44+ ethTxHashes [response .Hash ] = txIndex
5345
5446 if len (response .Logs ) > 0 {
5547 for _ , log := range response .Logs {
@@ -70,21 +62,32 @@ func PatchTxResponses(input []*abci.ExecTxResult) []*abci.ExecTxResult {
7062 txIndex ++
7163 }
7264
73- if len (anteEvents ) > 0 {
74- // prepend ante events in front to emulate the side effect of `EthEmitEventDecorator`
75- events := make ([]abci.Event , len (anteEvents )+ len (res .Events ))
76- copy (events , anteEvents )
77- copy (events [len (anteEvents ):], res .Events )
78- res .Events = events
65+ for i := range res .Events {
66+ if res .Events [i ].Type == EventTypeEthereumTx {
67+ var txHash string
68+ for _ , attr := range res .Events [i ].Attributes {
69+ if attr .Key == AttributeKeyEthereumTxHash {
70+ txHash = attr .Value
71+ break
72+ }
73+ }
7974
80- if dataDirty {
81- data , err := proto .Marshal (& txMsgData )
82- if err != nil {
83- panic (err )
75+ if idx , ok := ethTxHashes [txHash ]; ok {
76+ res .Events [i ].Attributes = append (res .Events [i ].Attributes , abci.EventAttribute {
77+ Key : AttributeKeyTxIndex ,
78+ Value : strconv .FormatUint (idx , 10 ),
79+ })
8480 }
81+ }
82+ }
8583
86- res .Data = data
84+ if dataDirty {
85+ data , err := proto .Marshal (& txMsgData )
86+ if err != nil {
87+ panic (err )
8788 }
89+
90+ res .Data = data
8891 }
8992 }
9093 return input
0 commit comments