handle string datetime format in tx list

This commit is contained in:
nolash 2021-05-18 17:32:58 +02:00
parent 8eb4e9631b
commit f1f5253865
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 19 additions and 0 deletions

View File

@ -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)

View File

@ -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'),)