Move classified_traces to csv write
This commit is contained in:
parent
bab2043575
commit
6b1c469a10
@ -1,6 +1,8 @@
|
|||||||
import json
|
import json
|
||||||
from typing import List
|
from datetime import datetime, timezone
|
||||||
|
from typing import Any, List
|
||||||
|
|
||||||
|
from mev_inspect.db import write_as_csv
|
||||||
from mev_inspect.models.traces import ClassifiedTraceModel
|
from mev_inspect.models.traces import ClassifiedTraceModel
|
||||||
from mev_inspect.schemas.traces import ClassifiedTrace
|
from mev_inspect.schemas.traces import ClassifiedTrace
|
||||||
|
|
||||||
@ -26,30 +28,40 @@ def write_classified_traces(
|
|||||||
db_session,
|
db_session,
|
||||||
classified_traces: List[ClassifiedTrace],
|
classified_traces: List[ClassifiedTrace],
|
||||||
) -> None:
|
) -> None:
|
||||||
models = []
|
now = datetime.now(timezone.utc)
|
||||||
for trace in classified_traces:
|
items = (
|
||||||
inputs_json = (json.loads(trace.json(include={"inputs"}))["inputs"],)
|
(
|
||||||
models.append(
|
now, # classified_at - gets a default
|
||||||
ClassifiedTraceModel(
|
trace.transaction_hash,
|
||||||
transaction_hash=trace.transaction_hash,
|
trace.block_number,
|
||||||
transaction_position=trace.transaction_position,
|
trace.classification.value,
|
||||||
block_number=trace.block_number,
|
trace.type.value,
|
||||||
classification=trace.classification.value,
|
str(trace.protocol),
|
||||||
trace_type=trace.type.value,
|
trace.abi_name,
|
||||||
trace_address=trace.trace_address,
|
trace.function_name,
|
||||||
protocol=str(trace.protocol),
|
trace.function_signature,
|
||||||
abi_name=trace.abi_name,
|
_inputs_as_json(trace),
|
||||||
function_name=trace.function_name,
|
trace.from_address,
|
||||||
function_signature=trace.function_signature,
|
trace.to_address,
|
||||||
inputs=inputs_json,
|
trace.gas,
|
||||||
from_address=trace.from_address,
|
trace.value,
|
||||||
to_address=trace.to_address,
|
trace.gas_used,
|
||||||
gas=trace.gas,
|
trace.error,
|
||||||
value=trace.value,
|
_to_csv_list(trace.trace_address),
|
||||||
gas_used=trace.gas_used,
|
trace.transaction_position,
|
||||||
error=trace.error,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
for trace in classified_traces
|
||||||
|
)
|
||||||
|
|
||||||
db_session.bulk_save_objects(models)
|
write_as_csv(db_session, "classified_traces", items)
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
|
def _inputs_as_json(trace) -> str:
|
||||||
|
return json.dumps(json.loads(trace.json(include={"inputs"}))["inputs"])
|
||||||
|
|
||||||
|
|
||||||
|
def _to_csv_list(values: List[Any]) -> str:
|
||||||
|
if len(values) == 0:
|
||||||
|
return "{}"
|
||||||
|
|
||||||
|
return "{" + ",".join(map(str, values)) + "}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user