Handle new return format from backend getters
This commit is contained in:
parent
b69005682c
commit
d837602394
@ -51,6 +51,7 @@ class BlockchainSync(SessionBase):
|
||||
o = q.first()
|
||||
|
||||
if o == None:
|
||||
SessionBase.release_session(session)
|
||||
return None
|
||||
|
||||
sync_id = o.id
|
||||
|
@ -44,6 +44,7 @@ class Syncer:
|
||||
|
||||
def add_filter(self, f):
|
||||
self.filter.add(f)
|
||||
self.backend.register_filter(str(f))
|
||||
|
||||
|
||||
class BlockPollSyncer(Syncer):
|
||||
@ -53,7 +54,7 @@ class BlockPollSyncer(Syncer):
|
||||
|
||||
|
||||
def loop(self, interval, conn):
|
||||
g = self.backend.get()
|
||||
(g, flags) = self.backend.get()
|
||||
last_tx = g[1]
|
||||
last_block = g[0]
|
||||
self.progress_callback(last_block, last_tx, 'loop started')
|
||||
@ -63,7 +64,8 @@ class BlockPollSyncer(Syncer):
|
||||
while True:
|
||||
try:
|
||||
block = self.get(conn)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
logg.debug('erro {}'.format(e))
|
||||
break
|
||||
last_block = block.number
|
||||
self.process(conn, block)
|
||||
@ -97,7 +99,9 @@ class HeadSyncer(BlockPollSyncer):
|
||||
|
||||
|
||||
def get(self, conn):
|
||||
(block_number, tx_number) = self.backend.get()
|
||||
#(block_number, tx_number) = self.backend.get()
|
||||
(height, flags) = self.backend.get()
|
||||
block_number = height[0]
|
||||
block_hash = []
|
||||
o = block_by_number(block_number)
|
||||
r = conn.do(o)
|
||||
|
@ -21,7 +21,7 @@ class SyncFilter:
|
||||
def add(self, fltr):
|
||||
if getattr(fltr, 'filter') == None:
|
||||
raise ValueError('filter object must implement have method filter')
|
||||
logg.debug('added filter {}'.format(str(fltr)))
|
||||
logg.debug('added filter "{}"'.format(str(fltr)))
|
||||
|
||||
self.filters.append(fltr)
|
||||
|
||||
@ -38,7 +38,7 @@ class SyncFilter:
|
||||
i += 1
|
||||
logg.debug('applying filter {}'.format(str(f)))
|
||||
f.filter(conn, block, tx, self.backend.db_session)
|
||||
self.backend.set_filter()
|
||||
self.backend.complete_filter(i)
|
||||
self.backend.disconnect()
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = chainsyncer
|
||||
version = 0.0.1a10
|
||||
version = 0.0.1a11
|
||||
description = Generic blockchain syncer driver
|
||||
author = Louis Holbrook
|
||||
author_email = dev@holbrook.no
|
||||
|
@ -1,4 +1,4 @@
|
||||
DROP TABLE chain_sync;
|
||||
DROP TABLE IF EXISTS chain_sync CASCADE;
|
||||
CREATE TABLE IF NOT EXISTS chain_sync (
|
||||
id serial primary key not null,
|
||||
blockchain varchar not null,
|
||||
@ -6,21 +6,7 @@ CREATE TABLE IF NOT EXISTS chain_sync (
|
||||
tx_start int not null default 0,
|
||||
block_cursor int not null default 0,
|
||||
tx_cursor int not null default 0,
|
||||
flags bytea not null,
|
||||
num_flags int not null,
|
||||
block_target int default null,
|
||||
date_created timestamp not null,
|
||||
date_updated timestamp default null
|
||||
);
|
||||
|
||||
DROP TABLE chain_sync_filter;
|
||||
CREATE TABLE IF NOT EXISTS chain_sync_filter (
|
||||
id serial primary key not null,
|
||||
chain_sync_id int not null,
|
||||
flags bytea default null,
|
||||
count int not null default 0,
|
||||
digest char(64) not null default '0000000000000000000000000000000000000000000000000000000000000000',
|
||||
CONSTRAINT fk_chain_sync
|
||||
FOREIGN KEY(chain_sync_id)
|
||||
REFERENCES chain_sync(id)
|
||||
);
|
||||
|
12
sql/postgresql/2.sql
Normal file
12
sql/postgresql/2.sql
Normal file
@ -0,0 +1,12 @@
|
||||
DROP TABLE IF EXISTS chain_sync_filter;
|
||||
CREATE TABLE IF NOT EXISTS chain_sync_filter (
|
||||
id serial primary key not null,
|
||||
chain_sync_id integer not null,
|
||||
flags bytea default null,
|
||||
flags_start bytea default null,
|
||||
count integer not null default 0,
|
||||
digest bytea not null,
|
||||
CONSTRAINT fk_chain_sync
|
||||
FOREIGN KEY(chain_sync_id)
|
||||
REFERENCES chain_sync(id)
|
||||
);
|
@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS chain_sync_filter (
|
||||
flags bytea default null,
|
||||
flags_start bytea default null,
|
||||
count integer not null default 0,
|
||||
digest char(64) not null default '0000000000000000000000000000000000000000000000000000000000000000',
|
||||
digest bytea not null,
|
||||
CONSTRAINT fk_chain_sync
|
||||
FOREIGN KEY(chain_sync_id)
|
||||
REFERENCES chain_sync(id)
|
||||
|
Loading…
Reference in New Issue
Block a user