diff --git a/mev_inspect/block.py b/mev_inspect/block.py index 0079fca..62ef37f 100644 --- a/mev_inspect/block.py +++ b/mev_inspect/block.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import Any, Dict, List +from typing import List from web3 import Web3 @@ -10,9 +10,6 @@ from mev_inspect.schemas.receipts import Receipt cache_directory = "./cache" -## Creates a block object, either from the cache or from the chain itself -## Note that you need to pass in the provider, not the web3 wrapped provider object! -## This is because only the provider allows you to make json rpc requests def create_from_block_number( block_number: int, base_provider, should_cache: bool ) -> Block: @@ -38,40 +35,18 @@ def create_from_block_number( def fetch_block(w3, base_provider, block_number: int) -> Block: - ## Get block data - block_data = w3.eth.get_block(block_number, True) - - ## Get the block receipts - ## TODO: evaluate whether or not this is sufficient or if gas used needs to be converted to a proper big number. - ## In inspect-ts it needed to be converted - block_receipts_raw = base_provider.make_request( - "eth_getBlockReceipts", [block_number] - ) - receipts: List[Receipt] = [ - Receipt(**receipt) for receipt in block_receipts_raw["result"] - ] - - ## Trace the whole block, return those calls + receipts_json = base_provider.make_request("eth_getBlockReceipts", [block_number]) traces_json = w3.parity.trace_block(block_number) + + receipts: List[Receipt] = [ + Receipt(**receipt) for receipt in receipts_json["result"] + ] traces = [Trace(**trace_json) for trace_json in traces_json] - ## Get the logs - block_hash = (block_data.hash).hex() - block_logs = w3.eth.get_logs({"blockHash": block_hash}) - - ## Get gas used by individual txs and store them too - txs_gas_data: Dict[str, Dict[str, Any]] = {} - transaction_hashes = get_transaction_hashes(traces) - - ## Create a new object return Block( block_number=block_number, - data=block_data, receipts=receipts, traces=traces, - logs=block_logs, - transaction_hashes=transaction_hashes, - txs_gas_data=txs_gas_data, ) diff --git a/mev_inspect/schemas/blocks.py b/mev_inspect/schemas/blocks.py index 03ed0bf..f8c8660 100644 --- a/mev_inspect/schemas/blocks.py +++ b/mev_inspect/schemas/blocks.py @@ -1,5 +1,5 @@ from enum import Enum -from typing import Dict, List, Optional +from typing import List, Optional from pydantic import validator @@ -60,11 +60,7 @@ class Trace(CamelModel): class Block(Web3Model): block_number: int traces: List[Trace] - data: dict - logs: List[dict] receipts: List[Receipt] - transaction_hashes: List[str] - txs_gas_data: Dict[str, dict] def get_filtered_traces(self, hash: str) -> List[Trace]: return [trace for trace in self.traces if trace.transaction_hash == hash]