def export_contracts(batch_size, receipts, output, max_workers, provider_uri, chain='ethereum'): """Exports contracts bytecode and sighashes.""" check_classic_provider_uri(chain, provider_uri) with smart_open(receipts, 'r') as receipts_file: contracts_iterable = ( { "contract_address": json.loads(receipt)["contract_address"].strip(), "block_number": json.loads(receipt)["block_number"] } for receipt in receipts_file if json.loads(receipt)["contract_address"] is not None) job = ExportContractsJob( contracts_iterable=contracts_iterable, batch_size=batch_size, batch_web3_provider=ThreadLocalProxy( lambda: get_provider_from_uri(provider_uri, batch=True)), item_exporter=contracts_item_exporter(output), max_workers=max_workers) job.run()
def export_events(start_block, end_block, block_list, provider_uri, batch_size, max_workers, event_hash, events_output, timeout=60, chain='ethereum'): provider_uri = check_classic_provider_uri(chain, provider_uri) if end_block is not None: validate_range(start_block, end_block) block_iterator = range(start_block, end_block + 1) elif block_list is not None: block_iterator = set([int(block) for block in block_list.split(':')]) else: raise ValueError( 'Either --end-block or --block-list options must be provided') job = ExportEventsJob( block_iterator=block_iterator, batch_web3_provider=ThreadLocalProxy(lambda: get_provider_from_uri( provider_uri, timeout=timeout, batch=True)), batch_size=batch_size, max_workers=max_workers, item_exporter=events_item_exporter(events_output), event_hash=event_hash) job.run()
def export_blocks_and_transactions(start_block, end_block, batch_size, provider_uri, max_workers, blocks_output, transactions_output, chain='ethereum'): """Exports blocks and transactions.""" provider_uri = check_classic_provider_uri(chain, provider_uri) if blocks_output is None and transactions_output is None: raise ValueError( 'Either --blocks-output or --transactions-output options must be provided' ) job = ExportBlocksJob( start_block=start_block, end_block=end_block, batch_size=batch_size, batch_web3_provider=ThreadLocalProxy( lambda: get_provider_from_uri(provider_uri, batch=True)), max_workers=max_workers, item_exporter=blocks_and_transactions_item_exporter( blocks_output, transactions_output), export_blocks=blocks_output is not None, export_transactions=transactions_output is not None) job.run()
def get_block_range_for_date(provider_uri, date, output, chain='ethereum'): """Outputs start and end blocks for given date.""" provider_uri = check_classic_provider_uri(chain, provider_uri) provider = get_provider_from_uri(provider_uri) web3 = Web3(provider) web3.middleware_stack.inject(geth_poa_middleware, layer=0) eth_service = EthService(web3) start_block, end_block = eth_service.get_block_range_for_date(date) with smart_open(output, 'w') as output_file: output_file.write('{},{}\n'.format(start_block, end_block))
def export_all(start, end, partition_batch_size, provider_uri, output_dir, max_workers, export_batch_size, chain='ethereum'): """Exports all data for a range of blocks.""" provider_uri = check_classic_provider_uri(chain, provider_uri) export_all_common( get_partitions(start, end, partition_batch_size, provider_uri), output_dir, provider_uri, max_workers, export_batch_size)
def export_receipts_and_logs(batch_size, transactions, provider_uri, max_workers, receipts_output, logs_output, chain='ethereum'): """Exports receipts and logs.""" provider_uri = check_classic_provider_uri(chain, provider_uri) with smart_open(transactions, 'r') as transactions_file: job = ExportReceiptsJob( transaction_hashes_iterable=(json.loads(transaction)['hash'].strip() for transaction in transactions_file), batch_size=batch_size, batch_web3_provider=ThreadLocalProxy(lambda: get_provider_from_uri(provider_uri, batch=True)), max_workers=max_workers, item_exporter=receipts_and_logs_item_exporter(receipts_output, logs_output), export_receipts=receipts_output is not None, export_logs=logs_output is not None) job.run()
def export_tokens(contracts, output, max_workers, provider_uri, chain='ethereum'): """Exports ERC20/ERC721 tokens.""" provider_uri = check_classic_provider_uri(chain, provider_uri) web3 = Web3(get_provider_from_uri(provider_uri)) web3.middleware_stack.inject(geth_poa_middleware, layer=0) with smart_open(contracts, 'r') as contracts_file: tokens_iterable = ({ "contract_address": contract["address"].strip(), "block_number": contract["block_number"] } for contract in (json.loads(contract) for contract in contracts_file) if contract["is_erc20"] or contract["is_erc721"]) job = ExportTokensJob(tokens_iterable=tokens_iterable, web3=ThreadLocalProxy(lambda: web3), item_exporter=tokens_item_exporter(output), max_workers=max_workers) job.run()