Use hex for digest

This commit is contained in:
nolash 2021-02-23 08:24:57 +01:00
parent 4b8d031b6c
commit 9bd61f71bb
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 10 additions and 10 deletions

View File

@ -3,14 +3,14 @@ import logging
import hashlib import hashlib
# external imports # external imports
from sqlalchemy import Column, String, Integer, BLOB, ForeignKey from sqlalchemy import Column, String, Integer, LargeBinary, ForeignKey
from sqlalchemy.ext.hybrid import hybrid_property, hybrid_method from sqlalchemy.ext.hybrid import hybrid_property, hybrid_method
# local imports # local imports
from .base import SessionBase from .base import SessionBase
from .sync import BlockchainSync from .sync import BlockchainSync
zero_digest = bytearray(32) zero_digest = bytes(32).hex()
logg = logging.getLogger(__name__) logg = logging.getLogger(__name__)
@ -19,9 +19,9 @@ class BlockchainSyncFilter(SessionBase):
__tablename__ = 'chain_sync_filter' __tablename__ = 'chain_sync_filter'
chain_sync_id = Column(Integer, ForeignKey('chain_sync.id')) chain_sync_id = Column(Integer, ForeignKey('chain_sync.id'))
flags_start = Column(BLOB) flags_start = Column(LargeBinary)
flags = Column(BLOB) flags = Column(LargeBinary)
digest = Column(BLOB) digest = Column(String(64))
count = Column(Integer) count = Column(Integer)
@ -42,7 +42,7 @@ class BlockchainSyncFilter(SessionBase):
def add(self, name): def add(self, name):
h = hashlib.new('sha256') h = hashlib.new('sha256')
h.update(self.digest) h.update(bytes.fromhex(self.digest))
h.update(name.encode('utf-8')) h.update(name.encode('utf-8'))
z = h.digest() z = h.digest()
@ -52,7 +52,7 @@ class BlockchainSyncFilter(SessionBase):
if old_byte_count != new_byte_count: if old_byte_count != new_byte_count:
self.flags = bytearray(1) + self.flags self.flags = bytearray(1) + self.flags
self.count += 1 self.count += 1
self.digest = z self.digest = z.hex()
def start(self): def start(self):

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = chainsyncer name = chainsyncer
version = 0.0.1a12 version = 0.0.1a14
description = Generic blockchain syncer driver description = Generic blockchain syncer driver
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no

View File

@ -5,7 +5,7 @@ CREATE TABLE IF NOT EXISTS chain_sync_filter (
flags bytea default null, flags bytea default null,
flags_start bytea default null, flags_start bytea default null,
count integer not null default 0, count integer not null default 0,
digest bytea not null, digest char(64) not null,
CONSTRAINT fk_chain_sync CONSTRAINT fk_chain_sync
FOREIGN KEY(chain_sync_id) FOREIGN KEY(chain_sync_id)
REFERENCES chain_sync(id) REFERENCES chain_sync(id)

View File

@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS chain_sync_filter (
flags bytea default null, flags bytea default null,
flags_start bytea default null, flags_start bytea default null,
count integer not null default 0, count integer not null default 0,
digest bytea not null, digest char(64) not null,
CONSTRAINT fk_chain_sync CONSTRAINT fk_chain_sync
FOREIGN KEY(chain_sync_id) FOREIGN KEY(chain_sync_id)
REFERENCES chain_sync(id) REFERENCES chain_sync(id)