Esempio n. 1
0
def test_block_ranges(start, stop, expected):
    if isinstance(expected, type) and issubclass(expected, Exception):
        with pytest.raises(expected):
            block_ranges(start, stop)
    else:
        actual = tuple(block_ranges(start, stop))
        assert len(actual) == len(expected)
        for actual, expected in zip(actual, expected):
            assert actual == expected
Esempio n. 2
0
def test_block_ranges(start, stop, expected):
    if isinstance(expected, type) and issubclass(expected, Exception):
        with pytest.raises(expected):
            block_ranges(start, stop)
    else:
        actual = tuple(block_ranges(start, stop))
        assert len(actual) == len(expected)
        for actual, expected in zip(actual, expected):
            assert actual == expected
Esempio n. 3
0
def get_logs_asap(address, topics, from_block, to_block):
    logs = []
    ranges = list(block_ranges(from_block, to_block, BATCH_SIZE))
    logger.info('fetching %d batches', len(ranges))
    batches = Parallel(8, "threading", verbose=10)(
        delayed(web3.eth.getLogs)({"address": address, "topics": topics, "fromBlock": start, "toBlock": end})
        for start, end in ranges
    )
    for batch in batches:
        logs.extend(batch)

    return logs
Esempio n. 4
0
def get_logs_asap(address, topics, from_block=None, to_block=None, verbose=0):
    logs = []

    if from_block is None:
        from_block = contract_creation_block(address)
    if to_block is None:
        to_block = chain.height

    ranges = list(block_ranges(from_block, to_block, BATCH_SIZE[chain.id]))
    if verbose > 0:
        logger.info('fetching %d batches', len(ranges))

    batches = Parallel(8, "threading", verbose=verbose)(
        delayed(web3.eth.get_logs)({
            "address": address,
            "topics": topics,
            "fromBlock": start,
            "toBlock": end
        }) for start, end in ranges)
    for batch in batches:
        logs.extend(batch)

    return logs