commit 8b085083ef197bce5f950fa9f231e0bac64153de
parent 63993cc223a0071616681efa352db4274cda66f4
Author: lash <dev@holbrook.no>
Date: Mon, 7 Aug 2023 12:43:11 +0100
Add filter initialization hook on session startup
Diffstat:
6 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,3 +1,5 @@
+* 0.8.2
+ - Add filter prepare method (with context) to interface
* 0.8.1
- Add context field to receive key-value collections from calling agent
* 0.8.0
diff --git a/chainsyncer/driver/base.py b/chainsyncer/driver/base.py
@@ -64,7 +64,7 @@ class SyncDriver:
def run(self, conn, interval=1, ctx=None):
while self.running_global:
self.session = SyncSession(self.store, ctx=ctx)
- self.item = self.session.start()
+ self.item = self.session.start(ctx=ctx)
if self.item == None:
self.running = False
self.running_global = False
@@ -129,7 +129,6 @@ class SyncDriver:
if self.post_callback != None:
self.post_callback(conn)
-
self.idle(interval)
diff --git a/chainsyncer/filter.py b/chainsyncer/filter.py
@@ -11,6 +11,10 @@ re_processedname = r'^_?[A-Z,\.]*$'
class SyncFilter:
+ def prepare(self, ctx=None):
+ return
+
+
def sum(self):
s = self.common_name()
h = hashlib.sha256()
@@ -61,6 +65,8 @@ class FilterState:
self.scan = scan
+ self.filters = []
+
def __verify_sum(self, v):
if not isinstance(v, bytes) and not isinstance(v, bytearray):
@@ -125,7 +131,3 @@ class FilterState:
def next_item(self):
return None
-
-
- def filters(self):
- return []
diff --git a/chainsyncer/session.py b/chainsyncer/session.py
@@ -23,9 +23,11 @@ class SyncSession:
return self.session_store.get(str(k))
- def start(self, offset=0, target=-1):
+ def start(self, offset=0, target=-1, ctx=None):
self.session_store.start(offset=offset, target=target)
self.item = self.session_store.next_item()
+ for fltr in self.filters:
+ fltr.prepare(ctx=ctx)
return self.item
diff --git a/chainsyncer/unittest/base.py b/chainsyncer/unittest/base.py
@@ -11,6 +11,7 @@ from shep.state import State
#from chainsyncer.driver.history import HistorySyncer
from chainsyncer.error import NoBlockForYou
from chainsyncer.driver import SyncDriver
+from chainsyncer.filter import SyncFilter
logging.STATETRACE = 5
logging.addLevelName('STATETRACE', logging.STATETRACE)
@@ -135,7 +136,7 @@ class MockStore(State):
pass
-class MockFilter:
+class MockFilter(SyncFilter):
def __init__(self, name, brk=None, brk_hard=None, z=None):
self.name = name
diff --git a/setup.cfg b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = chainsyncer
-version = 0.8.1
+version = 0.8.2
description = Generic blockchain syncer driver
author = Louis Holbrook
author_email = dev@holbrook.no