electrum

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

commit 363dd12a2a6d52addf4bb099c2ef20fd36abb6ed
parent dd848304e6772a7736614c62579a14a1aa791d82
Author: SomberNight <somber.night@protonmail.com>
Date:   Tue, 11 Dec 2018 21:29:23 +0100

qt: try even harder not to crash whole app on first start

Diffstat:
Melectrum/gui/qt/__init__.py | 6+++++-
Melectrum/gui/qt/main_window.py | 11+++--------
Melectrum/util.py | 11+++++++++++
3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/electrum/gui/qt/__init__.py b/electrum/gui/qt/__init__.py @@ -44,7 +44,7 @@ from electrum.plugin import run_hook from electrum.storage import WalletStorage from electrum.base_wizard import GoBack from electrum.util import (UserCancelled, PrintError, profiler, - WalletFileException, BitcoinException) + WalletFileException, BitcoinException, get_new_wallet_name) from .installwizard import InstallWizard @@ -263,6 +263,10 @@ class ElectrumGui(PrintError): d = QMessageBox(QMessageBox.Warning, _('Error'), _('Cannot create window for wallet') + ':\n' + str(e)) d.exec_() + if app_is_starting: + wallet_dir = os.path.dirname(path) + path = os.path.join(wallet_dir, get_new_wallet_name(wallet_dir)) + self.start_new_window(path, uri) return if uri: w.pay_to_URI(uri) diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py @@ -55,7 +55,8 @@ from electrum.util import (format_time, format_satoshis, format_fee_satoshis, export_meta, import_meta, bh2u, bfh, InvalidPassword, base_units, base_units_list, base_unit_name_to_decimal_point, decimal_point_to_base_unit_name, quantize_feerate, - UnknownBaseUnit, DECIMAL_POINT_DEFAULT, UserFacingException) + UnknownBaseUnit, DECIMAL_POINT_DEFAULT, UserFacingException, + get_new_wallet_name) from electrum.transaction import Transaction, TxOutput from electrum.address_synchronizer import AddTransactionException from electrum.wallet import (Multisig_Wallet, CannotBumpFee, Abstract_Wallet, @@ -487,13 +488,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): except FileNotFoundError as e: self.show_error(str(e)) return - i = 1 - while True: - filename = "wallet_%d" % i - if filename in os.listdir(wallet_folder): - i += 1 - else: - break + filename = get_new_wallet_name(wallet_folder) full_path = os.path.join(wallet_folder, filename) self.gui_object.start_new_window(full_path, None) diff --git a/electrum/util.py b/electrum/util.py @@ -413,6 +413,17 @@ def assert_file_in_datadir_available(path, config_path): 'Should be at {}'.format(path)) +def get_new_wallet_name(wallet_folder: str) -> str: + i = 1 + while True: + filename = "wallet_%d" % i + if filename in os.listdir(wallet_folder): + i += 1 + else: + break + return filename + + def assert_bytes(*args): """ porting helper, assert args type