@@ -268,7 +268,8 @@ func (e *PublicAPI) GetBlockTransactionCountByHash(hash common.Hash) *hexutil.Ui
268268 return nil
269269 }
270270
271- n := hexutil .Uint (len (resBlock .Block .Txs ))
271+ ethMsgs := e .backend .GetEthereumMsgsFromTendermintBlock (resBlock )
272+ n := hexutil .Uint (len (ethMsgs ))
272273 return & n
273274}
274275
@@ -286,7 +287,8 @@ func (e *PublicAPI) GetBlockTransactionCountByNumber(blockNum rpctypes.BlockNumb
286287 return nil
287288 }
288289
289- n := hexutil .Uint (len (resBlock .Block .Txs ))
290+ ethMsgs := e .backend .GetEthereumMsgsFromTendermintBlock (resBlock )
291+ n := hexutil .Uint (len (ethMsgs ))
290292 return & n
291293}
292294
@@ -526,23 +528,13 @@ func (e *PublicAPI) GetTransactionByBlockHashAndIndex(hash common.Hash, idx hexu
526528 }
527529
528530 i := int (idx )
529- if i >= len (resBlock .Block .Txs ) {
531+ ethMsgs := e .backend .GetEthereumMsgsFromTendermintBlock (resBlock )
532+ if i >= len (ethMsgs ) {
530533 e .logger .Debug ("block txs index out of bound" , "index" , i )
531534 return nil , nil
532535 }
533536
534- txBz := resBlock .Block .Txs [i ]
535- tx , err := e .clientCtx .TxConfig .TxDecoder ()(txBz )
536- if err != nil {
537- e .logger .Debug ("decoding failed" , "error" , err .Error ())
538- return nil , fmt .Errorf ("failed to decode tx: %w" , err )
539- }
540-
541- msg , err := evmtypes .UnwrapEthereumMsg (& tx )
542- if err != nil {
543- e .logger .Debug ("invalid tx" , "error" , err .Error ())
544- return nil , err
545- }
537+ msg := ethMsgs [i ]
546538
547539 return rpctypes .NewTransactionFromMsg (
548540 msg ,
@@ -569,23 +561,13 @@ func (e *PublicAPI) GetTransactionByBlockNumberAndIndex(blockNum rpctypes.BlockN
569561 }
570562
571563 i := int (idx )
572- if i >= len (resBlock .Block .Txs ) {
564+ ethMsgs := e .backend .GetEthereumMsgsFromTendermintBlock (resBlock )
565+ if i >= len (ethMsgs ) {
573566 e .logger .Debug ("block txs index out of bound" , "index" , i )
574567 return nil , nil
575568 }
576569
577- txBz := resBlock .Block .Txs [i ]
578- tx , err := e .clientCtx .TxConfig .TxDecoder ()(txBz )
579- if err != nil {
580- e .logger .Debug ("decoding failed" , "error" , err .Error ())
581- return nil , fmt .Errorf ("failed to decode tx: %w" , err )
582- }
583-
584- msg , err := evmtypes .UnwrapEthereumMsg (& tx )
585- if err != nil {
586- e .logger .Debug ("invalid tx" , "error" , err .Error ())
587- return nil , err
588- }
570+ msg := ethMsgs [i ]
589571
590572 return rpctypes .NewTransactionFromMsg (
591573 msg ,
@@ -598,11 +580,12 @@ func (e *PublicAPI) GetTransactionByBlockNumberAndIndex(blockNum rpctypes.BlockN
598580
599581// GetTransactionReceipt returns the transaction receipt identified by hash.
600582func (e * PublicAPI ) GetTransactionReceipt (hash common.Hash ) (map [string ]interface {}, error ) {
601- e .logger .Debug ("eth_getTransactionReceipt" , "hash" , hash .Hex ())
583+ hexTx := hash .Hex ()
584+ e .logger .Debug ("eth_getTransactionReceipt" , "hash" , hexTx )
602585
603586 res , err := e .backend .GetTxByEthHash (hash )
604587 if err != nil {
605- e .logger .Debug ("tx not found" , "hash" , hash . Hex () , "error" , err .Error ())
588+ e .logger .Debug ("tx not found" , "hash" , hexTx , "error" , err .Error ())
606589 return nil , nil
607590 }
608591
@@ -656,7 +639,17 @@ func (e *PublicAPI) GetTransactionReceipt(hash common.Hash) (map[string]interfac
656639
657640 logs , err := e .backend .GetTransactionLogs (hash )
658641 if err != nil {
659- e .logger .Debug ("logs not found" , "hash" , hash .Hex (), "error" , err .Error ())
642+ e .logger .Debug ("logs not found" , "hash" , hexTx , "error" , err .Error ())
643+ }
644+
645+ // get eth index based on block's txs
646+ var txIndex uint64
647+ msgs := e .backend .GetEthereumMsgsFromTendermintBlock (resBlock )
648+ for i := range msgs {
649+ if msgs [i ].Hash == hexTx {
650+ txIndex = uint64 (i )
651+ break
652+ }
660653 }
661654
662655 receipt := map [string ]interface {}{
@@ -677,7 +670,7 @@ func (e *PublicAPI) GetTransactionReceipt(hash common.Hash) (map[string]interfac
677670 // transaction corresponding to this receipt.
678671 "blockHash" : common .BytesToHash (resBlock .Block .Header .Hash ()).Hex (),
679672 "blockNumber" : hexutil .Uint64 (res .Height ),
680- "transactionIndex" : hexutil .Uint64 (res . Index ),
673+ "transactionIndex" : hexutil .Uint64 (txIndex ),
681674
682675 // sender and receiver (contract or EOA) addreses
683676 "from" : from ,
@@ -696,7 +689,7 @@ func (e *PublicAPI) GetTransactionReceipt(hash common.Hash) (map[string]interfac
696689 return receipt , nil
697690}
698691
699- // PendingTransactions returns the transactions that are in the transaction pool
692+ // GetPendingTransactions returns the transactions that are in the transaction pool
700693// and have a from address that is one of the accounts this node manages.
701694func (e * PublicAPI ) GetPendingTransactions () ([]* rpctypes.RPCTransaction , error ) {
702695 e .logger .Debug ("eth_getPendingTransactions" )
0 commit comments