Exemplo n.º 1
0
    def state_get(self, request):
        # CLIENT_STATE_GET_REQUEST
        nonleaf_msg = 'Expected a specific leaf address, ' \
                      'but received a prefix instead'

        root = RouteHandler._safe_get(request.match_info, 'merkle_root')
        addr = RouteHandler._safe_get(request.match_info, 'address')
        client_request = client.ClientStateGetRequest(merkle_root=root,
                                                      address=addr)

        validator_response = self._try_validator_request(
            Message.CLIENT_STATE_GET_REQUEST,
            client_request
        )

        parsed_response = RouteHandler._old_response_parse(
            client.ClientStateGetResponse,
            validator_response
        )

        if parsed_response.status == client.ClientStateGetResponse.NONLEAF:
            raise web.HTTPBadRequest(reason=nonleaf_msg)

        return RouteHandler._try_client_response(
            request.headers,
            parsed_response
        )
Exemplo n.º 2
0
    async def fetch_state(self, request):
        """Fetches data from a specific address in the validator's state tree.

        Request:
            query:
                - head: The id of the block to use as the head of the chain
                - address: The 70 character address of the data to be fetched

        Response:
            data: The base64 encoded binary data stored at that address
            head: The head used for this query (most recent if unspecified)
            link: The link to this exact query, including head block
        """
        error_traps = [
            error_handlers.InvalidAddressTrap,
            error_handlers.StateNotFoundTrap]

        address = request.match_info.get('address', '')
        head = request.url.query.get('head', None)

        response = await self._query_validator(
            Message.CLIENT_STATE_GET_REQUEST,
            client_pb2.ClientStateGetResponse,
            client_pb2.ClientStateGetRequest(head_id=head, address=address),
            error_traps)

        return self._wrap_response(
            data=response['value'],
            metadata=self._get_metadata(request, response))
Exemplo n.º 3
0
    def state_get(self, request):
        """
        Fetch a specific data leaf from the validator's state merkle-tree
        """
        error_traps = [
            error_handlers.MissingLeaf(),
            error_handlers.BadAddress()
        ]

        address = request.match_info.get('address', '')
        head = request.url.query.get('head', '')

        response = self._query_validator(
            Message.CLIENT_STATE_GET_REQUEST, client.ClientStateGetResponse,
            client.ClientStateGetRequest(head_id=head, address=address),
            error_traps)

        return RouteHandler._wrap_response(data=response['value'],
                                           metadata=RouteHandler._get_metadata(
                                               request, response))