web3-gear
web3-gear copied to clipboard
eth_getTransactionByHash throws error, missing null check for tx["clauses"][0]
error log
{
jsonrpc: '2.0',
error: { code: -32000, message: 'Server error' },
id: 'VET'
}
ERROR:root:list index out of range
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/jsonrpcserver/dispatcher.py", line 134, in handle_exceptions
yield handler
File "/usr/local/lib/python3.8/dist-packages/jsonrpcserver/async_dispatcher.py", line 41, in safe_call
result = await call(
File "/usr/local/lib/python3.8/dist-packages/jsonrpcserver/async_dispatcher.py", line 34, in call
return await validate_args(method, *args, **kwargs)(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/gear/rpc.py", line 28, in wrapper
raise e
File "/usr/local/lib/python3.8/dist-packages/gear/rpc.py", line 22, in wrapper
result = await func(*args, **kw)
File "/usr/local/lib/python3.8/dist-packages/gear/rpc.py", line 236, in eth_getTransactionByHash
return await thor.get_transaction_by_hash(tx_hash)
File "/usr/local/lib/python3.8/dist-packages/gear/thor/client.py", line 128, in get_transaction_by_hash
return None if tx is None else thor_tx_convert_to_eth_tx(tx)
File "/usr/local/lib/python3.8/dist-packages/gear/utils/compat.py", line 118, in thor_tx_convert_to_eth_tx
"to": tx["clauses"][0]["to"],
IndexError: list index out of range
On block number 11006969 (0xa7f3f9) it has transaction with 0x897a17e5781a096076b63e887baa27f5289edf1a6d392b1c5271ab82b68de782 hash.
{
"id": "0x897a17e5781a096076b63e887baa27f5289edf1a6d392b1c5271ab82b68de782",
"chainTag": 74,
"blockRef": "0x00a7f3f86790809c",
"expiration": 18,
"clauses": [],
"gasPriceCoef": 0,
"gas": 21000,
"origin": "0x12fca90a72a6683242447f328ed0adf9fdbded34",
"delegator": null,
"nonce": "0x77985ebc595875b5",
"dependsOn": null,
"size": 95,
"meta": {
"blockID": "0x00a7f3f9d659d4989fac36c7fb97fa5f10d754aa885a9646070a914036b6d1a8",
"blockNumber": 11006969,
"blockTimestamp": 1640585950
}
}
Because the clauses of the transaction is an empty array, it throws error on thor_tx_convert_to_eth_tx(tx)
def thor_tx_convert_to_eth_tx(tx):
return {
"hash": tx["id"],
"nonce": tx["nonce"],
"blockHash": tx["meta"]["blockID"],
"blockNumber": encode_number(tx["meta"]["blockNumber"]),
"transactionIndex": encode_number(0),
"from": tx["origin"],
"to": tx["clauses"][0]["to"] # if len(tx['clauses']) > 0 else None,
"value": tx["clauses"][0]["value"] # len(tx['clauses']) > 0 else None,
"gas": encode_number(tx["gas"]),
"gasPrice": encode_number(1),
"input": tx["clauses"][0]["data"] # len(tx['clauses']) > 0 else None,
}
Is if len(tx['clauses']) > 0 else None
could be a correct patch?
thor_receipt_convert_to_eth_receipt
also throw error
ERROR:root:list index out of range
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/jsonrpcserver/dispatcher.py", line 134, in handle_exceptions
yield handler
File "/usr/local/lib/python3.8/dist-packages/jsonrpcserver/async_dispatcher.py", line 41, in safe_call
result = await call(
File "/usr/local/lib/python3.8/dist-packages/jsonrpcserver/async_dispatcher.py", line 34, in call
return await validate_args(method, *args, **kwargs)(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/gear/rpc.py", line 28, in wrapper
raise e
File "/usr/local/lib/python3.8/dist-packages/gear/rpc.py", line 22, in wrapper
result = await func(*args, **kw)
File "/usr/local/lib/python3.8/dist-packages/gear/rpc.py", line 244, in eth_getTransactionReceipt
return await thor.get_transaction_receipt(tx_hash)
File "/usr/local/lib/python3.8/dist-packages/gear/thor/client.py", line 139, in get_transaction_receipt
return None if receipt is None else thor_receipt_convert_to_eth_receipt(receipt)
File "/usr/local/lib/python3.8/dist-packages/gear/utils/compat.py", line 64, in thor_receipt_convert_to_eth_receipt
"contractAddress": None if receipt["reverted"] else receipt["outputs"][0]["contractAddress"],
IndexError: list index out of range