From 138ac42788e27bcf2200e99fdaa4c30772bc0768 Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Tue, 20 Jul 2021 18:17:44 -0400 Subject: [PATCH] Rename BlockCall => Trace --- mev_inspect/block.py | 16 ++++++++-------- mev_inspect/processor.py | 6 +++--- mev_inspect/schemas/__init__.py | 2 +- mev_inspect/schemas/blocks.py | 12 ++++++------ testing_file.py | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/mev_inspect/block.py b/mev_inspect/block.py index 94b06d5..77ae962 100644 --- a/mev_inspect/block.py +++ b/mev_inspect/block.py @@ -3,7 +3,7 @@ from typing import List from web3 import Web3 -from mev_inspect.schemas import Block, BlockCall, BlockCallType +from mev_inspect.schemas import Block, Trace, TraceType cache_directory = "./cache" @@ -12,7 +12,7 @@ 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 createFromBlockNumber(block_number: int, base_provider) -> Block: +def create_from_block_number(block_number: int, base_provider) -> Block: cache_path = _get_cache_path(block_number) if cache_path.is_file(): @@ -42,8 +42,8 @@ def fetch_block(w3, base_provider, block_number: int) -> Block: ) ## Trace the whole block, return those calls - block_calls_json = w3.parity.trace_block(block_number) - block_calls = [BlockCall(**call_json) for call_json in block_calls_json] + traces_json = w3.parity.trace_block(block_number) + traces = [Trace(**trace_json) for trace_json in traces_json] ## Get the logs block_hash = (block_data.hash).hex() @@ -64,25 +64,25 @@ def fetch_block(w3, base_provider, block_number: int) -> Block: "netFeePaid": tx_data["gasPrice"] * tx_receipt["gasUsed"], } - transaction_hashes = get_transaction_hashes(block_calls) + transaction_hashes = get_transaction_hashes(traces) ## Create a new object return Block( block_number=block_number, data=block_data, receipts=block_receipts_raw, - calls=block_calls, + traces=traces, logs=block_logs, transaction_hashes=transaction_hashes, txs_gas_data=txs_gas_data, ) -def get_transaction_hashes(calls: List[BlockCall]) -> List[str]: +def get_transaction_hashes(calls: List[Trace]) -> List[str]: result = [] for call in calls: - if call.type != BlockCallType.reward: + if call.type != TraceType.reward: if ( call.transaction_hash is not None and call.transaction_hash not in result diff --git a/mev_inspect/processor.py b/mev_inspect/processor.py index c1a0efb..d3eca33 100644 --- a/mev_inspect/processor.py +++ b/mev_inspect/processor.py @@ -8,8 +8,8 @@ class Processor: def get_transaction_evaluations(self, block_data): for transaction_hash in block_data.transaction_hashes: - calls = block_data.get_filtered_calls(transaction_hash) - calls_json = [to_original_json_dict(call) for call in calls] + traces = block_data.get_filtered_traces(transaction_hash) + traces_json = [to_original_json_dict(trace) for trace in traces] for inspector in self.inspectors: - inspector.inspect(calls_json) + inspector.inspect(traces_json) diff --git a/mev_inspect/schemas/__init__.py b/mev_inspect/schemas/__init__.py index f56e7ec..442724e 100644 --- a/mev_inspect/schemas/__init__.py +++ b/mev_inspect/schemas/__init__.py @@ -1,2 +1,2 @@ from .abi import ABI -from .blocks import Block, BlockCall, BlockCallType +from .blocks import Block, Trace, TraceType diff --git a/mev_inspect/schemas/blocks.py b/mev_inspect/schemas/blocks.py index b160fcf..5ad16f2 100644 --- a/mev_inspect/schemas/blocks.py +++ b/mev_inspect/schemas/blocks.py @@ -4,7 +4,7 @@ from typing import Dict, List, Optional from .utils import CamelModel, Web3Model -class BlockCallType(Enum): +class TraceType(Enum): call = "call" create = "create" delegate_call = "delegateCall" @@ -12,7 +12,7 @@ class BlockCallType(Enum): suicide = "suicide" -class BlockCall(CamelModel): +class Trace(CamelModel): action: dict block_hash: str block_number: int @@ -21,18 +21,18 @@ class BlockCall(CamelModel): trace_address: List[int] transaction_hash: Optional[str] transaction_position: Optional[int] - type: BlockCallType + type: TraceType error: Optional[str] class Block(Web3Model): block_number: int - calls: List[BlockCall] + traces: List[Trace] data: dict logs: List[dict] receipts: dict transaction_hashes: List[str] txs_gas_data: Dict[str, dict] - def get_filtered_calls(self, hash: str) -> List[BlockCall]: - return [call for call in self.calls if call.transaction_hash == hash] + def get_filtered_traces(self, hash: str) -> List[Trace]: + return [trace for trace in self.traces if trace.transaction_hash == hash] diff --git a/testing_file.py b/testing_file.py index 98a7675..0b392a8 100644 --- a/testing_file.py +++ b/testing_file.py @@ -23,7 +23,7 @@ args = parser.parse_args() base_provider = Web3.HTTPProvider(args.rpc) ## Get block data that we need -block_data = block.createFromBlockNumber(args.block_number[0], base_provider) +block_data = block.create_from_block_number(args.block_number[0], base_provider) ## Build a Uniswap inspector uniswap_inspector = UniswapInspector(base_provider)