async def list_blocks(self, request): """Fetches list of blocks from validator, optionally filtered by id. Request: query: - head: The id of the block to use as the head of the chain - id: Comma separated list of block ids to include in results Response: data: JSON array of fully expanded Block objects head: The head used for this query (most recent if unspecified) link: The link to this exact query, including head block paging: Paging info and nav, like total resources and a next link """ paging_controls = self._get_paging_controls(request) validator_query = client_pb2.ClientBlockListRequest( head_id=request.url.query.get('head', None), block_ids=self._get_filter_ids(request), paging=self._make_paging_message(paging_controls)) response = await self._query_validator( Message.CLIENT_BLOCK_LIST_REQUEST, client_pb2.ClientBlockListResponse, validator_query) return self._wrap_paginated_response( request=request, response=response, controls=paging_controls, data=[self._expand_block(b) for b in response['blocks']])
def block_list(self, request): """ Fetch a list of blocks from the validator """ response = self._query_validator( Message.CLIENT_BLOCK_LIST_REQUEST, client.ClientBlockListResponse, client.ClientBlockListRequest() ) blocks = [RouteHandler._expand_block(b) for b in response['blocks']] return RouteHandler._wrap_response(data=blocks)
async def _get_latest_block_id(self): resp = await self._connection.send( Message.CLIENT_BLOCK_LIST_REQUEST, client_pb2.ClientBlockListRequest(paging=client_pb2.PagingControls( count=1)).SerializeToString()) block_list_resp = client_pb2.ClientBlockListResponse() block_list_resp.ParseFromString(resp.content) if block_list_resp.status != client_pb2.ClientBlockListResponse.OK: LOGGER.error('Unable to fetch latest block id') return block_list_resp.head_id
def block_list(self, request): """ Fetch a list of blocks from the validator """ head = request.url.query.get('head', '') response = self._query_validator( Message.CLIENT_BLOCK_LIST_REQUEST, client.ClientBlockListResponse, client.ClientBlockListRequest(head_id=head)) blocks = [RouteHandler._expand_block(b) for b in response['blocks']] return RouteHandler._wrap_response(data=blocks, metadata=RouteHandler._get_metadata( request, response))