Browse Source

Fix "same wallet can be opened multiple times via InstallWizard" (#4076)

* Fix #4073

* Account for if the wallet is already in the daemon

* Only start a new thread if it doesn't exist

* Modify run_and_get_wallet to not return duplicate wallets

* Inform user if encrypted wallet is already open in memory
master
Jason Bruderer 8 years ago committed by ghost43
parent
commit
9837a02c95
  1. 66
      gui/qt/__init__.py
  2. 21
      gui/qt/installwizard.py

66
gui/qt/__init__.py

@ -185,42 +185,44 @@ class ElectrumGui:
def start_new_window(self, path, uri): def start_new_window(self, path, uri):
'''Raises the window for the wallet if it is open. Otherwise '''Raises the window for the wallet if it is open. Otherwise
opens the wallet and creates a new window for it.''' opens the wallet and creates a new window for it'''
for w in self.windows: try:
if w.wallet.storage.path == path: wallet = self.daemon.load_wallet(path, None)
w.bring_to_top() except BaseException as e:
break traceback.print_exc(file=sys.stdout)
else: d = QMessageBox(QMessageBox.Warning, _('Error'),
_('Cannot load wallet:') + '\n' + str(e))
d.exec_()
return
if not wallet:
storage = WalletStorage(path, manual_upgrades=True)
wizard = InstallWizard(self.config, self.app, self.plugins, storage)
try: try:
wallet = self.daemon.load_wallet(path, None) wallet = wizard.run_and_get_wallet(self.daemon.get_wallet)
except BaseException as e: except UserCancelled:
traceback.print_exc(file=sys.stdout) pass
d = QMessageBox(QMessageBox.Warning, _('Error'), except GoBack as e:
_('Cannot load wallet:') + '\n' + str(e)) print_error('[start_new_window] Exception caught (GoBack)', e)
d.exec_() wizard.terminate()
return
if not wallet: if not wallet:
storage = WalletStorage(path, manual_upgrades=True) return
wizard = InstallWizard(self.config, self.app, self.plugins, storage)
try: if not self.daemon.get_wallet(wallet.storage.path):
wallet = wizard.run_and_get_wallet() # wallet was not in memory
except UserCancelled:
pass
except GoBack as e:
print_error('[start_new_window] Exception caught (GoBack)', e)
wizard.terminate()
if not wallet:
return
wallet.start_threads(self.daemon.network) wallet.start_threads(self.daemon.network)
self.daemon.add_wallet(wallet) self.daemon.add_wallet(wallet)
try: try:
w = self.create_window_for_wallet(wallet) for w in self.windows:
except BaseException as e: if w.wallet.storage.path == wallet.storage.path:
traceback.print_exc(file=sys.stdout) w.bring_to_top()
d = QMessageBox(QMessageBox.Warning, _('Error'), return
_('Cannot create window for wallet:') + '\n' + str(e)) w = self.create_window_for_wallet(wallet)
d.exec_() except BaseException as e:
return traceback.print_exc(file=sys.stdout)
d = QMessageBox(QMessageBox.Warning, _('Error'),
_('Cannot create window for wallet:') + '\n' + str(e))
d.exec_()
return
if uri: if uri:
w.pay_to_URI(uri) w.pay_to_URI(uri)
w.bring_to_top() w.bring_to_top()

21
gui/qt/installwizard.py

@ -148,7 +148,7 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
self.raise_() self.raise_()
self.refresh_gui() # Need for QT on MacOSX. Lame. self.refresh_gui() # Need for QT on MacOSX. Lame.
def run_and_get_wallet(self): def run_and_get_wallet(self, get_wallet_from_daemon):
vbox = QVBoxLayout() vbox = QVBoxLayout()
hbox = QHBoxLayout() hbox = QHBoxLayout()
@ -181,8 +181,12 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
def on_filename(filename): def on_filename(filename):
path = os.path.join(wallet_folder, filename) path = os.path.join(wallet_folder, filename)
wallet_from_memory = get_wallet_from_daemon(path)
try: try:
self.storage = WalletStorage(path, manual_upgrades=True) if wallet_from_memory:
self.storage = wallet_from_memory.storage
else:
self.storage = WalletStorage(path, manual_upgrades=True)
self.next_button.setEnabled(True) self.next_button.setEnabled(True)
except BaseException: except BaseException:
traceback.print_exc(file=sys.stderr) traceback.print_exc(file=sys.stderr)
@ -193,7 +197,7 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
msg =_("This file does not exist.") + '\n' \ msg =_("This file does not exist.") + '\n' \
+ _("Press 'Next' to create this wallet, or choose another file.") + _("Press 'Next' to create this wallet, or choose another file.")
pw = False pw = False
else: elif not wallet_from_memory:
if self.storage.is_encrypted_with_user_pw(): if self.storage.is_encrypted_with_user_pw():
msg = _("This file is encrypted with a password.") + '\n' \ msg = _("This file is encrypted with a password.") + '\n' \
+ _('Enter your password or choose another file.') + _('Enter your password or choose another file.')
@ -205,6 +209,10 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
else: else:
msg = _("Press 'Next' to open this wallet.") msg = _("Press 'Next' to open this wallet.")
pw = False pw = False
else:
msg = _("This file is already open in memory.") + "\n" \
+ _("Press 'Next' to create/focus window.")
pw = False
else: else:
msg = _('Cannot read file') msg = _('Cannot read file')
pw = False pw = False
@ -229,6 +237,9 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
return return
if not self.storage.file_exists(): if not self.storage.file_exists():
break break
wallet_from_memory = get_wallet_from_daemon(self.storage.path)
if wallet_from_memory:
return wallet_from_memory
if self.storage.file_exists() and self.storage.is_encrypted(): if self.storage.file_exists() and self.storage.is_encrypted():
if self.storage.is_encrypted_with_user_pw(): if self.storage.is_encrypted_with_user_pw():
password = self.pw_e.text() password = self.pw_e.text()
@ -251,7 +262,7 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
_('Failed to decrypt using this hardware device.') + '\n' + _('Failed to decrypt using this hardware device.') + '\n' +
_('If you use a passphrase, make sure it is correct.')) _('If you use a passphrase, make sure it is correct.'))
self.stack = [] self.stack = []
return self.run_and_get_wallet() return self.run_and_get_wallet(get_wallet_from_daemon)
except BaseException as e: except BaseException as e:
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)
QMessageBox.information(None, _('Error'), str(e)) QMessageBox.information(None, _('Error'), str(e))
@ -301,8 +312,6 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
self.wallet = Wallet(self.storage) self.wallet = Wallet(self.storage)
return self.wallet return self.wallet
def finished(self): def finished(self):
"""Called in hardware client wrapper, in order to close popups.""" """Called in hardware client wrapper, in order to close popups."""
return return

Loading…
Cancel
Save