From d7c2e4e9b36cc96718d67052de38cb96f45a613c Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Sat, 4 May 2019 17:22:32 -0400 Subject: [PATCH] fixed bug where lbrynet failed to start with single-key accounts in the wallet --- lbrynet/wallet/account.py | 11 ++++++----- tests/unit/wallet/test_account.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lbrynet/wallet/account.py b/lbrynet/wallet/account.py index 23c7da7f7..9b6e2165d 100644 --- a/lbrynet/wallet/account.py +++ b/lbrynet/wallet/account.py @@ -4,7 +4,7 @@ import binascii from hashlib import sha256 from string import hexdigits -from torba.client.baseaccount import BaseAccount +from torba.client.baseaccount import BaseAccount, HierarchicalDeterministic from torba.client.basetransaction import TXORef @@ -167,10 +167,11 @@ class Account(BaseAccount): )) async def save_max_gap(self): - gap = await self.get_max_gap() - self.receiving.gap = max(20, gap['max_receiving_gap'] + 1) - self.change.gap = max(6, gap['max_change_gap'] + 1) - self.wallet.save() + if issubclass(self.address_generator, HierarchicalDeterministic): + gap = await self.get_max_gap() + self.receiving.gap = max(20, gap['max_receiving_gap'] + 1) + self.change.gap = max(6, gap['max_change_gap'] + 1) + self.wallet.save() def get_balance(self, confirmations=0, include_claims=False, **constraints): if not include_claims: diff --git a/tests/unit/wallet/test_account.py b/tests/unit/wallet/test_account.py index 1fdbd4f2e..70dd98f03 100644 --- a/tests/unit/wallet/test_account.py +++ b/tests/unit/wallet/test_account.py @@ -95,3 +95,20 @@ class TestAccount(AsyncioTestCase): account = Account.from_dict(self.ledger, Wallet(), account_data) account_data['ledger'] = 'lbc_mainnet' self.assertDictEqual(account_data, account.to_dict()) + + async def test_save_max_gap(self): + account = Account.generate( + self.ledger, Wallet(), 'lbryum', { + 'name': 'deterministic-chain', + 'receiving': {'gap': 3, 'maximum_uses_per_address': 2}, + 'change': {'gap': 4, 'maximum_uses_per_address': 2} + } + ) + self.assertEqual(account.receiving.gap, 3) + self.assertEqual(account.change.gap, 4) + await account.save_max_gap() + self.assertEqual(account.receiving.gap, 20) + self.assertEqual(account.change.gap, 6) + # doesn't fail for single-address account + account2 = Account.generate(self.ledger, Wallet(), 'lbryum', {'name': 'single-address'}) + await account2.save_max_gap()