1
0

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
This commit is contained in:
Jason Bruderer
2018-03-14 23:46:23 -06:00
committed by ghost43
parent 8dd19a5920
commit 9837a02c95
2 changed files with 49 additions and 38 deletions

View File

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