electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 632905dfbeb93a59976d8248c935583eb434dfb2
parent 0219687d4168b80fa85b9dace7c17553a3a92af4
Author: ThomasV <thomasv@electrum.org>
Date:   Wed, 13 Jan 2016 11:27:17 +0100

instantiate wizard only if needed

Diffstat:
Mgui/qt/__init__.py | 6++++--
Mlib/daemon.py | 57++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mlib/wizard.py | 45---------------------------------------------
3 files changed, 58 insertions(+), 50 deletions(-)

diff --git a/gui/qt/__init__.py b/gui/qt/__init__.py @@ -143,6 +143,9 @@ class ElectrumGui: run_hook('on_new_window', w) return w + def get_wizard(self): + return InstallWizard(self.config, self.app, self.plugins) + def start_new_window(self, path, uri): '''Raises the window for the wallet if it is open. Otherwise opens the wallet and creates a new window for it.''' @@ -151,8 +154,7 @@ class ElectrumGui: w.bring_to_top() break else: - wizard = InstallWizard(self.config, self.app, self.plugins) - wallet = self.daemon.load_wallet(path, wizard) + wallet = self.daemon.load_wallet(path, self.get_wizard) if not wallet: return w = self.create_window_for_wallet(wallet) diff --git a/lib/daemon.py b/lib/daemon.py @@ -120,12 +120,12 @@ class Daemon(DaemonThread): response = "Error: Electrum is running in daemon mode. Please stop the daemon first." return response - def load_wallet(self, path, wizard=None): + def load_wallet(self, path, get_wizard): if path in self.wallets: wallet = self.wallets[path] else: - if wizard: - wallet = wizard.open_wallet(self.network, path) + if get_wizard: + wallet = self.open_wallet_with_wizard(self.network, path, get_wizard) else: storage = WalletStorage(path) wallet = Wallet(storage) @@ -134,6 +134,57 @@ class Daemon(DaemonThread): self.wallets[path] = wallet return wallet + def open_wallet_with_wizard(self, network, filename, get_wizard): + '''Instantiate wizard only if needed''' + storage = WalletStorage(filename) + need_sync = False + is_restore = False + self.wizard = None + + def wizard(): + if self.wizard is None: + self.wizard = get_wizard() + return self.wizard + + if storage.file_exists: + wallet = Wallet(storage) + #self.update_wallet_format(wallet) + else: + cr, wallet = wizard().create_or_restore(storage) + if not wallet: + return + need_sync = True + is_restore = (cr == 'restore') + + while True: + action = wallet.get_action() + if not action: + break + need_sync = True + wizard().run_wallet_action(wallet, action) + # Save the wallet after each action + wallet.storage.write() + + if network: + # Show network dialog if config does not exist + if self.config.get('server') is None: + wizard().choose_server(network) + else: + wizard().show_warning(_('You are offline')) + + if need_sync: + wizard().create_addresses(wallet) + + # start wallet threads + if network: + wallet.start_threads(network) + + if is_restore: + wizard().show_restore(wallet, network) + + return wallet + + def run_cmdline(self, config_options): config = SimpleConfig(config_options) cmdname = config.get('cmd') diff --git a/lib/wizard.py b/lib/wizard.py @@ -119,51 +119,6 @@ class WizardBase(PrintError): """Show restore result""" pass - def open_wallet(self, network, filename): - '''The main entry point of the wizard. Open a wallet from the given - filename. If the file doesn't exist launch the GUI-specific - install wizard proper.''' - storage = WalletStorage(filename) - need_sync = False - is_restore = False - - if storage.file_exists: - wallet = Wallet(storage) - self.update_wallet_format(wallet) - else: - cr, wallet = self.create_or_restore(storage) - if not wallet: - return - need_sync = True - is_restore = (cr == 'restore') - - while True: - action = wallet.get_action() - if not action: - break - need_sync = True - self.run_wallet_action(wallet, action) - # Save the wallet after each action - wallet.storage.write() - - if network: - # Show network dialog if config does not exist - if self.config.get('server') is None: - self.choose_server(network) - else: - self.show_warning(_('You are offline')) - - if need_sync: - self.create_addresses(wallet) - - # start wallet threads - if network: - wallet.start_threads(network) - - if is_restore: - self.show_restore(wallet, network) - - return wallet def run_wallet_action(self, wallet, action):