From 8281d123ab6d175daf7cdfcc9782f203867f3fad Mon Sep 17 00:00:00 2001 From: Gui Heise Date: Mon, 13 Sep 2021 15:28:51 -0400 Subject: [PATCH] WIP: Fix DB writing --- mev_inspect/crud/classified_traces.py | 28 +++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/mev_inspect/crud/classified_traces.py b/mev_inspect/crud/classified_traces.py index f0300f5..d6244fb 100644 --- a/mev_inspect/crud/classified_traces.py +++ b/mev_inspect/crud/classified_traces.py @@ -1,4 +1,3 @@ -import json from typing import List from mev_inspect.models.classified_traces import ClassifiedTraceModel @@ -22,9 +21,30 @@ def write_classified_traces( db_session, classified_traces: List[ClassifiedTrace], ) -> None: - models = [ - ClassifiedTraceModel(**json.loads(trace.json())) for trace in classified_traces - ] + models = [] + for trace in classified_traces: + models.append( + ClassifiedTraceModel( + **{ + "transaction_hash": trace.transaction_hash, + "block_number": trace.block_number, + "classification": trace.classification.value, + "trace_type": trace.type.value, + "trace_address": trace.trace_address, + "protocol": str(trace.protocol), + "abi_name": trace.abi_name, + "function_name": trace.function_name, + "function_signature": trace.function_signature, + "inputs": trace.inputs, + "from_address": trace.from_address, + "to_address": trace.to_address, + "gas": trace.gas, + "value": trace.value, + "gas_used": trace.gas_used, + "error": trace.error, + } + ) + ) db_session.bulk_save_objects(models) db_session.commit()