def get_newer_txs_after( self, timestamp: int, hash_bytes: bytes, count: int) -> Tuple[List['BaseTransaction'], bool]: from hathor.transaction import tx_or_block_from_proto self._check_connection() if isinstance(timestamp, float): self.log.warn( 'timestamp given in float will be truncated, use int instead') timestamp = int(timestamp) request = protos.ListRequest( tx_type=protos.TRANSACTION_TYPE, time_filter=protos.ONLY_NEWER, timestamp=timestamp, hash=hash_bytes, max_count=count, ) result = self._stub.List(request) tx_list = [] has_more = None for list_item in result: if list_item.HasField('transaction'): tx_proto = list_item.transaction tx_list.append(tx_or_block_from_proto(tx_proto, storage=self)) elif list_item.HasField('has_more'): has_more = list_item.has_more # assuming there are no more items after `has_more`, break soon break else: raise ValueError('unexpected list_item_oneof') assert has_more is not None return tx_list, has_more
def _call_list_request_generators( self, kwargs: Optional[Dict[str, Any]] = None) -> Iterator['BaseTransaction']: """ Execute a call for the ListRequest and yield the blocks or txs :param kwargs: Parameters to be sent to ListRequest :type kwargs: Dict[str,] """ from hathor.transaction import tx_or_block_from_proto def get_tx(tx): tx2 = self.get_transaction_from_weakref(tx.hash) if tx2: tx = tx2 else: self._save_to_weakref(tx) return tx self._check_connection() if kwargs: request = protos.ListRequest(**kwargs) else: request = protos.ListRequest() result = self._stub.List(request) for list_item in result: if not list_item.HasField('transaction'): break tx_proto = list_item.transaction tx = tx_or_block_from_proto(tx_proto, storage=self) assert tx.hash is not None lock = self._get_lock(tx.hash) if lock: with lock: tx = get_tx(tx) else: tx = get_tx(tx) yield tx
def _call_list_request_generators(self, kwargs): """ Execute a call for the ListRequest and yield the blocks or txs :param kwargs: Parameters to be sent to ListRequest :type kwargs: Dict[str,] """ from hathor.transaction import tx_or_block_from_proto self._check_connection() request = protos.ListRequest(**kwargs) result = self._stub.List(request) for list_item in result: if not list_item.HasField('transaction'): break tx_proto = list_item.transaction yield tx_or_block_from_proto(tx_proto, storage=self)
def get_transactions_before(self, hash_bytes, num_blocks=100): # pragma: no cover from hathor.transaction import tx_or_block_from_proto self._check_connection() request = protos.ListRequest( tx_type=protos.TRANSACTION_TYPE, hash=hash_bytes, max_count=num_blocks, filter_before=True, ) result = self._stub.List(request) tx_list = [] for list_item in result: if not list_item.HasField('transaction'): break tx_proto = list_item.transaction tx_list.append(tx_or_block_from_proto(tx_proto, storage=self)) return tx_list
def get_all_transactions(self) -> Iterator['BaseTransaction']: from hathor.transaction import tx_or_block_from_proto self._check_connection() request = protos.ListRequest() result = self._stub.List(request) for list_item in result: if not list_item.HasField('transaction'): break tx_proto = list_item.transaction tx = tx_or_block_from_proto(tx_proto, storage=self) assert tx.hash is not None tx2 = self.get_transaction_from_weakref(tx.hash) if tx2: yield tx2 else: self._save_to_weakref(tx) yield tx
def get_blocks_before(self, hash_bytes: bytes, num_blocks: int = 100) -> List[Block]: from hathor.transaction import tx_or_block_from_proto self._check_connection() request = protos.ListRequest( tx_type=protos.BLOCK_TYPE, hash=hash_bytes, max_count=num_blocks, filter_before=True, ) result = self._stub.List(request) tx_list: List[Block] = [] for list_item in result: if not list_item.HasField('transaction'): break tx_proto = list_item.transaction block = tx_or_block_from_proto(tx_proto, storage=self) assert isinstance(block, Block) tx_list.append(block) return tx_list