modifying code to inspect_many_blocks to accept half open ranges

This commit is contained in:
nikhilsamrat 2022-06-29 22:29:28 +05:30
parent b45f729237
commit 825a10be51
3 changed files with 8 additions and 6 deletions

View File

@ -1,7 +1,7 @@
import asyncio import asyncio
import logging import logging
import time import time
from typing import List, Optional from typing import List, Optional, Tuple, Dict
from sqlalchemy import orm from sqlalchemy import orm
from web3 import Web3 from web3 import Web3
@ -99,10 +99,10 @@ async def get_classified_traces_from_events(w3: Web3, after_block: int, before_b
base_provider = w3.provider base_provider = w3.provider
start = after_block start = after_block
stride = 300 stride = 300
reserves = dict() reserves: Dict[str, Tuple[str, str]] = dict()
while start < before_block: while start < before_block:
begin = start begin = start
end = start + stride if (start + stride) < before_block else before_block end = start + stride if (start + stride) < before_block else before_block-1
start += stride start += stride
print("fetching from node...", begin, end, flush=True) print("fetching from node...", begin, end, flush=True)
swaplogs = await _get_logs_for_topics(base_provider, begin, end, ["0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822"]) swaplogs = await _get_logs_for_topics(base_provider, begin, end, ["0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822"])

View File

@ -41,7 +41,7 @@ def write_arbitrages(
end_amount=arbitrage.end_amount, end_amount=arbitrage.end_amount,
profit_amount=arbitrage.profit_amount, profit_amount=arbitrage.profit_amount,
error=arbitrage.error, error=arbitrage.error,
protocols={swap.protocol.value for swap in arbitrage.swaps}, protocols={swap.protocol.value for swap in arbitrage.swaps if swap.protocol is not None},
) )
) )

View File

@ -1,5 +1,5 @@
import logging import logging
from typing import List, Optional from typing import List, Optional, Any, Dict
from sqlalchemy import orm from sqlalchemy import orm
from web3 import Web3 from web3 import Web3
@ -90,11 +90,13 @@ async def inspect_many_blocks(
arbitrages_payload = [] arbitrages_payload = []
async for swaps in get_classified_traces_from_events(w3, after_block_number, before_block_number): async for swaps in get_classified_traces_from_events(w3, after_block_number, before_block_number):
arbitrages = get_arbitrages(swaps) arbitrages = get_arbitrages(swaps)
count += len(arbitrages) count += len(arbitrages)
logger.info(f"{count} Found {len(swaps)} swaps and {len(arbitrages)} arbitrages") logger.info(f"{count} Found {len(swaps)} swaps and {len(arbitrages)} arbitrages")
if len(arbitrages) > 0: if len(arbitrages) > 0:
for arb in arbitrages: for arb in arbitrages:
arb_payload = dict() arb_payload: Dict[str, Any] = dict()
arb_payload['block_number'] = arb.block_number arb_payload['block_number'] = arb.block_number
arb_payload['transaction'] = arb.transaction_hash arb_payload['transaction'] = arb.transaction_hash
arb_payload['account'] = arb.account_address arb_payload['account'] = arb.account_address