mirror of
https://github.com/blockchain-etl/ethereum-etl.git
synced 2026-01-09 13:57:54 -05:00
58 lines
2.9 KiB
Python
58 lines
2.9 KiB
Python
# MIT License
|
|
#
|
|
# Copyright (c) 2018 Evgeny Medvedev, evge.medvedev@gmail.com
|
|
#
|
|
# 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 argparse
|
|
|
|
from ethereumetl.ipc import IPCWrapper
|
|
from ethereumetl.jobs.export_blocks_job import ExportBlocksJob
|
|
from ethereumetl.jobs.export_blocks_job_item_exporter import export_blocks_job_item_exporter
|
|
from ethereumetl.thread_local_proxy import ThreadLocalProxy
|
|
|
|
parser = argparse.ArgumentParser(description='Export blocks and transactions.')
|
|
parser.add_argument('-s', '--start-block', default=0, type=int, help='Start block')
|
|
parser.add_argument('-e', '--end-block', required=True, type=int, help='End block')
|
|
parser.add_argument('-b', '--batch-size', default=100, type=int, help='The number of blocks to export at a time.')
|
|
parser.add_argument('--ipc-path', required=True, type=str, help='The full path to the ipc file.')
|
|
parser.add_argument('--ipc-timeout', default=60, type=int, help='The timeout in seconds for ipc calls.')
|
|
parser.add_argument('-w', '--max-workers', default=5, type=int, help='The maximum number of workers.')
|
|
parser.add_argument('--blocks-output', default=None, type=str,
|
|
help='The output file for blocks. If not provided blocks will not be exported. '
|
|
'Use "-" for stdout')
|
|
parser.add_argument('--transactions-output', default=None, type=str,
|
|
help='The output file for transactions. If not provided transactions will not be exported. '
|
|
'Use "-" for stdout')
|
|
|
|
args = parser.parse_args()
|
|
|
|
job = ExportBlocksJob(
|
|
start_block=args.start_block,
|
|
end_block=args.end_block,
|
|
batch_size=args.batch_size,
|
|
ipc_wrapper=ThreadLocalProxy(lambda: IPCWrapper(args.ipc_path, timeout=args.ipc_timeout)),
|
|
max_workers=args.max_workers,
|
|
item_exporter=export_blocks_job_item_exporter(args.blocks_output, args.transactions_output),
|
|
export_blocks=args.blocks_output is not None,
|
|
export_transactions=args.transactions_output is not None)
|
|
|
|
job.run()
|