Skip to content

Commit

Permalink
fix: cant subtract none and int
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Dec 21, 2024
1 parent a595884 commit 1af19d4
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions eth_portfolio/_loaders/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,13 @@ async def _get_block_number():


async def get_block_for_nonce(address: Address, nonce: Nonce) -> int:
hi = None
async with _nonce_cache_locks[address]:
highest_known_nonce_lower_than_query = None
lowest_known_nonce_greater_than_query = None

# it is impossible for n to == nonce
for less_than, ns in itertools.groupby(
filter(lambda n: n != nonce, nonces[address]), lambda n: n < nonce
):
filtered = filter(lambda n: n != nonce, nonces[address])
for less_than, ns in itertools.groupby(filtered, lambda n: n < nonce):
if less_than:
max_value = max(ns)
if (
Expand All @@ -121,10 +119,7 @@ async def get_block_for_nonce(address: Address, nonce: Nonce) -> int:
highest_known_nonce_lower_than_query = max_value

else:
try:
min_value = min(filter(lambda n: n > nonce, ns))
except ValueError:
continue
min_value = min(ns)
if (
lowest_known_nonce_greater_than_query is None
or min_value < lowest_known_nonce_greater_than_query
Expand All @@ -138,6 +133,8 @@ async def get_block_for_nonce(address: Address, nonce: Nonce) -> int:

if lowest_known_nonce_greater_than_query is not None:
hi = nonces[address][lowest_known_nonce_greater_than_query]
else:
hi = await _get_block_number()

del highest_known_nonce_lower_than_query, lowest_known_nonce_greater_than_query

Expand All @@ -163,8 +160,6 @@ async def get_block_for_nonce(address: Address, nonce: Nonce) -> int:

del range_size

hi = hi or await _get_block_number()

debug_logs_enabled = logger.isEnabledFor(DEBUG)
while True:
_nonce = await get_nonce_at_block(address, lo)
Expand Down

0 comments on commit 1af19d4

Please sign in to comment.