Register loaded wallets in daemon, to prevent a wallet from being opened twice.
Simplify the wizard logic.
This commit is contained in:
parent
3d9f321cae
commit
62868ab29a
9
electrum
9
electrum
|
@ -98,12 +98,12 @@ def prompt_password(prompt, confirm=True):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def init_gui(config, network, plugins):
|
def init_gui(config, network, daemon, plugins):
|
||||||
gui_name = config.get('gui', 'qt')
|
gui_name = config.get('gui', 'qt')
|
||||||
if gui_name in ['lite', 'classic']:
|
if gui_name in ['lite', 'classic']:
|
||||||
gui_name = 'qt'
|
gui_name = 'qt'
|
||||||
gui = __import__('electrum_gui.' + gui_name, fromlist=['electrum_gui'])
|
gui = __import__('electrum_gui.' + gui_name, fromlist=['electrum_gui'])
|
||||||
gui = gui.ElectrumGui(config, network, plugins)
|
gui = gui.ElectrumGui(config, network, daemon, plugins)
|
||||||
return gui
|
return gui
|
||||||
|
|
||||||
|
|
||||||
|
@ -343,9 +343,10 @@ if __name__ == '__main__':
|
||||||
plugins.start()
|
plugins.start()
|
||||||
else:
|
else:
|
||||||
network = None
|
network = None
|
||||||
gui = init_gui(config, network, plugins)
|
daemon = Daemon(config, network)
|
||||||
daemon = Daemon(config, network, gui)
|
|
||||||
daemon.start()
|
daemon.start()
|
||||||
|
gui = init_gui(config, network, daemon, plugins)
|
||||||
|
daemon.gui = gui
|
||||||
gui.main()
|
gui.main()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
|
@ -904,7 +904,7 @@ config = None
|
||||||
|
|
||||||
class ElectrumGui:
|
class ElectrumGui:
|
||||||
|
|
||||||
def __init__(self, _config, _network, plugins):
|
def __init__(self, _config, _network, daemon, plugins):
|
||||||
global wallet, network, contacts, config
|
global wallet, network, contacts, config
|
||||||
network = _network
|
network = _network
|
||||||
config = _config
|
config = _config
|
||||||
|
|
|
@ -1189,7 +1189,7 @@ class ElectrumWindow:
|
||||||
tooltip = tx_hash + "\n%d confirmations"%conf if tx_hash else ''
|
tooltip = tx_hash + "\n%d confirmations"%conf if tx_hash else ''
|
||||||
details = self.get_tx_details(tx_hash)
|
details = self.get_tx_details(tx_hash)
|
||||||
|
|
||||||
self.history_list.prepend( [tx_hash, conf_icon, time_str, label, is_default_label,
|
self.history_list.prepend( [tx_hash, conf_icon, time_str, label, False,
|
||||||
format_satoshis(value,True,self.num_zeros, whitespaces=True),
|
format_satoshis(value,True,self.num_zeros, whitespaces=True),
|
||||||
format_satoshis(balance,False,self.num_zeros, whitespaces=True), tooltip, details] )
|
format_satoshis(balance,False,self.num_zeros, whitespaces=True), tooltip, details] )
|
||||||
if cursor: self.history_treeview.set_cursor( cursor )
|
if cursor: self.history_treeview.set_cursor( cursor )
|
||||||
|
@ -1284,7 +1284,7 @@ class ElectrumWindow:
|
||||||
|
|
||||||
class ElectrumGui():
|
class ElectrumGui():
|
||||||
|
|
||||||
def __init__(self, config, network, plugins):
|
def __init__(self, config, network, daemon, plugins):
|
||||||
self.network = network
|
self.network = network
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ from main_window import ElectrumWindow
|
||||||
|
|
||||||
class ElectrumGui:
|
class ElectrumGui:
|
||||||
|
|
||||||
def __init__(self, config, network, plugins, app=None):
|
def __init__(self, config, network, daemon, plugins):
|
||||||
Logger.debug('ElectrumGUI: initialising')
|
Logger.debug('ElectrumGUI: initialising')
|
||||||
self.network = network
|
self.network = network
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
|
@ -66,7 +66,7 @@ class OpenFileEventFilter(QObject):
|
||||||
|
|
||||||
class ElectrumGui(MessageBoxMixin):
|
class ElectrumGui(MessageBoxMixin):
|
||||||
|
|
||||||
def __init__(self, config, network, plugins):
|
def __init__(self, config, network, daemon, plugins):
|
||||||
set_language(config.get('language'))
|
set_language(config.get('language'))
|
||||||
# Uncomment this call to verify objects are being properly
|
# Uncomment this call to verify objects are being properly
|
||||||
# GC-ed when windows are closed
|
# GC-ed when windows are closed
|
||||||
|
@ -74,6 +74,7 @@ class ElectrumGui(MessageBoxMixin):
|
||||||
# ElectrumWindow], interval=5)])
|
# ElectrumWindow], interval=5)])
|
||||||
self.network = network
|
self.network = network
|
||||||
self.config = config
|
self.config = config
|
||||||
|
self.daemon = daemon
|
||||||
self.plugins = plugins
|
self.plugins = plugins
|
||||||
self.windows = []
|
self.windows = []
|
||||||
self.efilter = OpenFileEventFilter(self.windows)
|
self.efilter = OpenFileEventFilter(self.windows)
|
||||||
|
@ -134,12 +135,10 @@ class ElectrumGui(MessageBoxMixin):
|
||||||
# Use a signal as can be called from daemon thread
|
# Use a signal as can be called from daemon thread
|
||||||
self.app.emit(SIGNAL('new_window'), path, uri)
|
self.app.emit(SIGNAL('new_window'), path, uri)
|
||||||
|
|
||||||
def create_window_for_wallet(self, wallet, task):
|
def create_window_for_wallet(self, wallet):
|
||||||
w = ElectrumWindow(self, wallet)
|
w = ElectrumWindow(self, wallet)
|
||||||
self.windows.append(w)
|
self.windows.append(w)
|
||||||
self.build_tray_menu()
|
self.build_tray_menu()
|
||||||
if task:
|
|
||||||
WaitingDialog(w, task[0], task[1])
|
|
||||||
# FIXME: Remove in favour of the load_wallet hook
|
# FIXME: Remove in favour of the load_wallet hook
|
||||||
run_hook('on_new_window', w)
|
run_hook('on_new_window', w)
|
||||||
return w
|
return w
|
||||||
|
@ -153,10 +152,10 @@ class ElectrumGui(MessageBoxMixin):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
wizard = InstallWizard(self.config, self.app, self.plugins)
|
wizard = InstallWizard(self.config, self.app, self.plugins)
|
||||||
result = wizard.open_wallet(self.network, path)
|
wallet = self.daemon.load_wallet(path, wizard)
|
||||||
if not result:
|
if not wallet:
|
||||||
return
|
return
|
||||||
w = self.create_window_for_wallet(*result)
|
w = self.create_window_for_wallet(wallet)
|
||||||
|
|
||||||
if uri:
|
if uri:
|
||||||
w.pay_to_URI(uri)
|
w.pay_to_URI(uri)
|
||||||
|
|
|
@ -17,7 +17,8 @@ from electrum.mnemonic import prepare_seed
|
||||||
from electrum.wizard import (WizardBase, UserCancelled,
|
from electrum.wizard import (WizardBase, UserCancelled,
|
||||||
MSG_ENTER_PASSWORD, MSG_RESTORE_PASSPHRASE,
|
MSG_ENTER_PASSWORD, MSG_RESTORE_PASSPHRASE,
|
||||||
MSG_COSIGNER, MSG_ENTER_SEED_OR_MPK,
|
MSG_COSIGNER, MSG_ENTER_SEED_OR_MPK,
|
||||||
MSG_SHOW_MPK, MSG_VERIFY_SEED)
|
MSG_SHOW_MPK, MSG_VERIFY_SEED,
|
||||||
|
MSG_GENERATING_WAIT)
|
||||||
|
|
||||||
class CosignWidget(QWidget):
|
class CosignWidget(QWidget):
|
||||||
size = 120
|
size = 120
|
||||||
|
@ -134,6 +135,20 @@ class InstallWizard(WindowModalDialog, WizardBase):
|
||||||
if self.config.get('server') is None:
|
if self.config.get('server') is None:
|
||||||
self.network_dialog(network)
|
self.network_dialog(network)
|
||||||
|
|
||||||
|
def show_restore(self, wallet, network, action):
|
||||||
|
def on_finished(b):
|
||||||
|
if action == 'restore':
|
||||||
|
if network:
|
||||||
|
if wallet.is_found():
|
||||||
|
msg = _("Recovery successful")
|
||||||
|
else:
|
||||||
|
msg = _("No transactions found for this seed")
|
||||||
|
else:
|
||||||
|
msg = _("This wallet was restored offline. It may "
|
||||||
|
"contain more addresses than displayed.")
|
||||||
|
self.show_message(msg)
|
||||||
|
WaitingDialog(self, MSG_GENERATING_WAIT, wallet.wait_until_synchronized, on_finished)
|
||||||
|
|
||||||
def set_layout(self, layout):
|
def set_layout(self, layout):
|
||||||
w = QWidget()
|
w = QWidget()
|
||||||
w.setLayout(layout)
|
w.setLayout(layout)
|
||||||
|
|
|
@ -12,7 +12,7 @@ import sys, getpass, datetime
|
||||||
|
|
||||||
class ElectrumGui:
|
class ElectrumGui:
|
||||||
|
|
||||||
def __init__(self, config, network, plugins):
|
def __init__(self, config, network, daemon, plugins):
|
||||||
self.network = network
|
self.network = network
|
||||||
self.config = config
|
self.config = config
|
||||||
storage = WalletStorage(config.get_wallet_path())
|
storage = WalletStorage(config.get_wallet_path())
|
||||||
|
|
|
@ -12,7 +12,7 @@ import tty, sys
|
||||||
|
|
||||||
class ElectrumGui:
|
class ElectrumGui:
|
||||||
|
|
||||||
def __init__(self, config, network, plugins):
|
def __init__(self, config, network, daemon, plugins):
|
||||||
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.network = network
|
self.network = network
|
||||||
|
|
|
@ -61,16 +61,13 @@ class RequestHandler(SimpleJSONRPCRequestHandler):
|
||||||
|
|
||||||
class Daemon(DaemonThread):
|
class Daemon(DaemonThread):
|
||||||
|
|
||||||
def __init__(self, config, network, gui=None):
|
def __init__(self, config, network):
|
||||||
DaemonThread.__init__(self)
|
DaemonThread.__init__(self)
|
||||||
self.config = config
|
self.config = config
|
||||||
self.network = network
|
self.network = network
|
||||||
self.gui = gui
|
self.gui = None
|
||||||
self.wallets = {}
|
self.wallets = {}
|
||||||
if gui is None:
|
self.wallet = None
|
||||||
self.wallet = self.load_wallet(config)
|
|
||||||
else:
|
|
||||||
self.wallet = None
|
|
||||||
self.cmd_runner = Commands(self.config, self.wallet, self.network)
|
self.cmd_runner = Commands(self.config, self.wallet, self.network)
|
||||||
host = config.get('rpchost', 'localhost')
|
host = config.get('rpchost', 'localhost')
|
||||||
port = config.get('rpcport', 0)
|
port = config.get('rpcport', 0)
|
||||||
|
@ -123,22 +120,26 @@ class Daemon(DaemonThread):
|
||||||
response = "Error: Electrum is running in daemon mode. Please stop the daemon first."
|
response = "Error: Electrum is running in daemon mode. Please stop the daemon first."
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def load_wallet(self, config):
|
def load_wallet(self, path, wizard=None):
|
||||||
path = config.get_wallet_path()
|
|
||||||
if path in self.wallets:
|
if path in self.wallets:
|
||||||
wallet = self.wallets[path]
|
wallet = self.wallets[path]
|
||||||
else:
|
else:
|
||||||
storage = WalletStorage(path)
|
if wizard:
|
||||||
wallet = Wallet(storage)
|
wallet = wizard.open_wallet(self.network, path)
|
||||||
wallet.start_threads(self.network)
|
else:
|
||||||
self.wallets[path] = wallet
|
storage = WalletStorage(path)
|
||||||
|
wallet = Wallet(storage)
|
||||||
|
wallet.start_threads(self.network)
|
||||||
|
if wallet:
|
||||||
|
self.wallets[path] = wallet
|
||||||
return wallet
|
return wallet
|
||||||
|
|
||||||
def run_cmdline(self, config_options):
|
def run_cmdline(self, config_options):
|
||||||
config = SimpleConfig(config_options)
|
config = SimpleConfig(config_options)
|
||||||
cmdname = config.get('cmd')
|
cmdname = config.get('cmd')
|
||||||
cmd = known_commands[cmdname]
|
cmd = known_commands[cmdname]
|
||||||
wallet = self.load_wallet(config) if cmd.requires_wallet else None
|
path = config.get_wallet_path()
|
||||||
|
wallet = self.load_wallet(path) if cmd.requires_wallet else None
|
||||||
# arguments passed to function
|
# arguments passed to function
|
||||||
args = map(lambda x: config.get(x), cmd.params)
|
args = map(lambda x: config.get(x), cmd.params)
|
||||||
# decode json arguments
|
# decode json arguments
|
||||||
|
|
|
@ -126,43 +126,9 @@ class WizardBase(PrintError):
|
||||||
"""Choose a server if one is not set in the config anyway."""
|
"""Choose a server if one is not set in the config anyway."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def open_existing_wallet(self, storage, network):
|
def show_restore(self, wallet, network, action):
|
||||||
wallet = Wallet(storage)
|
"""Show restore result"""
|
||||||
self.update_wallet_format(wallet)
|
pass
|
||||||
self.run_wallet_actions(wallet)
|
|
||||||
wallet.start_threads(network)
|
|
||||||
return wallet, None
|
|
||||||
|
|
||||||
def create_new_wallet(self, storage, network):
|
|
||||||
action, wallet = self.create_or_restore(storage)
|
|
||||||
self.run_wallet_actions(wallet)
|
|
||||||
|
|
||||||
if network:
|
|
||||||
self.choose_server(network)
|
|
||||||
else:
|
|
||||||
self.show_warning(_('You are offline'))
|
|
||||||
|
|
||||||
def task():
|
|
||||||
# Synchronize before starting the threads
|
|
||||||
wallet.synchronize()
|
|
||||||
wallet.start_threads(network)
|
|
||||||
# FIXME
|
|
||||||
# if action == 'create':
|
|
||||||
# msg = _('Wallet addresses generated.')
|
|
||||||
# else:
|
|
||||||
# wallet.wait_until_synchronized()
|
|
||||||
# if network:
|
|
||||||
# if wallet.is_found():
|
|
||||||
# msg = _("Recovery successful")
|
|
||||||
# else:
|
|
||||||
# msg = _("No transactions found for this seed")
|
|
||||||
# else:
|
|
||||||
# msg = _("This wallet was restored offline. It may "
|
|
||||||
# "contain more addresses than displayed.")
|
|
||||||
# self.show_message(msg)
|
|
||||||
|
|
||||||
return wallet, (MSG_GENERATING_WAIT, task)
|
|
||||||
|
|
||||||
|
|
||||||
def open_wallet(self, network, filename):
|
def open_wallet(self, network, filename):
|
||||||
'''The main entry point of the wizard. Open a wallet from the given
|
'''The main entry point of the wizard. Open a wallet from the given
|
||||||
|
@ -170,22 +136,43 @@ class WizardBase(PrintError):
|
||||||
install wizard proper.'''
|
install wizard proper.'''
|
||||||
storage = WalletStorage(filename)
|
storage = WalletStorage(filename)
|
||||||
if storage.file_exists:
|
if storage.file_exists:
|
||||||
return self.open_existing_wallet(storage, network)
|
wallet = Wallet(storage)
|
||||||
|
self.update_wallet_format(wallet)
|
||||||
|
task = None
|
||||||
else:
|
else:
|
||||||
return self.create_new_wallet(storage, network)
|
cr, wallet = self.create_or_restore(storage)
|
||||||
|
if not wallet:
|
||||||
|
return
|
||||||
|
task = lambda: self.show_restore(wallet, network, cr)
|
||||||
|
|
||||||
def run_wallet_actions(self, wallet):
|
action = wallet.get_action()
|
||||||
if not wallet:
|
requires_action = action is not None
|
||||||
return
|
|
||||||
action = orig_action = wallet.get_action()
|
|
||||||
while action:
|
while action:
|
||||||
self.run_wallet_action(wallet, action)
|
self.run_wallet_action(wallet, action)
|
||||||
action = wallet.get_action()
|
action = wallet.get_action()
|
||||||
|
|
||||||
# Save the wallet after successful completion of actions.
|
# Save the wallet after successful completion of actions.
|
||||||
# It will be saved again once synchronized.
|
# It will be saved again once synchronized.
|
||||||
if orig_action:
|
if requires_action:
|
||||||
wallet.storage.write()
|
wallet.storage.write()
|
||||||
|
|
||||||
|
if network:
|
||||||
|
self.choose_server(network)
|
||||||
|
else:
|
||||||
|
self.show_warning(_('You are offline'))
|
||||||
|
|
||||||
|
# start wallet threads
|
||||||
|
if network:
|
||||||
|
wallet.start_threads(network)
|
||||||
|
else:
|
||||||
|
wallet.synchronize()
|
||||||
|
|
||||||
|
if task:
|
||||||
|
task()
|
||||||
|
|
||||||
|
return wallet
|
||||||
|
|
||||||
|
|
||||||
def run_wallet_action(self, wallet, action):
|
def run_wallet_action(self, wallet, action):
|
||||||
self.print_error("action %s on %s" % (action, wallet.basename()))
|
self.print_error("action %s on %s" % (action, wallet.basename()))
|
||||||
# Run the action on the wallet plugin, if any, then the
|
# Run the action on the wallet plugin, if any, then the
|
||||||
|
|
Loading…
Reference in New Issue