Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
myrho committed Feb 2, 2024
1 parent f91ee5e commit bb5203d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 38 deletions.
65 changes: 35 additions & 30 deletions gsrest/db/cassandra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -246,6 +248,7 @@ def build_select_address_txs_statement(network: str, node_type: NodeType,


class Cassandra:

def eth(func):

def check(*args, **kwargs):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 3 additions & 5 deletions gsrest/test/addresses_service.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -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}'
Expand Down
6 changes: 3 additions & 3 deletions gsrest/test/entities_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 =\
Expand Down

0 comments on commit bb5203d

Please sign in to comment.