Move list util to db shared
This commit is contained in:
parent
9b8cac5c5d
commit
0ed4f5456e
@ -1,8 +1,8 @@
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any, List
|
||||
from typing import List
|
||||
|
||||
from mev_inspect.db import write_as_csv
|
||||
from mev_inspect.db import to_postgres_list, write_as_csv
|
||||
from mev_inspect.models.traces import ClassifiedTraceModel
|
||||
from mev_inspect.schemas.traces import ClassifiedTrace
|
||||
|
||||
@ -47,7 +47,7 @@ def write_classified_traces(
|
||||
trace.value,
|
||||
trace.gas_used,
|
||||
trace.error,
|
||||
_to_csv_list(trace.trace_address),
|
||||
to_postgres_list(trace.trace_address),
|
||||
trace.transaction_position,
|
||||
)
|
||||
for trace in classified_traces
|
||||
@ -58,10 +58,3 @@ def write_classified_traces(
|
||||
|
||||
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)) + "}"
|
||||
|
@ -1,5 +1,5 @@
|
||||
import os
|
||||
from typing import Any, Iterable, Optional
|
||||
from typing import Any, Iterable, List, Optional
|
||||
|
||||
from sqlalchemy import create_engine, orm
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
@ -67,12 +67,6 @@ def get_trace_session() -> Optional[orm.Session]:
|
||||
return None
|
||||
|
||||
|
||||
def _clean_csv_value(value: Optional[Any]) -> str:
|
||||
if value is None:
|
||||
return r"\N"
|
||||
return str(value).replace("\n", "\\n")
|
||||
|
||||
|
||||
def write_as_csv(
|
||||
db_session,
|
||||
table_name: str,
|
||||
@ -84,3 +78,16 @@ def write_as_csv(
|
||||
|
||||
with db_session.connection().connection.cursor() as cursor:
|
||||
cursor.copy_from(csv_iterator, table_name, sep="|")
|
||||
|
||||
|
||||
def _clean_csv_value(value: Optional[Any]) -> str:
|
||||
if value is None:
|
||||
return r"\N"
|
||||
return str(value).replace("\n", "\\n")
|
||||
|
||||
|
||||
def to_postgres_list(values: List[Any]) -> str:
|
||||
if len(values) == 0:
|
||||
return "{}"
|
||||
|
||||
return "{" + ",".join(map(str, values)) + "}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user