From 55f5c7491c7fa04a522e293f3059e410866ade6c Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Thu, 11 Oct 2018 00:51:00 -0300 Subject: [PATCH] fixes from review for readability --- torba/baseaccount.py | 8 +------- torba/basedatabase.py | 12 ++++++------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/torba/baseaccount.py b/torba/baseaccount.py index a8616b650..fe35d9b37 100644 --- a/torba/baseaccount.py +++ b/torba/baseaccount.py @@ -111,18 +111,12 @@ class HierarchicalDeterministic(AddressManager): keys_batch, final_keys = [], [] for index in range(start, end+1): keys_batch.append((index, self.public_key.child(index))) - if len(keys_batch) % 180 == 0: + if index % 180 == 0 or index == end: yield self.db.add_keys( self.account, self.chain_number, keys_batch ) final_keys.extend(keys_batch) keys_batch.clear() - if keys_batch: - yield self.db.add_keys( - self.account, self.chain_number, keys_batch - ) - final_keys.extend(keys_batch) - keys_batch.clear() return [key[1].address for key in final_keys] @defer.inlineCallbacks diff --git a/torba/basedatabase.py b/torba/basedatabase.py index d47b05173..186c98d56 100644 --- a/torba/basedatabase.py +++ b/torba/basedatabase.py @@ -169,6 +169,10 @@ class SQLiteMixin: class BaseDatabase(SQLiteMixin): + PRAGMAS = """ + pragma journal_mode=WAL; + """ + CREATE_PUBKEY_ADDRESS_TABLE = """ create table if not exists pubkey_address ( address text primary key, @@ -221,10 +225,6 @@ class BaseDatabase(SQLiteMixin): create index if not exists txi_txoid_idx on txi (txoid); """ - PRAGMAS = """ - pragma journal_mode=WAL; - """ - CREATE_TABLES_QUERY = ( PRAGMAS + CREATE_TX_TABLE + @@ -480,10 +480,10 @@ class BaseDatabase(SQLiteMixin): ) + ', '.join(['(?, ?, ?, ?, ?)'] * len(keys)) values = [] for position, pubkey in keys: - values.extend([ + values.extend(( pubkey.address, account.public_key.address, chain, position, sqlite3.Binary(pubkey.pubkey_bytes) - ]) + )) return self.run_operation(sql, values) @classmethod