Gut processor. Make a simple classification object
This commit is contained in:
parent
1a9a7425b9
commit
dc583d4d07
@ -1,43 +1,28 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from mev_inspect.inspectors import Inspector
|
from mev_inspect.schemas.blocks import Block, TraceType
|
||||||
from mev_inspect.schemas.blocks import Block, NestedTrace, TraceType
|
|
||||||
from mev_inspect.schemas.classifications import (
|
from mev_inspect.schemas.classifications import (
|
||||||
Classification,
|
Classification,
|
||||||
UnknownClassification,
|
ClassificationType,
|
||||||
)
|
)
|
||||||
from mev_inspect.traces import as_nested_traces
|
|
||||||
|
|
||||||
|
|
||||||
class Processor:
|
class Processor:
|
||||||
def __init__(self, inspectors: List[Inspector]) -> None:
|
def __init__(self) -> None:
|
||||||
self._inspectors = inspectors
|
pass
|
||||||
|
|
||||||
def get_transaction_evaluations(
|
def process(
|
||||||
self,
|
self,
|
||||||
block: Block,
|
block: Block,
|
||||||
) -> List[Classification]:
|
) -> List[Classification]:
|
||||||
transaction_traces = (
|
|
||||||
trace for trace in block.traces if trace.type != TraceType.reward
|
|
||||||
)
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
self._run_inspectors(nested_trace)
|
Classification(
|
||||||
for nested_trace in as_nested_traces(transaction_traces)
|
transaction_hash=trace.transaction_hash,
|
||||||
]
|
block_number=trace.block_number,
|
||||||
|
trace_type=trace.type,
|
||||||
def _run_inspectors(self, nested_trace: NestedTrace) -> Classification:
|
trace_address=trace.trace_address,
|
||||||
for inspector in self._inspectors:
|
classification_type=ClassificationType.unknown,
|
||||||
classification = inspector.inspect(nested_trace)
|
|
||||||
|
|
||||||
if classification is not None:
|
|
||||||
return classification
|
|
||||||
|
|
||||||
internal_classifications = [
|
|
||||||
self._run_inspectors(subtrace) for subtrace in nested_trace.subtraces
|
|
||||||
]
|
|
||||||
|
|
||||||
return UnknownClassification(
|
|
||||||
trace=nested_trace.trace,
|
|
||||||
internal_classifications=internal_classifications,
|
|
||||||
)
|
)
|
||||||
|
for trace in block.traces
|
||||||
|
if trace.type != TraceType.reward
|
||||||
|
]
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
|
from enum import Enum
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from .blocks import Trace
|
from .blocks import TraceType
|
||||||
|
|
||||||
|
|
||||||
|
class ClassificationType(Enum):
|
||||||
|
unknown = "unknown"
|
||||||
|
|
||||||
|
|
||||||
class Classification(BaseModel):
|
class Classification(BaseModel):
|
||||||
pass
|
transaction_hash: str
|
||||||
|
block_number: int
|
||||||
|
trace_type: TraceType
|
||||||
class UnknownClassification(Classification):
|
trace_address: List[int]
|
||||||
trace: Trace
|
classification_type: ClassificationType
|
||||||
internal_classifications: List[Classification]
|
|
||||||
|
@ -3,7 +3,6 @@ import argparse
|
|||||||
from web3 import Web3
|
from web3 import Web3
|
||||||
|
|
||||||
from mev_inspect import block
|
from mev_inspect import block
|
||||||
from mev_inspect.inspectors.uniswap import UniswapInspector
|
|
||||||
from mev_inspect.processor import Processor
|
from mev_inspect.processor import Processor
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Inspect some blocks.")
|
parser = argparse.ArgumentParser(description="Inspect some blocks.")
|
||||||
@ -17,25 +16,32 @@ parser.add_argument(
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-rpc", metavar="r", help="rpc endpoint, this needs to have parity style traces"
|
"-rpc", metavar="r", help="rpc endpoint, this needs to have parity style traces"
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
## Set up the base provider, but don't wrap it in web3 so we can make requests to it with make_request()
|
|
||||||
base_provider = Web3.HTTPProvider(args.rpc)
|
|
||||||
|
|
||||||
## Get block data that we need
|
def inspect_block(base_provider, block_number):
|
||||||
block_data = block.create_from_block_number(args.block_number[0], base_provider)
|
block_data = block.create_from_block_number(block_number, base_provider)
|
||||||
print(f"Total traces: {len(block_data.traces)}")
|
print(f"Total traces: {len(block_data.traces)}")
|
||||||
|
|
||||||
total_transactions = len(
|
total_transactions = len(
|
||||||
set(t.transaction_hash for t in block_data.traces if t.transaction_hash is not None)
|
set(
|
||||||
)
|
t.transaction_hash
|
||||||
print(f"Total transactions: {total_transactions}")
|
for t in block_data.traces
|
||||||
|
if t.transaction_hash is not None
|
||||||
|
)
|
||||||
|
)
|
||||||
|
print(f"Total transactions: {total_transactions}")
|
||||||
|
|
||||||
## Build a Uniswap inspector
|
processor = Processor()
|
||||||
uniswap_inspector = UniswapInspector(base_provider)
|
classifications = processor.process(block_data)
|
||||||
|
|
||||||
## Create a processor, pass in an ARRAY of inspects
|
print(f"Returned {len(classifications)} classifications")
|
||||||
processor = Processor([uniswap_inspector, uniswap_inspector])
|
|
||||||
|
|
||||||
classifications = processor.get_transaction_evaluations(block_data)
|
|
||||||
print(f"Returned {len(classifications)} classifications")
|
if __name__ == "__main__":
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
## Set up the base provider, but don't wrap it in web3 so we can make requests to it with make_request()
|
||||||
|
|
||||||
|
w3_base_provider = Web3.HTTPProvider(args.rpc)
|
||||||
|
|
||||||
|
inspect_block(w3_base_provider, args.block_number[0])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user