From 374daa25afd06237b07a6b1abed2c8fcc648e22b Mon Sep 17 00:00:00 2001 From: ThomasV Date: Wed, 10 Sep 2014 10:09:13 +0200 Subject: [PATCH] create a PendingAccount if coins have been sent to next_account --- gui/qt/main_window.py | 2 +- lib/wallet.py | 17 +++++++++++++++++ plugins/trezor.py | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index dd0ba754..5686795c 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -2281,7 +2281,7 @@ class ElectrumWindow(QMainWindow): vbox.addLayout(h) private_keys = {} - addresses = self.wallet.addresses(True, False) + addresses = self.wallet.addresses(True) done = False def privkeys_thread(): for addr in addresses: diff --git a/lib/wallet.py b/lib/wallet.py index 797b8e56..bf2ab009 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -1343,6 +1343,13 @@ class BIP32_HD_Wallet(BIP32_Wallet): l.append(next_address) return l + def get_address_index(self, address): + if self.next_account: + next_id, next_xpub, next_address = self.next_account + if address == next_address: + return next_id, (0,0) + return BIP32_Wallet.get_address_index(self, address) + def num_accounts(self): keys = [] for k, v in self.accounts.items(): @@ -1390,6 +1397,9 @@ class BIP32_HD_Wallet(BIP32_Wallet): assert type(self.accounts.get(k)) == PendingAccount self.accounts.pop(k) self.save_accounts() + # prepare the next account + self.next_account = self.get_next_account(password) + self.storage.put('next_account', self.next_account) def create_pending_account(self, name, password): next_id, next_xpub, next_address = self.next_account if self.next_account else self.get_next_account_address(password) @@ -1407,6 +1417,7 @@ class BIP32_HD_Wallet(BIP32_Wallet): if self.next_account is None: try: self.next_account = self.get_next_account(None) + self.storage.put('next_account', self.next_account) except: pass @@ -1418,6 +1429,12 @@ class BIP32_HD_Wallet(BIP32_Wallet): self.add_account(next_id, BIP32_Account({'xpub':next_xpub})) # here the user should get a notification self.next_account = None + self.storage.put('next_account', self.next_account) + elif self.history.get(next_address, []): + if next_id not in self.accounts: + print_error("create pending account", next_id) + self.accounts[next_id] = PendingAccount({'pending':next_address}) + self.save_accounts() diff --git a/plugins/trezor.py b/plugins/trezor.py index 1c49bd11..955c1dbb 100644 --- a/plugins/trezor.py +++ b/plugins/trezor.py @@ -351,7 +351,7 @@ class TrezorWallet(NewWallet): def check_proper_device(self): self.get_client().ping('t') if not self.device_checked: - address = self.addresses(False, False)[0] + address = self.addresses(False)[0] address_id = self.address_id(address) n = self.get_client().expand_path(address_id) device_address = self.get_client().get_address('Bitcoin', n)