Split up backend modules
This commit is contained in:
parent
3b40f0e6f6
commit
7f0936b3e4
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())
|
||||
|
@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = chainsyncer
|
||||
version = 0.0.1a22
|
||||
version = 0.0.2a1
|
||||
description = Generic blockchain syncer driver
|
||||
author = Louis Holbrook
|
||||
author_email = dev@holbrook.no
|
||||
|
@ -5,7 +5,7 @@ import unittest
|
||||
from chainlib.chain import ChainSpec
|
||||
|
||||
# local imports
|
||||
from chainsyncer.backend import SyncerBackend
|
||||
from chainsyncer.backend.memory import MemBackend
|
||||
|
||||
# testutil imports
|
||||
from tests.base import TestBase
|
||||
@ -15,7 +15,7 @@ class TestBasic(TestBase):
|
||||
|
||||
def test_hello(self):
|
||||
chain_spec = ChainSpec('evm', 'bloxberg', 8996, 'foo')
|
||||
backend = SyncerBackend(chain_spec, 'foo')
|
||||
backend = MemBackend(chain_spec, 'foo')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -8,7 +8,7 @@ from chainlib.chain import ChainSpec
|
||||
# local imports
|
||||
from chainsyncer.db.models.base import SessionBase
|
||||
from chainsyncer.db.models.filter import BlockchainSyncFilter
|
||||
from chainsyncer.backend import SyncerBackend
|
||||
from chainsyncer.backend.sql import SyncerBackend
|
||||
|
||||
# testutil imports
|
||||
from tests.base import TestBase
|
||||
@ -67,6 +67,7 @@ class TestDatabase(TestBase):
|
||||
|
||||
session.close()
|
||||
|
||||
|
||||
def test_backend_retrieve(self):
|
||||
s = SyncerBackend.live(self.chain_spec, 42)
|
||||
s.register_filter('foo')
|
||||
|
@ -9,7 +9,7 @@ import shutil
|
||||
from chainlib.chain import ChainSpec
|
||||
|
||||
# local imports
|
||||
from chainsyncer.backend_file import SyncerFileBackend
|
||||
from chainsyncer.backend.file import SyncerFileBackend
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger().getChild(__name__)
|
||||
|
Loading…
Reference in New Issue
Block a user