@@ -2,6 +2,7 @@ package backend
22
33import (
44 "fmt"
5+ "math"
56 "math/big"
67 "strconv"
78
@@ -568,6 +569,7 @@ func (b *Backend) GetBlockReceipts(
568569 result [i ], err = b .formatTxReceipt (
569570 msg ,
570571 txResult ,
572+ resBlock ,
571573 blockRes ,
572574 blockHash ,
573575 )
@@ -582,6 +584,7 @@ func (b *Backend) GetBlockReceipts(
582584func (b * Backend ) formatTxReceipt (
583585 ethMsg * evmtypes.MsgEthereumTx ,
584586 txResult * cosmosevmtypes.TxResult ,
587+ resBlock * cmtrpctypes.ResultBlock ,
585588 blockRes * cmtrpctypes.ResultBlockResults ,
586589 blockHeaderHash string ,
587590) (map [string ]interface {}, error ) {
@@ -626,6 +629,20 @@ func (b *Backend) formatTxReceipt(
626629 b .Logger .Debug ("failed to parse logs" , "hash" , ethMsg .Hash ().String (), "error" , err .Error ())
627630 }
628631
632+ if txResult .EthTxIndex == - 1 {
633+ // Fallback to find tx index by iterating all valid eth transactions
634+ msgs := b .EthMsgsFromCometBlock (resBlock , blockRes )
635+ for i := range msgs {
636+ if msgs [i ].Hash () == ethTx .Hash () {
637+ if i > math .MaxInt32 {
638+ return nil , errors .New ("tx index overflow" )
639+ }
640+ txResult .EthTxIndex = int32 (i ) //#nosec G115 -- checked for int overflow already
641+ break
642+ }
643+ }
644+ }
645+
629646 // return error if still unable to find the eth tx index
630647 if txResult .EthTxIndex == - 1 {
631648 return nil , fmt .Errorf ("can't find index of ethereum tx" )
0 commit comments