Reorganize url path params in cic-cache-server
This commit is contained in:
parent
99b0fb5aed
commit
ad1c241a85
@ -19,26 +19,57 @@ from cic_cache.cache import (
|
|||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
#logg = logging.getLogger()
|
#logg = logging.getLogger()
|
||||||
|
|
||||||
re_transactions_all_bloom = r'/tx/(\d+)?/?(\d+)/?'
|
re_transactions_all_bloom = r'/tx/(\d+)?/?(\d+)/?(\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 = r'/txa/(\d+)?/?(\d+)/?'
|
re_transactions_all_data = r'/txa/(\d+)/?(\d+)?/?(\d+)?/?(\d+)?/?'
|
||||||
re_transactions_account_data = r'/txa/user/((0x)?[a-fA-F0-9]+)(/(\d+)(/(\d+))?)?/?'
|
re_transactions_account_data = r'/txa/user/((0x)?[a-fA-F0-9]+)(/(\d+)(/(\d+))?)?/?'
|
||||||
|
|
||||||
DEFAULT_LIMIT = 100
|
DEFAULT_LIMIT = 100
|
||||||
|
|
||||||
|
|
||||||
|
def parse_query_account(r):
|
||||||
|
address = strip_0x(r[1])
|
||||||
|
limit = DEFAULT_LIMIT
|
||||||
|
g = r.groups()
|
||||||
|
if len(g) > 3:
|
||||||
|
limit = r[4]
|
||||||
|
offset = 0
|
||||||
|
if len(g) > 4:
|
||||||
|
offset = r[6]
|
||||||
|
|
||||||
|
logg.debug('account query is address {} offset {} limit {}'.format(address, offset, limit))
|
||||||
|
|
||||||
|
return (address, offset, limit,)
|
||||||
|
|
||||||
|
|
||||||
|
# r is an re.Match
|
||||||
|
def parse_query_any(r):
|
||||||
|
limit = DEFAULT_LIMIT
|
||||||
|
if r.lastindex > 0:
|
||||||
|
limit = int(r[1])
|
||||||
|
offset = 0
|
||||||
|
if r.lastindex > 1:
|
||||||
|
offset = int(r[2])
|
||||||
|
block_offset = None
|
||||||
|
if r.lastindex > 2:
|
||||||
|
block_offset = int(r[3])
|
||||||
|
block_end = None
|
||||||
|
if r.lastindex > 3:
|
||||||
|
block_end = int(r[4])
|
||||||
|
if block_end < block_offset:
|
||||||
|
raise ValueError('cart before the horse, dude')
|
||||||
|
|
||||||
|
logg.debug('data query is offset {} limit {} block_offset {} block_end {}'.format(offset, limit, block_offset, block_end))
|
||||||
|
|
||||||
|
return (offset, limit, block_offset, block_end,)
|
||||||
|
|
||||||
|
|
||||||
def process_transactions_account_bloom(session, env):
|
def process_transactions_account_bloom(session, env):
|
||||||
r = re.match(re_transactions_account_bloom, env.get('PATH_INFO'))
|
r = re.match(re_transactions_account_bloom, env.get('PATH_INFO'))
|
||||||
if not r:
|
if not r:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
address = strip_0x(r[1])
|
(address, offset, limit,) = parse_query_account(r)
|
||||||
offset = 0
|
|
||||||
if r.lastindex > 2:
|
|
||||||
offset = r[4]
|
|
||||||
limit = DEFAULT_LIMIT
|
|
||||||
if r.lastindex > 4:
|
|
||||||
limit = r[6]
|
|
||||||
|
|
||||||
c = BloomCache(session)
|
c = BloomCache(session)
|
||||||
(lowest_block, highest_block, bloom_filter_block, bloom_filter_tx) = c.load_transactions_account(address, offset, limit)
|
(lowest_block, highest_block, bloom_filter_block, bloom_filter_tx) = c.load_transactions_account(address, offset, limit)
|
||||||
@ -62,12 +93,7 @@ def process_transactions_all_bloom(session, env):
|
|||||||
if not r:
|
if not r:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
offset = DEFAULT_LIMIT
|
(limit, offset, block_offset, block_end,) = parse_query_any(r)
|
||||||
if r.lastindex > 0:
|
|
||||||
offset = r[1]
|
|
||||||
limit = 0
|
|
||||||
if r.lastindex > 1:
|
|
||||||
limit = r[2]
|
|
||||||
|
|
||||||
c = BloomCache(session)
|
c = BloomCache(session)
|
||||||
(lowest_block, highest_block, bloom_filter_block, bloom_filter_tx) = c.load_transactions(offset, limit)
|
(lowest_block, highest_block, bloom_filter_block, bloom_filter_tx) = c.load_transactions(offset, limit)
|
||||||
@ -90,17 +116,15 @@ def process_transactions_all_data(session, env):
|
|||||||
r = re.match(re_transactions_all_data, env.get('PATH_INFO'))
|
r = re.match(re_transactions_all_data, env.get('PATH_INFO'))
|
||||||
if not r:
|
if not r:
|
||||||
return None
|
return None
|
||||||
if env.get('HTTP_X_CIC_CACHE_MODE') != 'all':
|
#if env.get('HTTP_X_CIC_CACHE_MODE') != 'all':
|
||||||
return None
|
# return None
|
||||||
|
|
||||||
logg.debug('got data request {}'.format(env))
|
logg.debug('got data request {}'.format(env))
|
||||||
block_offset = r[1]
|
|
||||||
block_end = r[2]
|
(offset, limit, block_offset, block_end) = parse_query_any(r)
|
||||||
if int(r[2]) < int(r[1]):
|
|
||||||
raise ValueError('cart before the horse, dude')
|
|
||||||
|
|
||||||
c = DataCache(session)
|
c = DataCache(session)
|
||||||
(lowest_block, highest_block, tx_cache) = c.load_transactions_with_data(0, 0, block_offset, block_end, oldest=True) # oldest needs to be settable
|
(lowest_block, highest_block, tx_cache) = c.load_transactions_with_data(offset, limit, block_offset, block_end, oldest=True) # oldest needs to be settable
|
||||||
|
|
||||||
for r in tx_cache:
|
for r in tx_cache:
|
||||||
r['date_block'] = r['date_block'].timestamp()
|
r['date_block'] = r['date_block'].timestamp()
|
||||||
@ -121,19 +145,10 @@ def process_transactions_account_data(session, env):
|
|||||||
r = re.match(re_transactions_account_data, env.get('PATH_INFO'))
|
r = re.match(re_transactions_account_data, env.get('PATH_INFO'))
|
||||||
if not r:
|
if not r:
|
||||||
return None
|
return None
|
||||||
if env.get('HTTP_X_CIC_CACHE_MODE') != 'all':
|
#if env.get('HTTP_X_CIC_CACHE_MODE') != 'all':
|
||||||
return None
|
# return None
|
||||||
|
|
||||||
logg.debug('got data request {}'.format(env))
|
(address, offset, limit,) = parse_query_account(r)
|
||||||
address = strip_0x(r[1])
|
|
||||||
#if r[2] == None:
|
|
||||||
# address = add_0x(address)
|
|
||||||
offset = 0
|
|
||||||
if r.lastindex > 2:
|
|
||||||
offset = r[4]
|
|
||||||
limit = DEFAULT_LIMIT
|
|
||||||
if r.lastindex > 4:
|
|
||||||
limit = r[6]
|
|
||||||
|
|
||||||
c = DataCache(session)
|
c = DataCache(session)
|
||||||
(lowest_block, highest_block, tx_cache) = c.load_transactions_account_with_data(address, offset, limit)
|
(lowest_block, highest_block, tx_cache) = c.load_transactions_account_with_data(address, offset, limit)
|
||||||
|
@ -160,6 +160,14 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- signer-data:/run/crypto-dev-signer
|
- signer-data:/run/crypto-dev-signer
|
||||||
- contract-config:/tmp/cic/config/:ro
|
- contract-config:/tmp/cic/config/:ro
|
||||||
|
command:
|
||||||
|
- /bin/bash
|
||||||
|
- -c
|
||||||
|
- |
|
||||||
|
set -a
|
||||||
|
if [[ -f /tmp/cic/config/env_reset ]]; then source /tmp/cic/config/env_reset; fi
|
||||||
|
set +a
|
||||||
|
./start_tasker.sh --aux-all -q cic-eth -vv
|
||||||
|
|
||||||
|
|
||||||
cic-eth-tracker:
|
cic-eth-tracker:
|
||||||
|
Loading…
Reference in New Issue
Block a user