Skip to content
Prev Previous commit
Next Next commit
Minimize log output
  • Loading branch information
afalaleev committed Apr 17, 2022
commit b7e9b99b632624546ccd78abebd7d664ce898901
25 changes: 21 additions & 4 deletions proxy/common_neon/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from typing import Dict, Any
from typing import Dict, Any, Optional

import json
import base58
Expand All @@ -12,11 +12,17 @@
from ..eth_proto import Trx as EthTx


def str_fmt_object(obj):
def str_fmt_object(obj) -> str:
def lookup(o) -> Optional[Dict]:
if hasattr(o, '__str_dict__'):
return o.__str_dict__()
elif hasattr(o, '__dict__'):
return o.__dict__
return None

name = f'{type(obj)}'
name = name[name.rfind('.') + 1:-2]
lookup = lambda o: o.__dict__ if hasattr(o, '__dict__') else None
members = {json.dumps(obj, skipkeys=True, default=lookup, sort_keys=True)}
members = json.dumps(obj, skipkeys=True, default=lookup, sort_keys=True)
return f'{name}: {members}'


Expand All @@ -33,6 +39,17 @@ def __init__(self, slot: int, is_finalized=False, hash=None, parent_hash=None, t
def __str__(self) -> str:
return str_fmt_object(self)

def __str_dict__(self) -> Dict:
return {
'slot': self.slot,
'is_finalized': self.is_finalized,
'is_fake': self.is_fake,
'hash': self.hash,
'parent_hash': self.parent_hash,
'time': self.time,
'len(signs)': len(self.signs)
}

def __getstate__(self) -> Dict:
return self.__dict__

Expand Down
28 changes: 26 additions & 2 deletions proxy/indexer/indexer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import copy
from typing import Iterator, Optional
from typing import Iterator, Optional, Dict

import base58
import time
Expand Down Expand Up @@ -128,9 +128,20 @@ def __init__(self, account: str):
self.count_written = 0
self.max_written = 0

def __str__(self):
def __str__(self) -> str:
return str_fmt_object(self)

def __str_dict__(self) -> Dict:
return {
'len(used_ixs)': len(self.used_ixs),
'len(ixs_cost)': len(self.ixs_cost),
'slot': self.slot,
'account': str(self.account),
'len(self.data)': len(self.data),
'count_written': self.count_written,
'max_written': self.max_written
}


class NeonTxResult(BaseEvmObject):
def __init__(self, storage_account: str, neon_tx: NeonTxInfo, neon_res: NeonTxResultInfo):
Expand All @@ -146,6 +157,19 @@ def __init__(self, storage_account: str, neon_tx: NeonTxInfo, neon_res: NeonTxRe
def __str__(self):
return str_fmt_object(self)

def __str_dict__(self) -> Dict:
return {
'len(used_ixs)': len(self.used_ixs),
'len(ixs_cost)': len(self.ixs_cost),
'slot': self.slot,
'storage_account': str(self.storage_account),
'holder_account': str(self.holder_account),
'neon_tx': self.neon_tx,
'neon_res': self.neon_res,
'len(blocked_accounts)': len(self.blocked_accounts),
'canceled': self.canceled,
'done': self.done
}

@logged_group("neon.Indexer")
class ReceiptsParserState:
Expand Down