예제 #1
0
    def get_all_tips(
            self,
            timestamp: Optional[Union[int, float]] = None) -> Set[Interval]:
        self._check_connection()
        if isinstance(timestamp, float) and timestamp != inf:
            self.log.warn(
                'timestamp given in float will be truncated, use int instead')
            timestamp = int(timestamp)

        if self._all_tips_cache is not None and timestamp is not None and timestamp >= self._all_tips_cache.timestamp:
            return self._all_tips_cache.tips

        request = protos.ListTipsRequest(tx_type=protos.ANY_TYPE,
                                         timestamp=timestamp)
        result = self._stub.ListTips(request)
        tips = set()
        for interval_proto in result:
            tips.add(
                Interval(interval_proto.begin, interval_proto.end,
                         interval_proto.data))

        if timestamp is not None and timestamp >= self.latest_timestamp:
            merkle_tree, hashes = self.calculate_merkle_tree(tips)
            self._all_tips_cache = AllTipsCache(self.latest_timestamp, tips,
                                                merkle_tree, hashes)

        return tips
예제 #2
0
 def get_tx_tips(self, timestamp: Optional[float] = None) -> Set[Interval]:
     self._check_connection()
     if isinstance(timestamp, float) and timestamp != inf:
         self.log.warn('timestamp given in float will be truncated, use int instead')
         timestamp = int(timestamp)
     request = protos.ListTipsRequest(tx_type=protos.TRANSACTION_TYPE, timestamp=timestamp)
     result = self._stub.ListTips(request)
     tips = set()
     for interval_proto in result:
         tips.add(Interval(interval_proto.begin, interval_proto.end, interval_proto.data))
     return tips