handle string datetime format in tx list
This commit is contained in:
parent
8eb4e9631b
commit
f1f5253865
@ -1,5 +1,6 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
import logging
|
import logging
|
||||||
|
import datetime
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
import moolb
|
import moolb
|
||||||
@ -101,13 +102,19 @@ class DataCache(Cache):
|
|||||||
tx_cache = []
|
tx_cache = []
|
||||||
highest_block = -1;
|
highest_block = -1;
|
||||||
lowest_block = -1;
|
lowest_block = -1;
|
||||||
|
date_is_str = None # stick this in startup
|
||||||
for r in rows:
|
for r in rows:
|
||||||
if highest_block == -1:
|
if highest_block == -1:
|
||||||
highest_block = r['block_number']
|
highest_block = r['block_number']
|
||||||
lowest_block = r['block_number']
|
lowest_block = r['block_number']
|
||||||
tx_type = 'unknown'
|
tx_type = 'unknown'
|
||||||
|
|
||||||
if r['value'] != None:
|
if r['value'] != None:
|
||||||
tx_type = '{}.{}'.format(r['domain'], r['value'])
|
tx_type = '{}.{}'.format(r['domain'], r['value'])
|
||||||
|
|
||||||
|
if date_is_str == None:
|
||||||
|
date_is_str = type(r['date_block']).__name__ == 'str'
|
||||||
|
|
||||||
o = {
|
o = {
|
||||||
'block_number': r['block_number'],
|
'block_number': r['block_number'],
|
||||||
'tx_hash': r['tx_hash'],
|
'tx_hash': r['tx_hash'],
|
||||||
@ -120,5 +127,9 @@ class DataCache(Cache):
|
|||||||
'destination_token': r['destination_token'],
|
'destination_token': r['destination_token'],
|
||||||
'tx_type': tx_type,
|
'tx_type': tx_type,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if date_is_str:
|
||||||
|
o['date_block'] = datetime.datetime.fromisoformat(r['date_block'])
|
||||||
|
|
||||||
tx_cache.append(o)
|
tx_cache.append(o)
|
||||||
return (lowest_block, highest_block, tx_cache)
|
return (lowest_block, highest_block, tx_cache)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
|
import logging
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
import base64
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from cic_cache.cache import (
|
from cic_cache.cache import (
|
||||||
@ -8,6 +10,8 @@ from cic_cache.cache import (
|
|||||||
DataCache,
|
DataCache,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
re_transactions_all_bloom = r'/tx/(\d+)?/?(\d+)/?'
|
re_transactions_all_bloom = r'/tx/(\d+)?/?(\d+)/?'
|
||||||
re_transactions_account_bloom = r'/tx/user/((0x)?[a-fA-F0-9]+)/?(\d+)?/?(\d+)/?'
|
re_transactions_account_bloom = r'/tx/user/((0x)?[a-fA-F0-9]+)/?(\d+)?/?(\d+)/?'
|
||||||
re_transactions_all_data = re_transactions_all_bloom
|
re_transactions_all_data = re_transactions_all_bloom
|
||||||
@ -93,12 +97,16 @@ def process_transactions_all_data(session, env):
|
|||||||
c = DataCache(session)
|
c = DataCache(session)
|
||||||
(lowest_block, highest_block, tx_cache) = c.load_transactions_with_data(offset, limit)
|
(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 = {
|
o = {
|
||||||
'low': lowest_block,
|
'low': lowest_block,
|
||||||
'high': highest_block,
|
'high': highest_block,
|
||||||
'data': tx_cache,
|
'data': tx_cache,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
j = json.dumps(o)
|
j = json.dumps(o)
|
||||||
|
|
||||||
return ('application/json', j.encode('utf-8'),)
|
return ('application/json', j.encode('utf-8'),)
|
||||||
|
Loading…
Reference in New Issue
Block a user