generate keys in batches of 2000s

This commit is contained in:
Victor Shyba 2018-10-10 17:21:38 -03:00 committed by Lex Berezhny
parent c6f2d8b6fc
commit 4b9c3e8409

View file

@ -108,13 +108,22 @@ class HierarchicalDeterministic(AddressManager):
@defer.inlineCallbacks
def generate_keys(self, start: int, end: int) -> defer.Deferred:
new_keys = []
keys_batch, final_keys = [], []
for index in range(start, end+1):
new_keys.append((index, self.public_key.child(index)))
keys_batch.append((index, self.public_key.child(index)))
if len(keys_batch) % 2000 == 0:
yield self.db.add_keys(
self.account, self.chain_number, new_keys
self.account, self.chain_number, keys_batch
)
return [key[1].address for key in new_keys]
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
def get_max_gap(self) -> defer.Deferred: