fix: eth json transaction (#4581)

pull/4582/head
Diego Nava 12 months ago committed by GitHub
parent 7be2b0260b
commit b7123fb30e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      rpc/eth/types.go
  2. 2
      rpc/transaction.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) {

@ -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

Loading…
Cancel
Save