Esempio n. 1
0
 def get_state(self, addresses, timeout=None):
     """
     Get the value at a given list of address in the validator's merkle
     state.
     Args:
         addressses (list): the addresss to fetch
         timeout: optional timeout, in seconds
     Returns:
         results (list): a list of Entries (address, data), for the
         addresses that have a value
     """
     request = state_context_pb2.TpStateGetRequest(
         context_id=self._context_id, addresses=addresses)
     response_string = self._stream.send(
         Message.TP_STATE_GET_REQUEST,
         request.SerializeToString()).result(timeout).content
     response = state_context_pb2.TpStateGetResponse()
     response.ParseFromString(response_string)
     if response.status == \
             state_context_pb2.TpStateGetResponse.AUTHORIZATION_ERROR:
         raise AuthorizationException(
             'Tried to get unauthorized address: {}'.format(addresses))
     entries = response.entries if response is not None else []
     results = [e for e in entries if len(e.data) != 0]
     return results
Esempio n. 2
0
    def get(self, addresses, timeout=None):
        """
        Get the value at a given list of address in the validator's merkle
        state.
        Args:
            addressses (list): the addresss to fetch
            timeout: optional timeout, in seconds
        Returns:
            results ((map): a map of address to StateEntry values, for the
            addresses that have a value
        """

        request = state_context_pb2.TpStateGetRequest(
            context_id=self._context_id, addresses=addresses)
        response_string = self._stream.send(
            Message.TP_STATE_GET_REQUEST,
            request.SerializeToString()).result(timeout).content
        response = state_context_pb2.TpStateGetResponse()
        response.ParseFromString(response_string)
        entries = response.entries if response is not None else []
        results = [
            StateEntry(address=e.address, data=e.data) for e in entries
            if len(e.data) != 0
        ]
        return results