def _make_paging_message(controls):
        """Turns a raw paging controls dict into Protobuf ClientPagingControls.
        """

        return client_list_control_pb2.ClientPagingControls(
            start=controls.get('start', None),
            limit=controls.get('limit', None))
Beispiel #2
0
    async def _get_latest_block_id(self):
        resp = await self._connection.send(
            Message.CLIENT_BLOCK_LIST_REQUEST,
            client_block_pb2.ClientBlockListRequest(
                paging=client_list_control_pb2.ClientPagingControls(
                    count=1)).SerializeToString())

        block_list_resp = client_block_pb2.ClientBlockListResponse()
        block_list_resp.ParseFromString(resp.content)

        if block_list_resp.status != \
           client_block_pb2.ClientBlockListResponse.OK:
            LOGGER.error('Unable to fetch latest block id')

        return block_list_resp.head_id
Beispiel #3
0
 async def _head_to_root(self, block_id):
     error_traps = [error_handlers.BlockNotFoundTrap]
     if block_id:
         response = await self._messenger._query_validator(
             Message.CLIENT_BLOCK_GET_BY_ID_REQUEST,
             client_block_pb2.ClientBlockGetResponse,
             client_block_pb2.ClientBlockGetByIdRequest(block_id=block_id),
             error_traps)
         block = self._expand_block(response['block'])
     else:
         response = await self._messenger._query_validator(
             Message.CLIENT_BLOCK_LIST_REQUEST,
             client_block_pb2.ClientBlockListResponse,
             client_block_pb2.ClientBlockListRequest(
                 paging=client_list_control_pb2.ClientPagingControls(
                     limit=1)), error_traps)
         block = self._expand_block(response['blocks'][0])
     return (
         block['header_signature'],
         block['header']['state_root_hash'],
     )
Beispiel #4
0
    def _make_paging_message(controls):
        """Turns a raw paging controls dict into Protobuf ClientPagingControls.
        """
        count = controls.get('count', None)
        end_index = controls.get('end_index', None)

        # an end_index must be changed to start_index, possibly modifying count
        if end_index is not None:
            if count is None:
                start_index = 0
                count = end_index
            elif count > end_index + 1:
                start_index = 0
                count = end_index + 1
            else:
                start_index = end_index + 1 - count
        else:
            start_index = controls.get('start_index', None)

        return client_list_control_pb2.ClientPagingControls(
            start_id=controls.get('start_id', None),
            end_id=controls.get('end_id', None),
            start_index=start_index,
            count=count)