Пример #1
0
    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))
    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(
                    limit=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
Пример #3
0
 async def _head_to_root(self, block_id):
     error_traps = [error_handlers.BlockNotFoundTrap]
     if block_id:
         response = await self._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._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'],
     )