Exemplo n.º 1
0
def extract_tokens(contracts,
                   provider_uri,
                   output,
                   max_workers,
                   values_as_strings=False):
    """Extracts tokens from contracts file."""

    set_max_field_size_limit()

    with smart_open(contracts, 'r') as contracts_file:
        if contracts.endswith('.json'):
            contracts_iterable = (json.loads(line) for line in contracts_file)
        else:
            contracts_iterable = csv.DictReader(contracts_file)
        converters = [
            IntToStringItemConverter(keys=['decimals', 'total_supply'])
        ] if values_as_strings else []
        job = ExtractTokensJob(
            contracts_iterable=contracts_iterable,
            web3=ThreadLocalProxy(
                lambda: Web3(get_provider_from_uri(provider_uri))),
            max_workers=max_workers,
            item_exporter=tokens_item_exporter(output, converters))

        job.run()
 def _extract_tokens(self, contracts):
     exporter = InMemoryItemExporter(item_types=['token'])
     job = ExtractTokensJob(
         contracts_iterable=contracts,
         web3=ThreadLocalProxy(lambda: Web3(self.batch_web3_provider)),
         max_workers=self.max_workers,
         item_exporter=exporter)
     job.run()
     tokens = exporter.get_items('token')
     return tokens
Exemplo n.º 3
0
def extract_tokens(contracts, provider_uri, output, max_workers):
    """Extracts tokens from contracts file."""

    set_max_field_size_limit()

    with smart_open(contracts, 'r') as contracts_file:
        if contracts.endswith('.json'):
            contracts_iterable = (json.loads(line) for line in contracts_file)
        else:
            contracts_iterable = csv.DictReader(contracts_file)
        job = ExtractTokensJob(
            contracts_iterable=contracts_iterable,
            web3=ThreadLocalProxy(
                lambda: Web3(get_provider_from_uri(provider_uri))),
            max_workers=max_workers,
            item_exporter=tokens_item_exporter(output))

        job.run()