From f1f52538653c1f95e87def589943b32beb712d5a Mon Sep 17 00:00:00 2001 From: nolash Date: Tue, 18 May 2021 17:32:58 +0200 Subject: [PATCH] handle string datetime format in tx list --- apps/cic-cache/cic_cache/cache.py | 11 +++++++++++ apps/cic-cache/cic_cache/runnable/daemons/query.py | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/apps/cic-cache/cic_cache/cache.py b/apps/cic-cache/cic_cache/cache.py index f4436eb8..f23e4a7c 100644 --- a/apps/cic-cache/cic_cache/cache.py +++ b/apps/cic-cache/cic_cache/cache.py @@ -1,5 +1,6 @@ # standard imports import logging +import datetime # external imports import moolb @@ -101,13 +102,19 @@ class DataCache(Cache): tx_cache = [] highest_block = -1; lowest_block = -1; + date_is_str = None # stick this in startup for r in rows: if highest_block == -1: highest_block = r['block_number'] lowest_block = r['block_number'] tx_type = 'unknown' + if r['value'] != None: tx_type = '{}.{}'.format(r['domain'], r['value']) + + if date_is_str == None: + date_is_str = type(r['date_block']).__name__ == 'str' + o = { 'block_number': r['block_number'], 'tx_hash': r['tx_hash'], @@ -120,5 +127,9 @@ class DataCache(Cache): 'destination_token': r['destination_token'], 'tx_type': tx_type, } + + if date_is_str: + o['date_block'] = datetime.datetime.fromisoformat(r['date_block']) + tx_cache.append(o) return (lowest_block, highest_block, tx_cache) diff --git a/apps/cic-cache/cic_cache/runnable/daemons/query.py b/apps/cic-cache/cic_cache/runnable/daemons/query.py index 9e136f39..7250122f 100644 --- a/apps/cic-cache/cic_cache/runnable/daemons/query.py +++ b/apps/cic-cache/cic_cache/runnable/daemons/query.py @@ -1,6 +1,8 @@ # standard imports +import logging import json import re +import base64 # local imports from cic_cache.cache import ( @@ -8,6 +10,8 @@ from cic_cache.cache import ( DataCache, ) +logg = logging.getLogger(__name__) + re_transactions_all_bloom = r'/tx/(\d+)?/?(\d+)/?' re_transactions_account_bloom = r'/tx/user/((0x)?[a-fA-F0-9]+)/?(\d+)?/?(\d+)/?' re_transactions_all_data = re_transactions_all_bloom @@ -93,12 +97,16 @@ def process_transactions_all_data(session, env): c = DataCache(session) (lowest_block, highest_block, tx_cache) = c.load_transactions_with_data(offset, limit) + for r in tx_cache: + r['date_block'] = r['date_block'].timestamp() + o = { 'low': lowest_block, 'high': highest_block, 'data': tx_cache, } + j = json.dumps(o) return ('application/json', j.encode('utf-8'),)