async def handle_get_block_headers(self, peer: ETHProxyPeer, msg: Dict[str, Any]) -> None: query = cast(Dict[Any, Union[bool, int]], msg) self.logger.debug("%s requested headers: %s", peer, query) request = ETHHeaderRequest( cast(BlockIdentifier, query['block_number_or_hash']), query['max_headers'], query['skip'], cast(bool, query['reverse']), ) headers = await self.lookup_headers(request) self.logger.debug2("Replying to %s with %d headers", peer, len(headers)) peer.sub_proto.send_block_headers(headers)
async def request_stuff() -> None: # Request some stuff from ropsten's block 2440319 # (https://ropsten.etherscan.io/block/2440319), just as a basic test. nonlocal peer_pool while not peer_pool.connected_nodes: peer_pool.logger.info("Waiting for peer connection...") await asyncio.sleep(0.2) peer = peer_pool.highest_td_peer block_hash = decode_hex( '0x59af08ab31822c992bb3dad92ddb68d820aa4c69e9560f07081fa53f1009b152' ) if peer_class == ETHPeer: peer = cast(ETHPeer, peer) peer.sub_proto.send_get_block_headers( ETHHeaderRequest(block_hash, 1, 0, False)) peer.sub_proto.send_get_block_bodies([block_hash]) peer.sub_proto.send_get_receipts([block_hash]) else: peer = cast(LESPeer, peer) request_id = 1 peer.sub_proto.send_get_block_headers( LESHeaderRequest(block_hash, 1, 0, False, request_id)) peer.sub_proto.send_get_block_bodies([block_hash], request_id + 1) peer.sub_proto.send_get_receipts(block_hash, request_id + 2)