4
0
mirror of git://holbrook.no/eth-monitor.git synced 2024-12-03 16:16:45 +01:00

WIP move rules compilation to settings module

This commit is contained in:
lash 2022-05-10 11:25:05 +00:00
parent 239e10ba5a
commit 80eee2b779
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 112 additions and 47 deletions

View File

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

View File

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

View File

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

View File

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

View File

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