Split up backend modules
This commit is contained in:
51
chainsyncer/backend/memory.py
Normal file
51
chainsyncer/backend/memory.py
Normal file
@@ -0,0 +1,51 @@
|
||||
# standard imports
|
||||
import logging
|
||||
|
||||
logg = logging.getLogger().getChild(__name__)
|
||||
|
||||
|
||||
class MemBackend:
|
||||
|
||||
def __init__(self, chain_spec, object_id, target_block=None):
|
||||
self.object_id = object_id
|
||||
self.chain_spec = chain_spec
|
||||
self.block_height = 0
|
||||
self.tx_height = 0
|
||||
self.flags = 0
|
||||
self.target_block = target_block
|
||||
self.db_session = None
|
||||
|
||||
|
||||
def connect(self):
|
||||
pass
|
||||
|
||||
|
||||
def disconnect(self):
|
||||
pass
|
||||
|
||||
|
||||
def set(self, block_height, tx_height):
|
||||
logg.debug('stateless backend received {} {}'.format(block_height, tx_height))
|
||||
self.block_height = block_height
|
||||
self.tx_height = tx_height
|
||||
|
||||
|
||||
def get(self):
|
||||
return ((self.block_height, self.tx_height), self.flags)
|
||||
|
||||
|
||||
def target(self):
|
||||
return (self.target_block, self.flags)
|
||||
|
||||
|
||||
def register_filter(self, name):
|
||||
pass
|
||||
|
||||
|
||||
def complete_filter(self, n):
|
||||
pass
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return "syncer membackend chain {} cursor".format(self.get())
|
||||
|
||||
@@ -10,7 +10,7 @@ from chainsyncer.db.models.sync import BlockchainSync
|
||||
from chainsyncer.db.models.filter import BlockchainSyncFilter
|
||||
from chainsyncer.db.models.base import SessionBase
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
logg = logging.getLogger().getChild(__name__)
|
||||
|
||||
|
||||
class SyncerBackend:
|
||||
@@ -287,57 +287,12 @@ class SyncerBackend:
|
||||
|
||||
|
||||
def complete_filter(self, n):
|
||||
self.connect()
|
||||
self.db_object_filter.set(n)
|
||||
|
||||
self.db_session.add(self.db_object_filter)
|
||||
self.db_session.commit()
|
||||
self.disconnect()
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return "syncerbackend chain {} start {} target {}".format(self.chain(), self.start(), self.target())
|
||||
|
||||
|
||||
|
||||
class MemBackend:
|
||||
|
||||
def __init__(self, chain_spec, object_id, target_block=None):
|
||||
self.object_id = object_id
|
||||
self.chain_spec = chain_spec
|
||||
self.block_height = 0
|
||||
self.tx_height = 0
|
||||
self.flags = 0
|
||||
self.target_block = target_block
|
||||
self.db_session = None
|
||||
|
||||
|
||||
def connect(self):
|
||||
pass
|
||||
|
||||
|
||||
def disconnect(self):
|
||||
pass
|
||||
|
||||
|
||||
def set(self, block_height, tx_height):
|
||||
logg.debug('stateless backend received {} {}'.format(block_height, tx_height))
|
||||
self.block_height = block_height
|
||||
self.tx_height = tx_height
|
||||
|
||||
|
||||
def get(self):
|
||||
return ((self.block_height, self.tx_height), self.flags)
|
||||
|
||||
|
||||
def target(self):
|
||||
return (self.target_block, self.flags)
|
||||
|
||||
|
||||
def register_filter(self, name):
|
||||
pass
|
||||
|
||||
|
||||
def complete_filter(self, n):
|
||||
pass
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return "syncer membackend chain {} cursor".format(self.get())
|
||||
|
||||
Reference in New Issue
Block a user