commit 8c67758b10e4669c4debb699235c06178a4a87eb
parent 991e909a2cf3482302bd9325264867a25e4528db
Author: nolash <dev@holbrook.no>
Date: Wed, 3 Feb 2021 23:32:19 +0100
Stub for dynamic method/domain (task/queue) callback
Diffstat:
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/cic_syncer/driver.py b/cic_syncer/driver.py
@@ -10,11 +10,12 @@ class Syncer:
running_global = True
- def __init__(self, backend):
+ def __init__(self, backend, handler):
self.cursor = None
self.running = True
self.backend = backend
self.filter = []
+ self.handler = handler
def chain(self):
@@ -29,8 +30,8 @@ class Syncer:
class MinedSyncer(Syncer):
- def __init__(self, backend):
- super(MinedSyncer, self).__init__(backend)
+ def __init__(self, backend, handler):
+ super(MinedSyncer, self).__init__(backend, handler)
def loop(self, interval, getter):
@@ -43,8 +44,8 @@ class MinedSyncer(Syncer):
class HeadSyncer(MinedSyncer):
- def __init__(self, backend):
- super(HeadSyncer, self).__init__(backend)
+ def __init__(self, backend, handler):
+ super(HeadSyncer, self).__init__(backend, handler)
def process(self, getter, block):
@@ -54,6 +55,7 @@ class HeadSyncer(MinedSyncer):
tx = None
while True:
try:
+ self.filter[0].handle(getter, block, None)
tx = block.tx(i)
logg.debug('tx {}'.format(tx))
self.backend.set(block.number(), i)
diff --git a/cic_syncer/runnable/tracker.py b/cic_syncer/runnable/tracker.py
@@ -21,6 +21,18 @@ logg = logging.getLogger()
config_dir = '/usr/local/etc/cic-syncer'
+
+class Handler:
+
+ def __init__(self, method, domain):
+ self.method = method
+ self.domain = domain
+
+ def handle(self, getter, tx, chain):
+ logg.debug('noop tx {} chain {} method {} domain {}'.format(tx, chain, self.method, self.domain))
+handler = getattr(Handler, 'handle')
+
+
argparser = argparse.ArgumentParser(description='daemon that monitors transactions in new blocks')
argparser.add_argument('-p', '--provider', dest='p', type=str, help='chain rpc provider address')
argparser.add_argument('-c', type=str, default=config_dir, help='config root to use')
@@ -58,7 +70,6 @@ queue = args.q
dsn = dsn_from_config(config)
SessionBase.connect(dsn)
-# TODO: There is too much code in this file, split it up
transfer_callbacks = []
for cb in config.get('TASKS_SYNCER_CALLBACKS', '').split(','):
@@ -100,7 +111,7 @@ def main():
block_offset = c.block_number()
syncer_backend = SyncerBackend.live(chain, block_offset+1)
- syncer = HeadSyncer(syncer_backend)
+ syncer = HeadSyncer(syncer_backend, handler)
for cb in config.get('TASKS_SYNCER_CALLBACKS', '').split(','):
task_split = cb.split(':')
@@ -108,7 +119,8 @@ def main():
if len(task_split) > 1:
task_queue = task_split[0]
task_pair = (task_split[1], task_queue)
- syncer.filter.append(task_pair)
+ h = Handler(task_pair[0], task_pair[1])
+ syncer.filter.append(h)
try:
logg.debug('block offset {} {}'.format(block_offset, c))