Producer Components#
Producer components are EVM-specific implementations of Data Bus Producers
BlockIDProducer#
Will produce a for a range of block IDs. Each Block ID will be contained within an EvmBlockIDDataPackage and sent to the Data Bus. The range is processed via a step parameter which determine the next item in the range in the same manner as the step parameter inm hte Python range() function.
Example:
async def run():
async with ParallelDataBus() as data_bus:
block_id_producer = BlockIDProducer(
BlockChain.ETHEREUM_MAINNET,
HexInt(0x0),
HexInt(0x9),
1,
)
await block_id_producer(data_bus)
Complete Simple Example#
import asyncio
from blockcrawler.core.bus import ParallelDataBus, DebugConsumer
from blockcrawler.core.entities import BlockChain
from blockcrawler.core.types import HexInt
from blockcrawler.evm.producers import BlockIDProducer
async def run():
async with ParallelDataBus() as data_bus:
await data_bus.register(DebugConsumer())
block_id_producer = BlockIDProducer(
BlockChain.ETHEREUM_MAINNET,
HexInt(0x0),
HexInt(0x9),
1,
)
await block_id_producer(data_bus)
if __name__ == "__main__":
asyncio.run(run())
Executing the above example will result in something similar to following being displayed in the console:
2023-03-01T16:35:25 - EvmBlockIDDataPackage(blockchain=<BlockChain.ETHEREUM_MAINNET: ‘ethereum-mainnet’>, block_id=HexInt(‘0x0’))
2023-03-01T16:35:25 - EvmBlockIDDataPackage(blockchain=<BlockChain.ETHEREUM_MAINNET: ‘ethereum-mainnet’>, block_id=HexInt(‘0x1’))
2023-03-01T16:35:25 - EvmBlockIDDataPackage(blockchain=<BlockChain.ETHEREUM_MAINNET: ‘ethereum-mainnet’>, block_id=HexInt(‘0x2’))
2023-03-01T16:35:25 - EvmBlockIDDataPackage(blockchain=<BlockChain.ETHEREUM_MAINNET: ‘ethereum-mainnet’>, block_id=HexInt(‘0x3’))
2023-03-01T16:35:25 - EvmBlockIDDataPackage(blockchain=<BlockChain.ETHEREUM_MAINNET: ‘ethereum-mainnet’>, block_id=HexInt(‘0x4’))
2023-03-01T16:35:25 - EvmBlockIDDataPackage(blockchain=<BlockChain.ETHEREUM_MAINNET: ‘ethereum-mainnet’>, block_id=HexInt(‘0x5’))
2023-03-01T16:35:25 - EvmBlockIDDataPackage(blockchain=<BlockChain.ETHEREUM_MAINNET: ‘ethereum-mainnet’>, block_id=HexInt(‘0x6’))
2023-03-01T16:35:25 - EvmBlockIDDataPackage(blockchain=<BlockChain.ETHEREUM_MAINNET: ‘ethereum-mainnet’>, block_id=HexInt(‘0x7’))
2023-03-01T16:35:25 - EvmBlockIDDataPackage(blockchain=<BlockChain.ETHEREUM_MAINNET: ‘ethereum-mainnet’>, block_id=HexInt(‘0x8’))
2023-03-01T16:35:25 - EvmBlockIDDataPackage(blockchain=<BlockChain.ETHEREUM_MAINNET: ‘ethereum-mainnet’>, block_id=HexInt(‘0x9’))
Download the example and try it yourself.