electrum

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

commit 1a080639288de6a4237a47e2f97b8b608f695aea
parent d1026b5afeae5873022427e3f344d000df5a1c4d
Author: SomberNight <somber.night@protonmail.com>
Date:   Tue, 10 Sep 2019 17:10:52 +0200

config: remove 'open_last_wallet' side-effecting

related: #5629

Diffstat:
Melectrum/daemon.py | 3+--
Melectrum/gui/kivy/__init__.py | 9+++++++--
Melectrum/gui/kivy/main_window.py | 14++++++++++----
Melectrum/gui/qt/__init__.py | 3+--
Melectrum/gui/qt/main_window.py | 2+-
Melectrum/simple_config.py | 16+++++-----------
6 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/electrum/daemon.py b/electrum/daemon.py @@ -366,8 +366,7 @@ class Daemon(Logger): config = SimpleConfig(config_options) if self.gui_object: if hasattr(self.gui_object, 'new_window'): - config.open_last_wallet() - path = config.get_wallet_path() + path = config.get_wallet_path(use_gui_last_wallet=True) self.gui_object.new_window(path, config.get('url')) response = "ok" else: diff --git a/electrum/gui/kivy/__init__.py b/electrum/gui/kivy/__init__.py @@ -27,6 +27,7 @@ import sys import os +from typing import TYPE_CHECKING try: sys.argv = [''] @@ -40,12 +41,17 @@ except ImportError: kivy.require('1.8.0') from kivy.logger import Logger +if TYPE_CHECKING: + from electrum.simple_config import SimpleConfig + from electrum.daemon import Daemon + from electrum.plugin import Plugins + class ElectrumGui: - def __init__(self, config, daemon, plugins): + def __init__(self, config: 'SimpleConfig', daemon: 'Daemon', plugins: 'Plugins'): Logger.debug('ElectrumGUI: initialising') self.daemon = daemon self.network = daemon.network @@ -54,7 +60,6 @@ class ElectrumGui: def main(self): from .main_window import ElectrumWindow - self.config.open_last_wallet() w = ElectrumWindow(config=self.config, network=self.network, plugins = self.plugins, diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py @@ -7,6 +7,7 @@ import traceback from decimal import Decimal import threading import asyncio +from typing import TYPE_CHECKING from electrum.bitcoin import TYPE_ADDRESS from electrum.storage import WalletStorage @@ -77,6 +78,10 @@ from electrum.util import (base_units, NoDynamicFeeEstimates, decimal_point_to_b from .uix.dialogs.lightning_open_channel import LightningOpenChannelDialog from .uix.dialogs.lightning_channels import LightningChannelsDialog +if TYPE_CHECKING: + from electrum.simple_config import SimpleConfig + + class ElectrumWindow(App): electrum_config = ObjectProperty(None) @@ -311,7 +316,7 @@ class ElectrumWindow(App): App.__init__(self)#, **kwargs) title = _('Electrum App') - self.electrum_config = config = kwargs.get('config', None) + self.electrum_config = config = kwargs.get('config', None) # type: SimpleConfig self.language = config.get('language', 'en') self.network = network = kwargs.get('network', None) # type: Network if self.network: @@ -543,7 +548,7 @@ class ElectrumWindow(App): self.network.register_callback(self.on_channel, ['channel']) self.network.register_callback(self.on_payment_status, ['payment_status']) # load wallet - self.load_wallet_by_name(self.electrum_config.get_wallet_path()) + self.load_wallet_by_name(self.electrum_config.get_wallet_path(use_gui_last_wallet=True)) # URI passed in config uri = self.electrum_config.get('url') if uri: @@ -565,7 +570,8 @@ class ElectrumWindow(App): elif not self.wallet: # wizard did not return a wallet; and there is no wallet open atm # try to open last saved wallet (potentially start wizard again) - self.load_wallet_by_name(self.electrum_config.get_wallet_path(), ask_if_wizard=True) + self.load_wallet_by_name(self.electrum_config.get_wallet_path(use_gui_last_wallet=True), + ask_if_wizard=True) def load_wallet_by_name(self, path, ask_if_wizard=False): if not path: @@ -1077,7 +1083,7 @@ class ElectrumWindow(App): self.stop_wallet() os.unlink(wallet_path) self.show_error(_("Wallet removed: {}").format(basename)) - new_path = self.electrum_config.get_wallet_path() + new_path = self.electrum_config.get_wallet_path(use_gui_last_wallet=True) self.load_wallet_by_name(new_path) def show_seed(self, label): diff --git a/electrum/gui/qt/__init__.py b/electrum/gui/qt/__init__.py @@ -343,8 +343,7 @@ class ElectrumGui(Logger): return self.timer.start() - self.config.open_last_wallet() - path = self.config.get_wallet_path() + path = self.config.get_wallet_path(use_gui_last_wallet=True) if not self.start_new_window(path, self.config.get('url'), app_is_starting=True): return signal.signal(signal.SIGINT, lambda *args: self.app.quit()) diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py @@ -556,7 +556,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): self.recently_visited_menu.setEnabled(len(recent)) def get_wallet_folder(self): - return os.path.dirname(os.path.abspath(self.config.get_wallet_path())) + return os.path.dirname(os.path.abspath(self.wallet.storage.path)) def new_wallet(self): try: diff --git a/electrum/simple_config.py b/electrum/simple_config.py @@ -265,17 +265,17 @@ class SimpleConfig(Logger): if os.path.exists(self.path): # or maybe not? raise - def get_wallet_path(self): + def get_wallet_path(self, *, use_gui_last_wallet=False): """Set the path of the wallet.""" # command line -w option if self.get('wallet_path'): return os.path.join(self.get('cwd', ''), self.get('wallet_path')) - # path in config file - path = self.get('default_wallet_path') - if path and os.path.exists(path): - return path + if use_gui_last_wallet: + path = self.get('gui_last_wallet') + if path and os.path.exists(path): + return path # default path util.assert_datadir_available(self.path) @@ -304,12 +304,6 @@ class SimpleConfig(Logger): def get_session_timeout(self): return self.get('session_timeout', 300) - def open_last_wallet(self): - if self.get('wallet_path') is None: - last_wallet = self.get('gui_last_wallet') - if last_wallet is not None and os.path.exists(last_wallet): - self.cmdline_options['default_wallet_path'] = last_wallet - def save_last_wallet(self, wallet): if self.get('wallet_path') is None: path = wallet.storage.path