2023-07-08 17:01:26 +00:00
package jsonrpc
2020-10-12 14:17:34 +00:00
2020-10-14 15:59:42 +00:00
import (
2021-05-04 05:51:28 +00:00
"bytes"
2020-10-14 15:59:42 +00:00
"context"
2023-08-18 16:10:35 +00:00
"fmt"
2021-07-01 04:29:32 +00:00
"math/big"
2020-10-12 14:17:34 +00:00
2023-01-27 04:39:34 +00:00
"github.com/ledgerwatch/erigon-lib/common"
2023-04-13 11:19:02 +00:00
"github.com/ledgerwatch/erigon-lib/common/hexutility"
2021-07-01 21:31:14 +00:00
"github.com/ledgerwatch/erigon-lib/gointerfaces"
"github.com/ledgerwatch/erigon-lib/gointerfaces/txpool"
"github.com/ledgerwatch/erigon-lib/gointerfaces/types"
2023-01-13 18:12:18 +00:00
2021-05-20 18:25:53 +00:00
"github.com/ledgerwatch/erigon/common/hexutil"
"github.com/ledgerwatch/erigon/core/rawdb"
types2 "github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/rpc"
2022-06-14 13:29:49 +00:00
"github.com/ledgerwatch/erigon/turbo/rpchelper"
2020-10-14 15:59:42 +00:00
)
2020-10-24 17:03:52 +00:00
// GetTransactionByHash implements eth_getTransactionByHash. Returns information about a transaction given the transaction's hash.
2023-01-27 04:39:34 +00:00
func ( api * APIImpl ) GetTransactionByHash ( ctx context . Context , txnHash common . Hash ) ( * RPCTransaction , error ) {
2021-04-03 06:26:00 +00:00
tx , err := api . db . BeginRo ( ctx )
2020-10-14 15:59:42 +00:00
if err != nil {
return nil , err
}
defer tx . Rollback ( )
2022-02-10 08:36:24 +00:00
chainConfig , err := api . chainConfig ( tx )
2022-01-06 11:22:59 +00:00
if err != nil {
return nil , err
}
2022-02-10 08:36:24 +00:00
// https://infura.io/docs/ethereum/json-rpc/eth-getTransactionByHash
2022-07-09 03:15:22 +00:00
blockNum , ok , err := api . txnLookup ( ctx , tx , txnHash )
2021-07-11 05:25:21 +00:00
if err != nil {
return nil , err
}
2022-12-12 13:26:00 +00:00
// Private API returns 0 if transaction is not found.
if blockNum == 0 && chainConfig . Bor != nil {
2023-08-18 16:10:35 +00:00
blockNum , ok , err = api . _blockReader . EventLookup ( ctx , tx , txnHash )
2022-12-12 13:26:00 +00:00
if err != nil {
return nil , err
}
2023-08-18 16:10:35 +00:00
fmt . Printf ( "Found block num %d, ok %t\n" , blockNum , ok )
2022-12-12 13:26:00 +00:00
}
2023-01-28 21:20:08 +00:00
if ok {
2023-05-27 09:39:14 +00:00
block , err := api . blockByNumberWithSenders ( ctx , tx , blockNum )
2022-02-10 08:36:24 +00:00
if err != nil {
return nil , err
}
if block == nil {
return nil , nil
}
blockHash := block . Hash ( )
var txnIndex uint64
var txn types2 . Transaction
for i , transaction := range block . Transactions ( ) {
2022-07-09 03:15:22 +00:00
if transaction . Hash ( ) == txnHash {
2022-02-10 08:36:24 +00:00
txn = transaction
txnIndex = uint64 ( i )
break
}
2022-01-07 13:52:38 +00:00
}
2021-07-01 04:29:32 +00:00
2022-02-10 08:36:24 +00:00
// Add GasPrice for the DynamicFeeTransaction
var baseFee * big . Int
2023-01-27 04:39:34 +00:00
if chainConfig . IsLondon ( blockNum ) && blockHash != ( common . Hash { } ) {
2022-02-10 08:36:24 +00:00
baseFee = block . BaseFee ( )
}
2021-07-01 04:29:32 +00:00
2022-03-07 03:24:21 +00:00
// if no transaction was found then we return nil
if txn == nil {
2022-07-09 03:15:22 +00:00
if chainConfig . Bor == nil {
return nil , nil
2022-07-07 08:40:50 +00:00
}
2023-08-18 16:10:35 +00:00
borTx := types2 . NewBorTransaction ( )
Fix eth_getBlockByNumber and eth_getTransactionReceipt some bugs for polygon (#6319)
Get bor state sync tx and receipt has some error:
```
Reqeust:
curl -X "POST" "{{polygon_rpc_endpoint}}" -H 'Content-Type: application/json; charset=utf-8' -d $'{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_getTransactionByHash",
"params": [
"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad"
]
}'
Response:
{"jsonrpc":"2.0","id":1,"result":null}
```
```
Reqeust:
curl -X "POST" "{{polygon_rpc_endpoint}}" -H 'Content-Type: application/json; charset=utf-8' -d $'{
"id": 1,
"method": "eth_getTransactionReceipt",
"jsonrpc": "2.0",
"params": [
"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad"
]
}'
Response
{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"EOF"}}
```
fixed:
```
Request:
curl -X "POST" "{{polygon_rpc_endpoint}}" -H 'Content-Type: application/json; charset=utf-8' -d $'{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_getTransactionByHash",
"params": [
"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad"
]
}'
Response:
{"jsonrpc":"2.0","id":1,"result":{"blockHash":"0xb308eeda80e2a20e1f934d5d37e5f82a078b828128a60283978286ddf0a25264","blockNumber":"0x1c317c0","from":"0x0000000000000000000000000000000000000000","gas":"0x0","gasPrice":"0x0","hash":"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad","input":"0x","nonce":"0x0","to":"0x0000000000000000000000000000000000000000","transactionIndex":"0x89","value":"0x0","type":"0x0","chainId":"0x89","v":"0x0","r":"0x0","s":"0x0"}}
```
```
curl -X "POST" "{{polygon_rpc_endpoint}}" -H 'Content-Type: application/json; charset=utf-8' -d $'{
"id": 1,
"method": "eth_getTransactionReceipt",
"jsonrpc": "2.0",
"params": [
"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad"
]
}'
{"jsonrpc":"2.0","id":1,"result":{"blockHash":"0xb308eeda80e2a20e1f934d5d37e5f82a078b828128a60283978286ddf0a25264","blockNumber":"0x1c317c0","contractAddress":null,"cumulativeGasUsed":"0x0","effectiveGasPrice":"0xd532a03e6","from":"0x0000000000000000000000000000000000000000","gasUsed":"0x0","logs":[{"address":"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x00000000000000000000000038830f36f752ed29039f441cfb543639a6e07b41"],"data":"0x000000000000000000000000000000000000000000000000009c51c4521e0000","blockNumber":"0x1c317c0","transactionHash":"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad","transactionIndex":"0x89","blockHash":"0xb308eeda80e2a20e1f934d5d37e5f82a078b828128a60283978286ddf0a25264","logIndex":"0x2ee","removed":false},{"address":"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x000000000000000000000000f93bcb6f00c1a90050a60a9f737b4cb87126b8f8"],"data":"0x000000000000000000000000000000000000000000000000006a6674f260d000","blockNumber":"0x1c317c0","transactionHash":"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad","transactionIndex":"0x89","blockHash":"0xb308eeda80e2a20e1f934d5d37e5f82a078b828128a60283978286ddf0a25264","logIndex":"0x2ef","removed":false},{"address":"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x000000000000000000000000fd1091c0e49bf1d44b4786747e034d65ab46f36e"],"data":"0x000000000000000000000000000000000000000000000000002386f26fc10000","blockNumber":"0x1c317c0","transactionHash":"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad","transactionIndex":"0x89","blockHash":"0xb308eeda80e2a20e1f934d5d37e5f82a078b828128a60283978286ddf0a25264","logIndex":"0x2f0","removed":false},{"address":"0x7f280dac515121dcda3eac69eb4c13a52392cace","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x000000000000000000000000882d04c3d8410ddf2061b3cba2c3522854316feb"],"data":"0x000000000000000000000000000000000000000000001850e2f557310490f925","blockNumber":"0x1c317c0","transactionHash":"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad","transactionIndex":"0x89","blockHash":"0xb308eeda80e2a20e1f934d5d37e5f82a078b828128a60283978286ddf0a25264","logIndex":"0x2f1","removed":false},{"address":"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x00000000000000000000000028515b56512cb168ad6e6a2428bb39cb696d8bee"],"data":"0x0000000000000000000000000000000000000000000000000058d15e17628000","blockNumber":"0x1c317c0","transactionHash":"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad","transactionIndex":"0x89","blockHash":"0xb308eeda80e2a20e1f934d5d37e5f82a078b828128a60283978286ddf0a25264","logIndex":"0x2f2","removed":false}],"logsBloom":"0x000000000100a0000000000000000000000000000040000000000000000000000000000000000020000000000000000000000000000080000000000000000800000000000000000000000008000000000800000000000000040000000000000000000000020000000000000000000800000000000000000000000010000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000020000002000000000008000000001000000000000002000000000000000020001000040000008000000000000000000080000000000000000000000000000000","status":"0x1","to":"0x0000000000000000000000000000000000000000","transactionHash":"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad","transactionIndex":"0x89","type":"0x0"}}
```
2022-12-15 11:13:52 +00:00
return newRPCBorTransaction ( borTx , txnHash , blockHash , blockNum , uint64 ( len ( block . Transactions ( ) ) ) , baseFee , chainConfig . ChainID ) , nil
2022-02-10 08:36:24 +00:00
}
2022-03-07 03:24:21 +00:00
return newRPCTransaction ( txn , blockHash , blockNum , txnIndex , baseFee ) , nil
2021-05-04 05:51:28 +00:00
}
2021-07-22 14:21:55 +00:00
curHeader := rawdb . ReadCurrentHeader ( tx )
2021-10-20 00:28:14 +00:00
if curHeader == nil {
return nil , nil
}
2021-07-22 14:21:55 +00:00
2021-05-04 05:51:28 +00:00
// No finalized transaction, try to retrieve it from the pool
2022-07-09 03:15:22 +00:00
reply , err := api . txPool . Transactions ( ctx , & txpool . TransactionsRequest { Hashes : [ ] * types . H256 { gointerfaces . ConvertHashToH256 ( txnHash ) } } )
2021-05-04 05:51:28 +00:00
if err != nil {
return nil , err
}
2021-05-04 21:58:13 +00:00
if len ( reply . RlpTxs [ 0 ] ) > 0 {
2023-08-02 16:25:15 +00:00
txn , err := types2 . DecodeWrappedTransaction ( reply . RlpTxs [ 0 ] )
2021-05-04 05:51:28 +00:00
if err != nil {
return nil , err
}
2022-01-18 14:04:05 +00:00
2022-03-07 03:24:21 +00:00
// if no transaction was found in the txpool then we return nil and an error warning that we didn't find the transaction by the hash
2022-01-18 14:04:05 +00:00
if txn == nil {
return nil , nil
}
2021-07-22 14:21:55 +00:00
return newRPCPendingTransaction ( txn , curHeader , chainConfig ) , nil
2021-05-04 05:51:28 +00:00
}
// Transaction unknown, return as such
return nil , nil
}
// GetRawTransactionByHash returns the bytes of the transaction for the given hash.
2023-04-13 11:19:02 +00:00
func ( api * APIImpl ) GetRawTransactionByHash ( ctx context . Context , hash common . Hash ) ( hexutility . Bytes , error ) {
2021-05-04 05:51:28 +00:00
tx , err := api . db . BeginRo ( ctx )
if err != nil {
return nil , err
}
defer tx . Rollback ( )
// https://infura.io/docs/ethereum/json-rpc/eth-getTransactionByHash
2022-01-07 13:52:38 +00:00
blockNum , ok , err := api . txnLookup ( ctx , tx , hash )
2022-01-06 11:22:59 +00:00
if err != nil {
return nil , err
}
2022-01-07 13:52:38 +00:00
if ! ok {
2022-01-06 11:22:59 +00:00
return nil , nil
}
2023-05-27 09:39:14 +00:00
block , err := api . blockByNumberWithSenders ( ctx , tx , blockNum )
2021-07-11 05:25:21 +00:00
if err != nil {
return nil , err
}
2022-01-07 13:52:38 +00:00
if block == nil {
return nil , nil
}
var txn types2 . Transaction
for _ , transaction := range block . Transactions ( ) {
if transaction . Hash ( ) == hash {
txn = transaction
break
}
}
2021-05-04 21:58:13 +00:00
if txn != nil {
2021-05-04 05:51:28 +00:00
var buf bytes . Buffer
err = txn . MarshalBinary ( & buf )
return buf . Bytes ( ) , err
}
// No finalized transaction, try to retrieve it from the pool
reply , err := api . txPool . Transactions ( ctx , & txpool . TransactionsRequest { Hashes : [ ] * types . H256 { gointerfaces . ConvertHashToH256 ( hash ) } } )
if err != nil {
return nil , err
}
2021-05-04 21:58:13 +00:00
if len ( reply . RlpTxs [ 0 ] ) > 0 {
2021-05-04 05:51:28 +00:00
return reply . RlpTxs [ 0 ] , nil
}
return nil , nil
2020-10-14 15:59:42 +00:00
}
2020-10-24 17:03:52 +00:00
// GetTransactionByBlockHashAndIndex implements eth_getTransactionByBlockHashAndIndex. Returns information about a transaction given the block's hash and a transaction index.
2023-01-27 04:39:34 +00:00
func ( api * APIImpl ) GetTransactionByBlockHashAndIndex ( ctx context . Context , blockHash common . Hash , txIndex hexutil . Uint64 ) ( * RPCTransaction , error ) {
2021-04-03 06:26:00 +00:00
tx , err := api . db . BeginRo ( ctx )
2020-10-14 15:59:42 +00:00
if err != nil {
return nil , err
}
defer tx . Rollback ( )
2022-07-07 08:40:50 +00:00
chainConfig , err := api . chainConfig ( tx )
if err != nil {
return nil , err
}
2020-10-14 15:59:42 +00:00
// https://infura.io/docs/ethereum/json-rpc/eth-getTransactionByBlockHashAndIndex
2023-05-27 09:39:14 +00:00
block , err := api . blockByHashWithSenders ( ctx , tx , blockHash )
2020-10-24 06:57:09 +00:00
if err != nil {
return nil , err
}
2020-10-14 15:59:42 +00:00
if block == nil {
2021-05-26 10:35:39 +00:00
return nil , nil // not error, see https://github.com/ledgerwatch/erigon/issues/1645
2020-10-14 15:59:42 +00:00
}
txs := block . Transactions ( )
2022-07-07 08:40:50 +00:00
if uint64 ( txIndex ) > uint64 ( len ( txs ) ) {
2022-02-02 14:25:16 +00:00
return nil , nil // not error
2022-07-07 08:40:50 +00:00
} else if uint64 ( txIndex ) == uint64 ( len ( txs ) ) {
2022-07-09 03:15:22 +00:00
if chainConfig . Bor == nil {
2022-07-07 08:40:50 +00:00
return nil , nil // not error
}
2023-07-14 07:49:10 +00:00
borTx := rawdb . ReadBorTransactionForBlock ( tx , block . NumberU64 ( ) )
2022-07-09 03:15:22 +00:00
if borTx == nil {
return nil , nil // not error
}
derivedBorTxHash := types2 . ComputeBorTxHash ( block . NumberU64 ( ) , block . Hash ( ) )
Fix eth_getBlockByNumber and eth_getTransactionReceipt some bugs for polygon (#6319)
Get bor state sync tx and receipt has some error:
```
Reqeust:
curl -X "POST" "{{polygon_rpc_endpoint}}" -H 'Content-Type: application/json; charset=utf-8' -d $'{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_getTransactionByHash",
"params": [
"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad"
]
}'
Response:
{"jsonrpc":"2.0","id":1,"result":null}
```
```
Reqeust:
curl -X "POST" "{{polygon_rpc_endpoint}}" -H 'Content-Type: application/json; charset=utf-8' -d $'{
"id": 1,
"method": "eth_getTransactionReceipt",
"jsonrpc": "2.0",
"params": [
"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad"
]
}'
Response
{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"EOF"}}
```
fixed:
```
Request:
curl -X "POST" "{{polygon_rpc_endpoint}}" -H 'Content-Type: application/json; charset=utf-8' -d $'{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_getTransactionByHash",
"params": [
"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad"
]
}'
Response:
{"jsonrpc":"2.0","id":1,"result":{"blockHash":"0xb308eeda80e2a20e1f934d5d37e5f82a078b828128a60283978286ddf0a25264","blockNumber":"0x1c317c0","from":"0x0000000000000000000000000000000000000000","gas":"0x0","gasPrice":"0x0","hash":"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad","input":"0x","nonce":"0x0","to":"0x0000000000000000000000000000000000000000","transactionIndex":"0x89","value":"0x0","type":"0x0","chainId":"0x89","v":"0x0","r":"0x0","s":"0x0"}}
```
```
curl -X "POST" "{{polygon_rpc_endpoint}}" -H 'Content-Type: application/json; charset=utf-8' -d $'{
"id": 1,
"method": "eth_getTransactionReceipt",
"jsonrpc": "2.0",
"params": [
"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad"
]
}'
{"jsonrpc":"2.0","id":1,"result":{"blockHash":"0xb308eeda80e2a20e1f934d5d37e5f82a078b828128a60283978286ddf0a25264","blockNumber":"0x1c317c0","contractAddress":null,"cumulativeGasUsed":"0x0","effectiveGasPrice":"0xd532a03e6","from":"0x0000000000000000000000000000000000000000","gasUsed":"0x0","logs":[{"address":"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x00000000000000000000000038830f36f752ed29039f441cfb543639a6e07b41"],"data":"0x000000000000000000000000000000000000000000000000009c51c4521e0000","blockNumber":"0x1c317c0","transactionHash":"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad","transactionIndex":"0x89","blockHash":"0xb308eeda80e2a20e1f934d5d37e5f82a078b828128a60283978286ddf0a25264","logIndex":"0x2ee","removed":false},{"address":"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x000000000000000000000000f93bcb6f00c1a90050a60a9f737b4cb87126b8f8"],"data":"0x000000000000000000000000000000000000000000000000006a6674f260d000","blockNumber":"0x1c317c0","transactionHash":"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad","transactionIndex":"0x89","blockHash":"0xb308eeda80e2a20e1f934d5d37e5f82a078b828128a60283978286ddf0a25264","logIndex":"0x2ef","removed":false},{"address":"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x000000000000000000000000fd1091c0e49bf1d44b4786747e034d65ab46f36e"],"data":"0x000000000000000000000000000000000000000000000000002386f26fc10000","blockNumber":"0x1c317c0","transactionHash":"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad","transactionIndex":"0x89","blockHash":"0xb308eeda80e2a20e1f934d5d37e5f82a078b828128a60283978286ddf0a25264","logIndex":"0x2f0","removed":false},{"address":"0x7f280dac515121dcda3eac69eb4c13a52392cace","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x000000000000000000000000882d04c3d8410ddf2061b3cba2c3522854316feb"],"data":"0x000000000000000000000000000000000000000000001850e2f557310490f925","blockNumber":"0x1c317c0","transactionHash":"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad","transactionIndex":"0x89","blockHash":"0xb308eeda80e2a20e1f934d5d37e5f82a078b828128a60283978286ddf0a25264","logIndex":"0x2f1","removed":false},{"address":"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x00000000000000000000000028515b56512cb168ad6e6a2428bb39cb696d8bee"],"data":"0x0000000000000000000000000000000000000000000000000058d15e17628000","blockNumber":"0x1c317c0","transactionHash":"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad","transactionIndex":"0x89","blockHash":"0xb308eeda80e2a20e1f934d5d37e5f82a078b828128a60283978286ddf0a25264","logIndex":"0x2f2","removed":false}],"logsBloom":"0x000000000100a0000000000000000000000000000040000000000000000000000000000000000020000000000000000000000000000080000000000000000800000000000000000000000008000000000800000000000000040000000000000000000000020000000000000000000800000000000000000000000010000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000020000002000000000008000000001000000000000002000000000000000020001000040000008000000000000000000080000000000000000000000000000000","status":"0x1","to":"0x0000000000000000000000000000000000000000","transactionHash":"0x9916e99b24daba1fb01e093105bc6988b49125ea15fd4b3c4cfa18719e1631ad","transactionIndex":"0x89","type":"0x0"}}
```
2022-12-15 11:13:52 +00:00
return newRPCBorTransaction ( borTx , derivedBorTxHash , block . Hash ( ) , block . NumberU64 ( ) , uint64 ( txIndex ) , block . BaseFee ( ) , chainConfig . ChainID ) , nil
2020-10-14 15:59:42 +00:00
}
2021-07-01 04:29:32 +00:00
return newRPCTransaction ( txs [ txIndex ] , block . Hash ( ) , block . NumberU64 ( ) , uint64 ( txIndex ) , block . BaseFee ( ) ) , nil
2020-10-14 15:59:42 +00:00
}
2021-05-04 05:51:28 +00:00
// GetRawTransactionByBlockHashAndIndex returns the bytes of the transaction for the given block hash and index.
2023-04-13 11:19:02 +00:00
func ( api * APIImpl ) GetRawTransactionByBlockHashAndIndex ( ctx context . Context , blockHash common . Hash , index hexutil . Uint ) ( hexutility . Bytes , error ) {
2021-05-04 05:51:28 +00:00
tx , err := api . db . BeginRo ( ctx )
if err != nil {
return nil , err
}
defer tx . Rollback ( )
// https://infura.io/docs/ethereum/json-rpc/eth-getRawTransactionByBlockHashAndIndex
2023-05-27 09:39:14 +00:00
block , err := api . blockByHashWithSenders ( ctx , tx , blockHash )
2021-05-04 05:51:28 +00:00
if err != nil {
return nil , err
}
if block == nil {
2021-05-26 10:35:39 +00:00
return nil , nil // not error, see https://github.com/ledgerwatch/erigon/issues/1645
2021-05-04 05:51:28 +00:00
}
return newRPCRawTransactionFromBlockIndex ( block , uint64 ( index ) )
}
2020-10-24 17:03:52 +00:00
// GetTransactionByBlockNumberAndIndex implements eth_getTransactionByBlockNumberAndIndex. Returns information about a transaction given a block number and transaction index.
2020-10-14 15:59:42 +00:00
func ( api * APIImpl ) GetTransactionByBlockNumberAndIndex ( ctx context . Context , blockNr rpc . BlockNumber , txIndex hexutil . Uint ) ( * RPCTransaction , error ) {
2021-04-03 06:26:00 +00:00
tx , err := api . db . BeginRo ( ctx )
2020-10-14 15:59:42 +00:00
if err != nil {
return nil , err
}
defer tx . Rollback ( )
2022-07-07 08:40:50 +00:00
chainConfig , err := api . chainConfig ( tx )
if err != nil {
return nil , err
}
2020-10-14 15:59:42 +00:00
// https://infura.io/docs/ethereum/json-rpc/eth-getTransactionByBlockNumberAndIndex
2023-05-31 04:26:38 +00:00
blockNum , hash , _ , err := rpchelper . GetBlockNumber ( rpc . BlockNumberOrHashWithNumber ( blockNr ) , tx , api . filters )
2020-10-14 15:59:42 +00:00
if err != nil {
return nil , err
}
2023-05-31 04:26:38 +00:00
block , err := api . blockWithSenders ( ctx , tx , hash , blockNum )
2020-10-24 06:57:09 +00:00
if err != nil {
return nil , err
}
2020-10-14 15:59:42 +00:00
if block == nil {
2021-05-26 10:35:39 +00:00
return nil , nil // not error, see https://github.com/ledgerwatch/erigon/issues/1645
2020-10-14 15:59:42 +00:00
}
txs := block . Transactions ( )
2022-07-07 08:40:50 +00:00
if uint64 ( txIndex ) > uint64 ( len ( txs ) ) {
2022-02-02 14:25:16 +00:00
return nil , nil // not error
2022-07-07 08:40:50 +00:00
} else if uint64 ( txIndex ) == uint64 ( len ( txs ) ) {
2022-07-09 03:15:22 +00:00
if chainConfig . Bor == nil {
2022-07-07 08:40:50 +00:00
return nil , nil // not error
}
2023-07-14 07:49:10 +00:00
borTx := rawdb . ReadBorTransactionForBlock ( tx , blockNum )
2022-07-09 03:15:22 +00:00
if borTx == nil {
return nil , nil
}
2023-07-14 07:49:10 +00:00
derivedBorTxHash := types2 . ComputeBorTxHash ( blockNum , hash )
return newRPCBorTransaction ( borTx , derivedBorTxHash , hash , blockNum , uint64 ( txIndex ) , block . BaseFee ( ) , chainConfig . ChainID ) , nil
2020-10-14 15:59:42 +00:00
}
2023-07-14 07:49:10 +00:00
return newRPCTransaction ( txs [ txIndex ] , hash , blockNum , uint64 ( txIndex ) , block . BaseFee ( ) ) , nil
2020-10-14 15:59:42 +00:00
}
2021-05-04 05:51:28 +00:00
// GetRawTransactionByBlockNumberAndIndex returns the bytes of the transaction for the given block number and index.
2023-04-13 11:19:02 +00:00
func ( api * APIImpl ) GetRawTransactionByBlockNumberAndIndex ( ctx context . Context , blockNr rpc . BlockNumber , index hexutil . Uint ) ( hexutility . Bytes , error ) {
2021-05-04 05:51:28 +00:00
tx , err := api . db . BeginRo ( ctx )
if err != nil {
return nil , err
}
defer tx . Rollback ( )
// https://infura.io/docs/ethereum/json-rpc/eth-getRawTransactionByBlockNumberAndIndex
2023-05-27 09:39:14 +00:00
block , err := api . blockByRPCNumber ( ctx , blockNr , tx )
2021-05-04 05:51:28 +00:00
if err != nil {
return nil , err
}
if block == nil {
2021-05-26 10:35:39 +00:00
return nil , nil // not error, see https://github.com/ledgerwatch/erigon/issues/1645
2021-05-04 05:51:28 +00:00
}
return newRPCRawTransactionFromBlockIndex ( block , uint64 ( index ) )
}