From e36e4c6354555bea759aa74be117d33493e03770 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Sun, 15 Jul 2018 00:40:46 -0400 Subject: [PATCH] pubkey should stay as blob --- torba/basedatabase.py | 4 +-- torba/baseledger.py | 61 ++++++++++++++++++++++--------------------- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/torba/basedatabase.py b/torba/basedatabase.py index 82026afad..a850aa2b7 100644 --- a/torba/basedatabase.py +++ b/torba/basedatabase.py @@ -88,7 +88,7 @@ class BaseDatabase(SQLiteMixin): account text not null, chain integer not null, position integer not null, - pubkey text not null, + pubkey blob not null, history text, used_times integer not null default 0 ); @@ -270,7 +270,7 @@ class BaseDatabase(SQLiteMixin): values.append(account.public_key.address) values.append(chain) values.append(position) - values.append(pubkey.pubkey_bytes) + values.append(sqlite3.Binary(pubkey.pubkey_bytes)) return self.db.runOperation(sql, values) @staticmethod diff --git a/torba/baseledger.py b/torba/baseledger.py index f62816957..f07b5c3b6 100644 --- a/torba/baseledger.py +++ b/torba/baseledger.py @@ -269,41 +269,42 @@ class BaseLedger(six.with_metaclass(LedgerRegistry)): yield lock.acquire() - #try: - # see if we have a local copy of transaction, otherwise fetch it from server - raw, local_height, is_verified = yield self.db.get_transaction(hex_id) - save_tx = None - if raw is None: - _raw = yield self.network.get_transaction(hex_id) - tx = self.transaction_class(unhexlify(_raw)) - save_tx = 'insert' - else: - tx = self.transaction_class(raw) + try: - if remote_height > 0 and not is_verified: - is_verified = yield self.is_valid_transaction(tx, remote_height) - is_verified = 1 if is_verified else 0 - if save_tx is None: - save_tx = 'update' + # see if we have a local copy of transaction, otherwise fetch it from server + raw, local_height, is_verified = yield self.db.get_transaction(hex_id) + save_tx = None + if raw is None: + _raw = yield self.network.get_transaction(hex_id) + tx = self.transaction_class(unhexlify(_raw)) + save_tx = 'insert' + else: + tx = self.transaction_class(raw) - yield self.db.save_transaction_io( - save_tx, tx, remote_height, is_verified, address, self.address_to_hash160(address), - ''.join('{}:{}:'.format(tx_id, tx_height) for tx_id, tx_height in synced_history) - ) + if remote_height > 0 and not is_verified: + is_verified = yield self.is_valid_transaction(tx, remote_height) + is_verified = 1 if is_verified else 0 + if save_tx is None: + save_tx = 'update' - log.debug("{}: sync'ed tx {} for address: {}, height: {}, verified: {}".format( - self.get_id(), hex_id, address, remote_height, is_verified - )) - self._on_transaction_controller.add(TransactionEvent(address, tx, remote_height, is_verified)) + yield self.db.save_transaction_io( + save_tx, tx, remote_height, is_verified, address, self.address_to_hash160(address), + ''.join('{}:{}:'.format(tx_id, tx_height) for tx_id, tx_height in synced_history) + ) - #except: - # log.exception('Failed to synchronize transaction:') - # raise + log.debug("{}: sync'ed tx {} for address: {}, height: {}, verified: {}".format( + self.get_id(), hex_id, address, remote_height, is_verified + )) + self._on_transaction_controller.add(TransactionEvent(address, tx, remote_height, is_verified)) - #finally: - lock.release() - if not lock.locked: - del self._transaction_processing_locks[hex_id] + except: + log.exception('Failed to synchronize transaction:') + raise + + finally: + lock.release() + if not lock.locked: + del self._transaction_processing_locks[hex_id] @defer.inlineCallbacks def subscribe_history(self, address):