forked from blockchain-etl/ethereum-etl
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support bor node eth_getTransactionReceiptsByBlock
- Loading branch information
Showing
7 changed files
with
9,136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# MIT License | ||
# | ||
# Copyright (c) 2018 Evgeny Medvedev, [email protected] | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
|
||
import json | ||
|
||
from blockchainetl.jobs.base_job import BaseJob | ||
from ethereumetl.executors.batch_work_executor import BatchWorkExecutor | ||
from ethereumetl.json_rpc_requests import generate_get_transaction_receipt_by_block_json_rpc | ||
from ethereumetl.mappers.receipt_log_mapper import EthReceiptLogMapper | ||
from ethereumetl.mappers.receipt_mapper import EthReceiptMapper | ||
from ethereumetl.utils import rpc_response_batch_to_results | ||
|
||
|
||
# Exports receipts and logs | ||
class ExportBorBlockReceiptsJob(BaseJob): | ||
def __init__( | ||
self, | ||
blocks_iterable, | ||
batch_size, | ||
batch_web3_provider, | ||
max_workers, | ||
item_exporter, | ||
export_receipts=True, | ||
export_logs=True): | ||
self.batch_web3_provider = batch_web3_provider | ||
self.blocks_iterable = blocks_iterable | ||
|
||
self.batch_work_executor = BatchWorkExecutor(batch_size, max_workers, progress_name=self.__class__.__name__) | ||
self.item_exporter = item_exporter | ||
|
||
self.export_receipts = export_receipts | ||
self.export_logs = export_logs | ||
if not self.export_receipts and not self.export_logs: | ||
raise ValueError('At least one of export_receipts or export_logs must be True') | ||
|
||
self.receipt_mapper = EthReceiptMapper() | ||
self.receipt_log_mapper = EthReceiptLogMapper() | ||
|
||
def _start(self): | ||
self.item_exporter.open() | ||
|
||
def _export(self): | ||
self.batch_work_executor.execute(self.blocks_iterable, self._export_receipts) | ||
|
||
def _export_receipts(self, blocks_iterable): | ||
receipts_rpc = list(generate_get_transaction_receipt_by_block_json_rpc(blocks_iterable)) | ||
response = self.batch_web3_provider.make_batch_request(json.dumps(receipts_rpc)) | ||
results = rpc_response_batch_to_results(response) | ||
receipts = [self.receipt_mapper.json_dict_to_receipt(result) for receipts in results for result in receipts] | ||
for receipt in receipts: | ||
self._export_receipt(receipt) | ||
|
||
def _export_receipt(self, receipt): | ||
if self.export_receipts: | ||
self.item_exporter.export_item(self.receipt_mapper.receipt_to_dict(receipt)) | ||
if self.export_logs: | ||
for log in receipt.logs: | ||
self.item_exporter.export_item(self.receipt_log_mapper.receipt_log_to_dict(log)) | ||
|
||
def _end(self): | ||
self.batch_work_executor.shutdown() | ||
self.item_exporter.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
tests/ethereumetl/job/test_export_bor_block_receipts_job.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# MIT License | ||
# | ||
# Copyright (c) 2018 Evgeny Medvedev, [email protected] | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
|
||
import pytest | ||
|
||
import tests.resources | ||
from ethereumetl.jobs.export_bor_block_receipts_job import ExportBorBlockReceiptsJob | ||
from ethereumetl.jobs.exporters.receipts_and_logs_item_exporter import receipts_and_logs_item_exporter | ||
from ethereumetl.thread_local_proxy import ThreadLocalProxy | ||
from tests.ethereumetl.job.helpers import get_web3_provider | ||
from tests.helpers import compare_lines_ignore_order, read_file | ||
|
||
RESOURCE_GROUP = 'test_export_bor_block_receipts_job' | ||
|
||
|
||
def read_resource(resource_group, file_name): | ||
return tests.resources.read_resource([RESOURCE_GROUP, resource_group], file_name) | ||
|
||
|
||
TARGET_BLOCK_NUMBER = 64225931 | ||
|
||
|
||
@pytest.mark.parametrize("batch_size,block_number,output_format,resource_group,web3_provider_type", [ | ||
(1, TARGET_BLOCK_NUMBER, 'json', 'bor_block_receipts_job', 'mock') | ||
# skip_if_slow_tests_disabled((1, DEFAULT_TX_HASHES, 'csv', 'receipts_with_logs', 'infura')) | ||
]) | ||
def test_export_bor_block_receipts_job(tmpdir, batch_size, block_number, output_format, resource_group, web3_provider_type): | ||
receipts_output_file = str(tmpdir.join('actual_receipts.' + output_format)) | ||
logs_output_file = str(tmpdir.join('actual_logs.' + output_format)) | ||
print("receipts_output_file", receipts_output_file) | ||
print("logs_output_file", logs_output_file) | ||
|
||
job = ExportBorBlockReceiptsJob( | ||
blocks_iterable=(block_number,), | ||
batch_size=batch_size, | ||
batch_web3_provider=ThreadLocalProxy( | ||
lambda: get_web3_provider(web3_provider_type, lambda file: read_resource(resource_group, file), batch=True) | ||
), | ||
max_workers=5, | ||
item_exporter=receipts_and_logs_item_exporter(receipts_output_file, logs_output_file), | ||
export_receipts=receipts_output_file is not None, | ||
export_logs=logs_output_file is not None | ||
) | ||
job.run() | ||
|
||
compare_lines_ignore_order( | ||
read_resource(resource_group, 'expected_receipts.' + output_format), read_file(receipts_output_file) | ||
) | ||
|
||
compare_lines_ignore_order( | ||
read_resource(resource_group, 'expected_logs.' + output_format), read_file(logs_output_file) | ||
) |
Oops, something went wrong.