Rename BlockCall => Trace

This commit is contained in:
Luke Van Seters 2021-07-20 18:17:44 -04:00
parent 29915c8e1f
commit 138ac42788
5 changed files with 19 additions and 19 deletions

View File

@ -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

View File

@ -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)

View File

@ -1,2 +1,2 @@
from .abi import ABI
from .blocks import Block, BlockCall, BlockCallType
from .blocks import Block, Trace, TraceType

View File

@ -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]

View File

@ -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)