diff --git a/rpc/eth/types.go b/rpc/eth/types.go index f76aa4442..f1ad725eb 100644 --- a/rpc/eth/types.go +++ b/rpc/eth/types.go @@ -110,6 +110,37 @@ func NewTransaction( } return result, nil } +func NewTransactionFromTransaction( + tx *types.Transaction, blockHash common.Hash, + blockNumber uint64, timestamp uint64, index uint64, +) (*Transaction, error) { + from, err := tx.SenderAddress() + if err != nil { + return nil, fmt.Errorf("unable to get sender address: %w", err) + } + v, r, s := tx.RawSignatureValues() + + result := &Transaction{ + From: from, + Gas: hexutil.Uint64(tx.GasLimit()), + GasPrice: (*hexutil.Big)(tx.GasPrice()), + Hash: tx.Hash(), + Input: hexutil.Bytes(tx.Data()), + Nonce: hexutil.Uint64(tx.Nonce()), + To: tx.To(), + Value: (*hexutil.Big)(tx.Value()), + Timestamp: hexutil.Uint64(timestamp), + V: (*hexutil.Big)(v), + R: (*hexutil.Big)(r), + S: (*hexutil.Big)(s), + } + if blockHash != (common.Hash{}) { + result.BlockHash = &blockHash + result.BlockNumber = (*hexutil.Big)(new(big.Int).SetUint64(blockNumber)) + result.TransactionIndex = (*hexutil.Uint64)(&index) + } + return result, nil +} // NewReceipt returns the RPC data for a new receipt func NewReceipt(tx *types.EthTransaction, blockHash common.Hash, blockNumber, blockIndex uint64, receipt *types.Receipt) (map[string]interface{}, error) { diff --git a/rpc/transaction.go b/rpc/transaction.go index 8ea211d6a..7ee27e7a9 100644 --- a/rpc/transaction.go +++ b/rpc/transaction.go @@ -236,7 +236,7 @@ func (s *PublicTransactionService) newRPCTransaction(tx *types.Transaction, bloc } return NewStructuredResponse(tx) case Eth: - tx, err := eth.NewTransaction(tx.ConvertToEth(), blockHash, blockNumber, timestamp, index) + tx, err := eth.NewTransactionFromTransaction(tx, blockHash, blockNumber, timestamp, index) if err != nil { DoMetricRPCQueryInfo(GetTransactionByHash, FailedNumber) return nil, err