4
0
mirror of git://holbrook.no/eth-monitor.git synced 2024-11-21 20:06:46 +01:00

Allow filter and renderers set with config, envs

This commit is contained in:
lash 2022-03-06 19:42:01 +00:00
parent ac76ceb985
commit e1f411443c
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
7 changed files with 84 additions and 21 deletions

View File

@ -1,3 +1,5 @@
- 0.2.0
* Dependency upgrades
- 0.1.0 - 0.1.0
* Read blocks, tx, rcpt from cache * Read blocks, tx, rcpt from cache
* Read include and exclude address lists from cli options * Read include and exclude address lists from cli options

56
eth_monitor/config.py Normal file
View File

@ -0,0 +1,56 @@
# standard imports
import re
import logging
logg = logging.getLogger(__name__)
re_env='^ETHMONITOR_({}_(.+))$'
def __override_env(config, config_stem, env):
re_env_instance = re_env.format(config_stem)
for k in env:
r = re.search(re_env_instance, k)
if r != None:
logg.debug('match renderer environment variable: {} '.format(r.group(1)))
config.add(env[k], r.group(1), True)
def __override_arg(config, config_stem, args):
if args == None:
return
args_array = getattr(args, config_stem.lower())
if args_array == None:
return
i = 0
for a in args_array:
s = config_stem + '_ARG_' + str(i)
config.add(a, s, True)
i += 1
def override(config, keyword, env={}, args=None):
config_stem = keyword.upper()
__override_arg(config, config_stem, args)
__override_env(config, config_stem, env)
def list_from_prefix(config, keyword):
re_config = keyword.upper() + '_'
k_default = re_config + 'DEFAULT'
r = []
for k in config.all():
if re.match(re_config, k):
v = config.get(k)
if k == k_default:
try:
v = v.split(',')
except AttributeError:
continue
r.append(v)
return r

View File

@ -0,0 +1,2 @@
[filter]
default =

View File

@ -0,0 +1,2 @@
[renderer]
default =

View File

@ -31,6 +31,7 @@ from eth_monitor.rules import (
) )
from eth_monitor.filters import RuledFilter from eth_monitor.filters import RuledFilter
from eth_monitor.filters.out import OutFilter from eth_monitor.filters.out import OutFilter
from eth_monitor.config import override, list_from_prefix
logging.basicConfig(level=logging.WARNING) logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger() logg = logging.getLogger()
@ -104,9 +105,9 @@ config.add(args.offset, '_SYNC_OFFSET', True)
config.add(args.skip_history, '_NO_HISTORY', True) config.add(args.skip_history, '_NO_HISTORY', True)
config.add(args.single, '_SINGLE', True) config.add(args.single, '_SINGLE', True)
config.add(args.head, '_HEAD', True) config.add(args.head, '_HEAD', True)
logg.debug('loaded config:\{}'.format(config)) override(config, 'renderer', env=os.environ, args=args)
override(config, 'filter', env=os.environ, args=args)
logg.debug('config loaded:\n{}'.format(config)) logg.debug('loaded config:\n{}'.format(config))
chain_spec = ChainSpec.from_chain_str(args.i) chain_spec = ChainSpec.from_chain_str(args.i)
@ -326,11 +327,17 @@ def main():
cache_filter, cache_filter,
] ]
if args.filter != None: for fltr in list_from_prefix(config, 'filter'):
for fltr in args.filter:
m = importlib.import_module(fltr) m = importlib.import_module(fltr)
fltr_object = m.Filter(rules_filter=address_rules) fltr_object = m.Filter(rules_filter=address_rules)
filters.append(fltr_object) filters.append(fltr_object)
logg.info('using filter module {}'.format(fltr))
renderers_mods = []
for renderer in list_from_prefix(config, 'renderer'):
m = importlib.import_module(renderer)
renderers_mods.append(m)
logg.info('using renderer module {}'.format(renderer))
syncer_setup_func = None syncer_setup_func = None
if config.true('_HEAD'): if config.true('_HEAD'):
@ -352,11 +359,6 @@ def main():
skip_history=config.true('_NO_HISTORY'), skip_history=config.true('_NO_HISTORY'),
) )
renderers_mods = []
for renderer in args.renderer:
m = importlib.import_module(renderer)
renderers_mods.append(m)
out_filter = OutFilter(chain_spec, rules_filter=address_rules, renderers=renderers_mods) out_filter = OutFilter(chain_spec, rules_filter=address_rules, renderers=renderers_mods)
filters.append(out_filter) filters.append(out_filter)

View File

@ -1,6 +1,6 @@
chainlib-eth>=0.1.0b3,<=0.1.0 chainlib-eth>=0.1.0b4,<=0.1.0
chainlib~=0.0.23 chainlib>=0.1.0b1,<=0.1.0
chainsyncer~=0.1.0 chainsyncer~=0.2.0
eth-erc20~=0.1.11 eth-erc20~=0.2.0
leveldir~=0.3.0 leveldir~=0.3.0
eth-cache~=0.1.0 eth-cache~=0.1.0

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = eth-monitor name = eth-monitor
version = 0.1.0rc1 version = 0.2.0
description = Monitor and cache transactions using match filters description = Monitor and cache transactions using match filters
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no
@ -31,7 +31,6 @@ packages =
eth_monitor eth_monitor
eth_monitor.importers eth_monitor.importers
eth_monitor.filters eth_monitor.filters
eth_monitor.store
eth_monitor.runnable eth_monitor.runnable
eth_monitor.mock eth_monitor.mock