simplify generate_keys

This commit is contained in:
Victor Shyba 2019-01-29 14:27:46 -03:00 committed by Lex Berezhny
parent e1c0caa357
commit 19e326c140

View file

@ -134,16 +134,9 @@ class HierarchicalDeterministic(AddressManager):
async def _generate_keys(self, start: int, end: int) -> List[str]: async def _generate_keys(self, start: int, end: int) -> List[str]:
if not self.address_generator_lock.locked(): if not self.address_generator_lock.locked():
raise RuntimeError('Should not be called outside of address_generator_lock.') raise RuntimeError('Should not be called outside of address_generator_lock.')
keys_batch, final_keys = [], [] keys = [(index, self.public_key.child(index)) for index in range(start, end+1)]
for index in range(start, end+1): await self.account.ledger.db.add_keys(self.account, self.chain_number, keys)
keys_batch.append((index, self.public_key.child(index))) return [key[1].address for key in keys]
if index % 180 == 0 or index == end:
await self.account.ledger.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]
def get_address_records(self, only_usable: bool = False, **constraints): def get_address_records(self, only_usable: bool = False, **constraints):
if only_usable: if only_usable: