eth-monitor

Monitor and cache ethereum transactions with match filters
git clone git://git.defalsify.org/eth-monitor.git
Log | Files | Refs | README | LICENSE

commit 80eee2b77922b683d11d8312d1df162855c5c566
parent 239e10ba5ad40e62313684822bcb968e34e8f91b
Author: lash <dev@holbrook.no>
Date:   Tue, 10 May 2022 11:25:05 +0000

WIP move rules compilation to settings module

Diffstat:
Meth_monitor/cli/arg.py | 24++++++++++++------------
Meth_monitor/cli/config.py | 13+++++++++++++
Meth_monitor/data/config/monitor.ini | 11++++++++---
Meth_monitor/runnable/sync.py | 35+++--------------------------------
Meth_monitor/settings.py | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 112 insertions(+), 47 deletions(-)

diff --git a/eth_monitor/cli/arg.py b/eth_monitor/cli/arg.py @@ -5,18 +5,18 @@ def process_flags(argparser, flags): argparser.add_argument('--cache-dir', dest='cache_dir', type=str, help='Directory to store tx data') # address rules flags - argparser.add_argument('--input', default=[], action='append', type=str, help='Add input (recipient) addresses to includes list') - argparser.add_argument('--output', default=[], action='append', type=str, help='Add output (sender) addresses to includes list') - argparser.add_argument('--exec', default=[], action='append', type=str, help='Add exec (contract) addresses to includes list') - argparser.add_argument('--data', default=[], action='append', type=str, help='Add data prefix strings to include list') - argparser.add_argument('--data-in', default=[], action='append', dest='data_in', type=str, help='Add data contain strings to include list') - argparser.add_argument('--x-data', default=[], action='append', dest='xdata', type=str, help='Add data prefix string to exclude list') - argparser.add_argument('--x-data-in', default=[], action='append', dest='xdata_in', type=str, help='Add data contain string to exclude list') - argparser.add_argument('--address', default=[], action='append', type=str, help='Add addresses as input, output and exec to includes list') - argparser.add_argument('--x-input', default=[], action='append', type=str, dest='xinput', help='Add input (recipient) addresses to excludes list') - argparser.add_argument('--x-output', default=[], action='append', type=str, dest='xoutput', help='Add output (sender) addresses to excludes list') - argparser.add_argument('--x-exec', default=[], action='append', type=str, dest='xexec', help='Add exec (contract) addresses to excludes list') - argparser.add_argument('--x-address', default=[], action='append', type=str, dest='xaddress', help='Add addresses as input, output and exec to excludes list') + argparser.add_argument('--input', action='append', type=str, help='Add input (recipient) addresses to includes list') + argparser.add_argument('--output', action='append', type=str, help='Add output (sender) addresses to includes list') + argparser.add_argument('--exec', action='append', type=str, help='Add exec (contract) addresses to includes list') + argparser.add_argument('--data', action='append', type=str, help='Add data prefix strings to include list') + argparser.add_argument('--data-in', action='append', dest='data_in', type=str, help='Add data contain strings to include list') + argparser.add_argument('--x-data', action='append', dest='xdata', type=str, help='Add data prefix string to exclude list') + argparser.add_argument('--x-data-in', action='append', dest='xdata_in', type=str, help='Add data contain string to exclude list') + argparser.add_argument('--address', action='append', type=str, help='Add addresses as input, output and exec to includes list') + argparser.add_argument('--x-input', action='append', type=str, dest='xinput', help='Add input (recipient) addresses to excludes list') + argparser.add_argument('--x-output', action='append', type=str, dest='xoutput', help='Add output (sender) addresses to excludes list') + argparser.add_argument('--x-exec', action='append', type=str, dest='xexec', help='Add exec (contract) addresses to excludes list') + argparser.add_argument('--x-address', action='append', type=str, dest='xaddress', help='Add addresses as input, output and exec to excludes list') argparser.add_argument('--includes-file', type=str, dest='includes_file', help='Load include rules from file') argparser.add_argument('--excludes-file', type=str, dest='excludes_file', help='Load exclude rules from file') argparser.add_argument('--include-default', dest='include_default', action='store_true', help='Include all transactions by default') diff --git a/eth_monitor/cli/config.py b/eth_monitor/cli/config.py @@ -1,4 +1,17 @@ def process_config(config, args, flags): + arg_override = {} + arg_override['ETHMONITOR_INPUTS'] = getattr(args, 'input') + arg_override['ETHMONITOR_OUTPUTS'] = getattr(args, 'output') + arg_override['ETHMONITOR_EXEC'] = getattr(args, 'exec') + arg_override['ETHMONITOR_ADDRESS'] = getattr(args, 'address') + arg_override['ETHMONITOR_X_INPUTS'] = getattr(args, 'xinput') + arg_override['ETHMONITOR_X_OUTPUTS'] = getattr(args, 'xoutput') + arg_override['ETHMONITOR_X_EXEC'] = getattr(args, 'xexec') + arg_override['ETHMONITOR_X_ADDRESS'] = getattr(args, 'xaddress') + arg_override['ETHMONITOR_INCLUDE_DEFAULT'] = getattr(args, 'include_default') + + config.dict_override(arg_override, 'local cli args') + config.add(getattr(args, 'session_id'), '_SESSION_ID', False) config.add(getattr(args, 'cache_dir'), '_CACHE_DIR', False) diff --git a/eth_monitor/data/config/monitor.ini b/eth_monitor/data/config/monitor.ini @@ -1,8 +1,13 @@ [ethmonitor] -input = -output = +inputs = +outputs = exec = +x_inputs = +x_outputs = +x_exec = +address = +x_address = renderer = filter = -default = 0 +include_default = 0 state_dir = diff --git a/eth_monitor/runnable/sync.py b/eth_monitor/runnable/sync.py @@ -122,31 +122,6 @@ logg.debug('loaded settings:\n{}'.format(settings)) #rpc = EthHTTPConnection(args.p) -def setup_address_arg_rules(rules, args): - include_inputs = args.input - include_outputs = args.output - include_exec = args.exec - exclude_inputs = args.xinput - exclude_outputs = args.xoutput - exclude_exec = args.xexec - - for address in args.address: - include_inputs.append(address) - include_outputs.append(address) - include_exec.append(address) - - for address in args.xaddress: - exclude_inputs.append(address) - exclude_outputs.append(address) - exclude_exec.append(address) - - includes = RuleSimple(include_outputs, include_inputs, include_exec, description='INCLUDE') - rules.include(includes) - - excludes = RuleSimple(exclude_outputs, exclude_inputs, exclude_exec, description='EXCLUDE') - rules.exclude(excludes) - - return rules def setup_data_arg_rules(rules, args): @@ -316,7 +291,9 @@ def main(): if block_limit == 0: block_limit = block_offset - address_rules = AddressRules(include_by_default=args.include_default) + sys.exit(0) + + #address_rules = AddressRules(include_by_default=args.include_default) address_rules = setup_data_arg_rules( address_rules, args, @@ -372,14 +349,8 @@ def main(): ) filters.append(out_filter) - #if state_dir == None: - # sync_store = syncer_store_class(session_id=config.get('_SESSION_ID'), state_event_callback=state_change_callback, filter_state_event_callback=filter_change_callback) - #else: - #sync_store = syncer_store_class(state_dir, session_id=config.get('_SESSION_ID'), state_event_callback=state_change_callback, filter_state_event_callback=filter_change_callback) logg.info('session is {}'.format(settings.get('SESSION_ID'))) - sys.exit(0) - for fltr in filters: sync_store.register(fltr) drv = ChainInterfaceDriver(sync_store, chain_interface, offset=session_block_offset, target=block_limit, pre_callback=pre_callback, post_callback=post_callback, block_callback=block_filter_handler.filter) diff --git a/eth_monitor/settings.py b/eth_monitor/settings.py @@ -9,6 +9,14 @@ from chainlib.settings import ChainSettings from chainsyncer.settings import ChainsyncerSettings from chainlib.eth.connection import EthHTTPConnection +# local imports +from eth_monitor.rules import ( + AddressRules, + RuleSimple, + RuleMethod, + RuleData, + ) + logg = logging.getLogger(__name__) @@ -53,6 +61,73 @@ class EthMonitorSettings(ChainsyncerSettings): self.o['SYNC_STORE'] = sync_store + #def process_address_arg_rules(rules, args): + def process_address_arg_rules(self, config): + include_inputs = config.get('ETHMONITOR_INPUTS') + if include_inputs == None: + include_inputs = [] + else: + include_inputs = include_inputs.split(',') + + include_outputs = config.get('ETHMONITOR_OUTPUTS') + if include_outputs == None: + include_outputs = [] + else: + include_outputs = include_outputs.split(',') + + include_exec = config.get('ETHMONITOR_EXEC') + if include_exec == None: + include_exec = [] + else: + include_exec = include_exec.split(',') + + exclude_inputs = config.get('ETHMONITOR_X_INPUTS') + if exclude_inputs == None: + exclude_inputs = [] + else: + exclude_inputs = exclude_inputs.split(',') + + exclude_outputs = config.get('ETHMONITOR_X_OUTPUTS') + if exclude_outputs == None: + exclude_outputs = [] + else: + exclude_outputs = exclude_outputs.split(',') + + exclude_exec = config.get('ETHMONITOR_X_EXEC') + if exclude_exec == None: + exclude_exec = [] + else: + exclude_exec = exclude_exec.split(',') + + + address = config.get('ETHMONITOR_ADDRESS') + if address != None: + for address in address.split(','): + include_inputs.append(address) + include_outputs.append(address) + include_exec.append(address) + + address = config.get('ETHMONITOR_X_ADDRESS') + if address != None: + for address in address.split(','): + exclude_inputs.append(address) + exclude_outputs.append(address) + exclude_exec.append(address) + + includes = RuleSimple(include_outputs, include_inputs, include_exec, description='INCLUDE') + self.o['RULES'].include(includes) + + excludes = RuleSimple(exclude_outputs, exclude_inputs, exclude_exec, description='EXCLUDE') + self.o['RULES'].exclude(excludes) + + + def process_arg_rules(self, config): + address_rules = AddressRules(include_by_default=config.get('ETHMONITOR_INCLUDE_DEFAULT')) + self.o['RULES'] = address_rules + + self.process_address_arg_rules(config) + + def process_common(self, config): super(EthMonitorSettings, self).process_common(config) # TODO: duplicate from chaind, consider move to chainlib-eth @@ -65,3 +140,4 @@ class EthMonitorSettings(ChainsyncerSettings): def process(self, config): self.process_common(config) self.process_monitor_session(config) + self.process_arg_rules(config)