diff --git a/gsrest/db/cassandra.py b/gsrest/db/cassandra.py index fae488c..d27b4ac 100644 --- a/gsrest/db/cassandra.py +++ b/gsrest/db/cassandra.py @@ -192,8 +192,7 @@ def merge_address_txs_subquery_results( precedence = heapq.nsmallest if ascending else heapq.nlargest results = precedence(fetch_size, candidates, - key=partial(transaction_ordering_key, - tx_id_keys)) + key=partial(transaction_ordering_key, tx_id_keys)) # use the last tx_id as page handle border_tx_id = results[-1][tx_id_keys] if results else None @@ -204,8 +203,7 @@ def build_select_address_txs_statement(network: str, node_type: NodeType, cols: Optional[Sequence[str]], with_lower_bound: bool, with_upper_bound: bool, - with_tx_id: bool, - ascending: bool, + with_tx_id: bool, ascending: bool, fetch_size: int) -> str: # prebuild useful helpers and conditions eth_like = is_eth_like(network) @@ -228,11 +226,15 @@ def build_select_address_txs_statement(network: str, node_type: NodeType, # conditional where clause, loop dependent if not with_tx_id: if ascending: - query += wc(f"{tx_id_col} > %(tx_id_lower_bound)s", with_lower_bound) - query += wc(f"{tx_id_col} <= %(tx_id_upper_bound)s", with_upper_bound) + query += wc(f"{tx_id_col} > %(tx_id_lower_bound)s", + with_lower_bound) + query += wc(f"{tx_id_col} <= %(tx_id_upper_bound)s", + with_upper_bound) else: - query += wc(f"{tx_id_col} >= %(tx_id_lower_bound)s", with_lower_bound) - query += wc(f"{tx_id_col} < %(tx_id_upper_bound)s", with_upper_bound) + query += wc(f"{tx_id_col} >= %(tx_id_lower_bound)s", + with_lower_bound) + query += wc(f"{tx_id_col} < %(tx_id_upper_bound)s", + with_upper_bound) else: query += wc(f"{tx_id_col} = %(tx_id)s", True) @@ -246,6 +248,7 @@ def build_select_address_txs_statement(network: str, node_type: NodeType, class Cassandra: + def eth(func): def check(*args, **kwargs): @@ -747,7 +750,8 @@ async def list_txs_by_node_type(self, id=id, tx_id_lower_bound=first_tx_id, tx_id_upper_bound=upper_bound, - is_outgoing=(direction == 'out' if direction is not None else None), + is_outgoing=(direction == 'out' + if direction is not None else None), include_assets=include_assets, ascending=ascending, page=page, @@ -1804,7 +1808,8 @@ async def add_balance_eth(self, currency, row): "and currency=%s" results = { - c: one(await self.execute_async( + c: + one(await self.execute_async( currency, 'transformed', query, [row['address_id'], row['address_id_group'], c])) for c in balance_currencies @@ -1940,20 +1945,20 @@ async def get_id_secondary_group_eth(self, currency, table, id_group): return 0 if result is None else \ result['max_secondary_id'] - async def list_address_txs_ordered( - self, - network: str, - node_type: NodeType, - id, - tx_id_lower_bound: Optional[int], - tx_id_upper_bound: Optional[int], - is_outgoing: Optional[bool], - include_assets: Sequence[Tuple[str, bool]], - page: Optional[int], - fetch_size: int, - cols: Optional[Sequence[str]] = None, - tx_ids: Optional[Sequence[int]] = None, - ascending: bool = False): + async def list_address_txs_ordered(self, + network: str, + node_type: NodeType, + id, + tx_id_lower_bound: Optional[int], + tx_id_upper_bound: Optional[int], + is_outgoing: Optional[bool], + include_assets: Sequence[Tuple[str, + bool]], + page: Optional[int], + fetch_size: int, + cols: Optional[Sequence[str]] = None, + tx_ids: Optional[Sequence[int]] = None, + ascending: bool = False): """Loads a address transactions in execution order it allows to only get out- or incoming transaction or only transactions of a certain asset (token), for a given address id @@ -1996,7 +2001,8 @@ async def list_address_txs_ordered( item_id_secondary_group = self.sec_in(secondary_id_group) - directions = [is_outgoing] if is_outgoing is not None else [False, True] + directions = [is_outgoing + ] if is_outgoing is not None else [False, True] results = [] """ Keep retrieving pages until the demanded fetch_size is fulfilled @@ -2022,7 +2028,6 @@ async def list_address_txs_ordered( else: this_tx_id_lower_bound = page - # prebuild useful conditions, dependent on loop has_upper_bound = this_tx_id_upper_bound is not None @@ -2067,9 +2072,8 @@ async def list_address_txs_ordered( # collect and merge results more_results, page = merge_address_txs_subquery_results( - [r.current_rows for r in await asyncio.gather(*aws)], - ascending, - fs_it, + [r.current_rows + for r in await asyncio.gather(*aws)], ascending, fs_it, 'transaction_id' if is_eth_like(network) else 'tx_id') results.extend(more_results) @@ -2127,7 +2131,8 @@ async def list_txs_by_node_type_eth(self, id=address, tx_id_lower_bound=first_tx_id, tx_id_upper_bound=upper_bound, - is_outgoing=(direction == 'out' if direction is not None else None), + is_outgoing=(direction == 'out' + if direction is not None else None), include_assets=include_assets, ascending=ascending, page=page, diff --git a/gsrest/test/addresses_service.py b/gsrest/test/addresses_service.py index 959700c..f5a88bb 100644 --- a/gsrest/test/addresses_service.py +++ b/gsrest/test/addresses_service.py @@ -1,4 +1,3 @@ -import pdb from openapi_server.models.address import Address from openapi_server.models.tx_summary import TxSummary from openapi_server.models.neighbor_addresses import NeighborAddresses @@ -17,7 +16,6 @@ from gsrest.util.values import make_values import gsrest.test.tags_service as ts import copy -from pprint import pprint address = Address( currency="btc", @@ -675,7 +673,8 @@ async def list_address_txs(test_case): order='asc') test_case.assertEqual(_reversed, result['address_txs']) - path_with_order_and_page = path_with_order + '&pagesize={pagesize}&page={page}' + path_with_order_and_page = path_with_order + \ + '&pagesize={pagesize}&page={page}' result = await test_case.request(path_with_order_and_page, currency='btc', address=address2.address, @@ -692,8 +691,7 @@ async def list_address_txs(test_case): pagesize=2, page=result['next_page']) - test_case.assertEqual(_reversed[2:3], - result['address_txs']) + test_case.assertEqual(_reversed[2:3], result['address_txs']) test_case.assertEqual(result.get('next_page', None), None) path_with_direction = path + '?direction={direction}' diff --git a/gsrest/test/entities_service.py b/gsrest/test/entities_service.py index fc2cf8c..67b673b 100644 --- a/gsrest/test/entities_service.py +++ b/gsrest/test/entities_service.py @@ -720,7 +720,8 @@ async def list_entity_txs(test_case): order='asc') test_case.assertEqual(_reversed, result['address_txs']) - path_with_order_and_page = path_with_order + '&pagesize={pagesize}&page={page}' + path_with_order_and_page = path_with_order + \ + '&pagesize={pagesize}&page={page}' result = await test_case.request(path_with_order_and_page, currency='btc', entity=144534, @@ -737,8 +738,7 @@ async def list_entity_txs(test_case): pagesize=2, page=result['next_page']) - test_case.assertEqual(_reversed[2:3], - result['address_txs']) + test_case.assertEqual(_reversed[2:3], result['address_txs']) test_case.assertEqual(result.get('next_page', None), None) path_with_direction =\