Ejemplo n.º 1
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.MissingLeaf(),
            error_handlers.BadAddress()
        ]

        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))
Ejemplo n.º 2
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))