Rename BlockCall => Trace
This commit is contained in:
parent
29915c8e1f
commit
138ac42788
@ -3,7 +3,7 @@ from typing import List
|
|||||||
|
|
||||||
from web3 import Web3
|
from web3 import Web3
|
||||||
|
|
||||||
from mev_inspect.schemas import Block, BlockCall, BlockCallType
|
from mev_inspect.schemas import Block, Trace, TraceType
|
||||||
|
|
||||||
|
|
||||||
cache_directory = "./cache"
|
cache_directory = "./cache"
|
||||||
@ -12,7 +12,7 @@ cache_directory = "./cache"
|
|||||||
## Creates a block object, either from the cache or from the chain itself
|
## 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!
|
## 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
|
## 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)
|
cache_path = _get_cache_path(block_number)
|
||||||
|
|
||||||
if cache_path.is_file():
|
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
|
## Trace the whole block, return those calls
|
||||||
block_calls_json = w3.parity.trace_block(block_number)
|
traces_json = w3.parity.trace_block(block_number)
|
||||||
block_calls = [BlockCall(**call_json) for call_json in block_calls_json]
|
traces = [Trace(**trace_json) for trace_json in traces_json]
|
||||||
|
|
||||||
## Get the logs
|
## Get the logs
|
||||||
block_hash = (block_data.hash).hex()
|
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"],
|
"netFeePaid": tx_data["gasPrice"] * tx_receipt["gasUsed"],
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction_hashes = get_transaction_hashes(block_calls)
|
transaction_hashes = get_transaction_hashes(traces)
|
||||||
|
|
||||||
## Create a new object
|
## Create a new object
|
||||||
return Block(
|
return Block(
|
||||||
block_number=block_number,
|
block_number=block_number,
|
||||||
data=block_data,
|
data=block_data,
|
||||||
receipts=block_receipts_raw,
|
receipts=block_receipts_raw,
|
||||||
calls=block_calls,
|
traces=traces,
|
||||||
logs=block_logs,
|
logs=block_logs,
|
||||||
transaction_hashes=transaction_hashes,
|
transaction_hashes=transaction_hashes,
|
||||||
txs_gas_data=txs_gas_data,
|
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 = []
|
result = []
|
||||||
|
|
||||||
for call in calls:
|
for call in calls:
|
||||||
if call.type != BlockCallType.reward:
|
if call.type != TraceType.reward:
|
||||||
if (
|
if (
|
||||||
call.transaction_hash is not None
|
call.transaction_hash is not None
|
||||||
and call.transaction_hash not in result
|
and call.transaction_hash not in result
|
||||||
|
@ -8,8 +8,8 @@ class Processor:
|
|||||||
|
|
||||||
def get_transaction_evaluations(self, block_data):
|
def get_transaction_evaluations(self, block_data):
|
||||||
for transaction_hash in block_data.transaction_hashes:
|
for transaction_hash in block_data.transaction_hashes:
|
||||||
calls = block_data.get_filtered_calls(transaction_hash)
|
traces = block_data.get_filtered_traces(transaction_hash)
|
||||||
calls_json = [to_original_json_dict(call) for call in calls]
|
traces_json = [to_original_json_dict(trace) for trace in traces]
|
||||||
|
|
||||||
for inspector in self.inspectors:
|
for inspector in self.inspectors:
|
||||||
inspector.inspect(calls_json)
|
inspector.inspect(traces_json)
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
from .abi import ABI
|
from .abi import ABI
|
||||||
from .blocks import Block, BlockCall, BlockCallType
|
from .blocks import Block, Trace, TraceType
|
||||||
|
@ -4,7 +4,7 @@ from typing import Dict, List, Optional
|
|||||||
from .utils import CamelModel, Web3Model
|
from .utils import CamelModel, Web3Model
|
||||||
|
|
||||||
|
|
||||||
class BlockCallType(Enum):
|
class TraceType(Enum):
|
||||||
call = "call"
|
call = "call"
|
||||||
create = "create"
|
create = "create"
|
||||||
delegate_call = "delegateCall"
|
delegate_call = "delegateCall"
|
||||||
@ -12,7 +12,7 @@ class BlockCallType(Enum):
|
|||||||
suicide = "suicide"
|
suicide = "suicide"
|
||||||
|
|
||||||
|
|
||||||
class BlockCall(CamelModel):
|
class Trace(CamelModel):
|
||||||
action: dict
|
action: dict
|
||||||
block_hash: str
|
block_hash: str
|
||||||
block_number: int
|
block_number: int
|
||||||
@ -21,18 +21,18 @@ class BlockCall(CamelModel):
|
|||||||
trace_address: List[int]
|
trace_address: List[int]
|
||||||
transaction_hash: Optional[str]
|
transaction_hash: Optional[str]
|
||||||
transaction_position: Optional[int]
|
transaction_position: Optional[int]
|
||||||
type: BlockCallType
|
type: TraceType
|
||||||
error: Optional[str]
|
error: Optional[str]
|
||||||
|
|
||||||
|
|
||||||
class Block(Web3Model):
|
class Block(Web3Model):
|
||||||
block_number: int
|
block_number: int
|
||||||
calls: List[BlockCall]
|
traces: List[Trace]
|
||||||
data: dict
|
data: dict
|
||||||
logs: List[dict]
|
logs: List[dict]
|
||||||
receipts: dict
|
receipts: dict
|
||||||
transaction_hashes: List[str]
|
transaction_hashes: List[str]
|
||||||
txs_gas_data: Dict[str, dict]
|
txs_gas_data: Dict[str, dict]
|
||||||
|
|
||||||
def get_filtered_calls(self, hash: str) -> List[BlockCall]:
|
def get_filtered_traces(self, hash: str) -> List[Trace]:
|
||||||
return [call for call in self.calls if call.transaction_hash == hash]
|
return [trace for trace in self.traces if trace.transaction_hash == hash]
|
||||||
|
@ -23,7 +23,7 @@ args = parser.parse_args()
|
|||||||
base_provider = Web3.HTTPProvider(args.rpc)
|
base_provider = Web3.HTTPProvider(args.rpc)
|
||||||
|
|
||||||
## Get block data that we need
|
## 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
|
## Build a Uniswap inspector
|
||||||
uniswap_inspector = UniswapInspector(base_provider)
|
uniswap_inspector = UniswapInspector(base_provider)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user