@@ -28,9 +28,11 @@ func PatchTxResponses(input []*abci.ExecTxResult) []*abci.ExecTxResult {
2828 panic (err )
2929 }
3030
31- var dataDirty bool
32- ethTxHashes := make (map [string ]uint64 )
33-
31+ var (
32+ anteEvents []abci.Event
33+ // if the response data is modified and need to be marshaled back
34+ dataDirty bool
35+ )
3436 for i , rsp := range txMsgData .MsgResponses {
3537 var response MsgEthereumTxResponse
3638 if rsp .TypeUrl != "/" + proto .MessageName (& response ) {
@@ -41,7 +43,13 @@ func PatchTxResponses(input []*abci.ExecTxResult) []*abci.ExecTxResult {
4143 panic (err )
4244 }
4345
44- ethTxHashes [response .Hash ] = txIndex
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+ })
4553
4654 if len (response .Logs ) > 0 {
4755 for _ , log := range response .Logs {
@@ -62,32 +70,21 @@ func PatchTxResponses(input []*abci.ExecTxResult) []*abci.ExecTxResult {
6270 txIndex ++
6371 }
6472
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- }
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
7479
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- })
80+ if dataDirty {
81+ data , err := proto .Marshal (& txMsgData )
82+ if err != nil {
83+ panic (err )
8084 }
81- }
82- }
8385
84- if dataDirty {
85- data , err := proto .Marshal (& txMsgData )
86- if err != nil {
87- panic (err )
86+ res .Data = data
8887 }
89-
90- res .Data = data
9188 }
9289 }
9390 return input
0 commit comments