Example #1
0
    def __init__(self, start_block, end_block, zilliqa_api, max_workers,
                 item_exporter):
        validate_range(start_block, end_block)
        self.start_block = start_block
        self.end_block = end_block

        self.batch_work_executor = BatchWorkExecutor(
            1, max_workers, retry_exceptions=RETRY_EXCEPTIONS)
        self.item_exporter = item_exporter

        self.zilliqa_service = ZilliqaService(zilliqa_api)
Example #2
0
class ExportDsBlocksJob(BaseJob):
    def __init__(self, start_block, end_block, zilliqa_api, max_workers,
                 item_exporter):
        validate_range(start_block, end_block)
        self.start_block = start_block
        self.end_block = end_block

        self.batch_work_executor = BatchWorkExecutor(
            1, max_workers, retry_exceptions=RETRY_EXCEPTIONS)
        self.item_exporter = item_exporter

        self.zilliqa_service = ZilliqaService(zilliqa_api)

    def _start(self):
        self.item_exporter.open()

    def _export(self):
        self.batch_work_executor.execute(
            range(self.start_block, self.end_block + 1),
            self._export_batch,
            total_items=self.end_block - self.start_block + 1)

    def _export_batch(self, block_number_batch):
        for block_number in block_number_batch:
            block = self.zilliqa_service.get_ds_block(block_number)
            self.item_exporter.export_item(map_ds_block(block))

    def _end(self):
        self.batch_work_executor.shutdown()
        self.item_exporter.close()
class TxBlockTimestampGraph(object):
    def __init__(self, zilliqa_api):
        self._zilliqa_service = ZilliqaService(zilliqa_api)

    def get_first_point(self):
        block = self._zilliqa_service.get_genesis_tx_block()
        return block_to_point(block)

    def get_last_point(self):
        block = self._zilliqa_service.get_latest_tx_block()
        return block_to_point(block)

    def get_point(self, block_number):
        block = self._zilliqa_service.get_tx_block(block_number)
        return block_to_point(block)

    def get_points(self, block_numbers):
        blocks = [
            self._zilliqa_service.get_tx_block(block_number)
            for block_number in block_numbers
        ]
        return [block_to_point(block) for block in blocks]
Example #4
0
class ExportTxBlocksJob(BaseJob):
    def __init__(self,
                 start_block,
                 end_block,
                 zilliqa_api,
                 max_workers,
                 item_exporter,
                 export_transactions=True,
                 export_event_logs=True,
                 export_exceptions=True,
                 export_transitions=True):
        validate_range(start_block, end_block)
        self.start_block = start_block
        self.end_block = end_block

        self.batch_work_executor = BatchWorkExecutor(
            1, max_workers, retry_exceptions=RETRY_EXCEPTIONS)
        self.item_exporter = item_exporter

        self.zilliqa_service = ZilliqaService(zilliqa_api)

        self.export_transactions = export_transactions
        self.export_event_logs = export_event_logs
        self.export_exceptions = export_exceptions
        self.export_transitions = export_transitions

    def _start(self):
        self.item_exporter.open()

    def _export(self):
        self.batch_work_executor.execute(
            range(self.start_block, self.end_block + 1),
            self._export_batch,
            total_items=self.end_block - self.start_block + 1)

    def _export_batch(self, block_number_batch):
        items = []
        for number in block_number_batch:
            tx_block = map_tx_block(self.zilliqa_service.get_tx_block(number))

            txns = list(self.zilliqa_service.get_transactions(
                number)) if tx_block.get('num_transactions') > 0 else []
            if self._should_export_transactions():
                for txn in txns:
                    items.append(map_transaction(tx_block, txn))
                    if self._should_export_event_logs(txn):
                        items.extend(map_event_logs(tx_block, txn))
                    if self._should_export_exceptions(txn):
                        items.extend(map_exceptions(tx_block, txn))
                    if self._should_export_transitions(txn):
                        items.extend(map_transitions(tx_block, txn))
            tx_block['num_present_transactions'] = len(txns)
            items.append(tx_block)

        for item in items:
            self.item_exporter.export_item(item)

    def _should_export_transactions(self):
        return self.export_transactions

    def _should_export_event_logs(self, txn):
        return self.export_event_logs and txn.get('receipt')

    def _should_export_exceptions(self, txn):
        return self.export_exceptions and txn.get('receipt')

    def _should_export_transitions(self, txn):
        return self.export_transitions and txn.get('receipt')

    def _end(self):
        self.batch_work_executor.shutdown()
        self.item_exporter.close()
 def __init__(self, zilliqa_api):
     self._zilliqa_service = ZilliqaService(zilliqa_api)