Better install wizard
Break out the workflow logic of the install wizard into a base class. This means reimplementing with full support in a new GUI is now easy; you just provide ways to request passwords, show messages etc. The API is fully documented in the base class. There are a couple of minor outstanding issues, including that the old messages shown when recovering a wallet are missing. I will come back to that. Ledger wallet might be broken. Other improvements: The install wizard code is now easy to follow and understand. Hardware wallets can now be restored without any need for their accompanying libraries. Various bits of trustedcoin were broken and have been fixed. Many plugin hooks can be removed. I have only started on this.
This commit is contained in:
@@ -130,70 +130,35 @@ class ElectrumGui(MessageBoxMixin):
|
||||
for window in self.windows:
|
||||
window.close()
|
||||
|
||||
def remove_from_recently_open(self, filename):
|
||||
recent = self.config.get('recently_open', [])
|
||||
if filename in recent:
|
||||
recent.remove(filename)
|
||||
self.config.set_key('recently_open', recent)
|
||||
|
||||
def load_wallet_file(self, filename):
|
||||
try:
|
||||
storage = WalletStorage(filename)
|
||||
except Exception as e:
|
||||
self.show_error(str(e))
|
||||
return
|
||||
if not storage.file_exists:
|
||||
self.remove_from_recently_open(filename)
|
||||
action = 'new'
|
||||
else:
|
||||
try:
|
||||
wallet = Wallet(storage)
|
||||
except BaseException as e:
|
||||
traceback.print_exc(file=sys.stdout)
|
||||
self.show_warning(str(e))
|
||||
return
|
||||
action = wallet.get_action()
|
||||
|
||||
if action is not None:
|
||||
return self.install_wizard(storage, action)
|
||||
|
||||
wallet.start_threads(self.network)
|
||||
return self.create_window_for_wallet(wallet)
|
||||
|
||||
def install_wizard(self, storage, action):
|
||||
wizard = InstallWizard(self, storage)
|
||||
wallet = wizard.run(action)
|
||||
return self.create_window_for_wallet(wallet)
|
||||
|
||||
def new_window(self, path, uri=None):
|
||||
# Use a signal as can be called from daemon thread
|
||||
self.app.emit(SIGNAL('new_window'), path, uri)
|
||||
|
||||
def create_window_for_wallet(self, wallet):
|
||||
if not wallet:
|
||||
return
|
||||
def create_window_for_wallet(self, wallet, task):
|
||||
w = ElectrumWindow(self, wallet)
|
||||
w.connect_slots(self.timer)
|
||||
w.update_recently_visited(wallet.storage.path)
|
||||
# initial configuration
|
||||
if self.config.get('hide_gui') is True and self.tray.isVisible():
|
||||
w.hide()
|
||||
else:
|
||||
w.show()
|
||||
self.windows.append(w)
|
||||
self.build_tray_menu()
|
||||
if task:
|
||||
WaitingDialog(w, task[0], task[1])
|
||||
# FIXME: Remove in favour of the load_wallet hook
|
||||
run_hook('on_new_window', w)
|
||||
return w
|
||||
|
||||
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:
|
||||
w = self.load_wallet_file(path)
|
||||
wizard = InstallWizard(self.config, self.app, self.plugins)
|
||||
result = wizard.open_wallet(self.network, path)
|
||||
if not result:
|
||||
return
|
||||
w = self.create_window_for_wallet(*result)
|
||||
|
||||
if uri and w:
|
||||
if uri:
|
||||
w.pay_to_URI(uri)
|
||||
|
||||
return w
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import re
|
||||
import sys
|
||||
import threading
|
||||
from sys import stdout
|
||||
|
||||
from PyQt4.QtGui import *
|
||||
from PyQt4.QtCore import *
|
||||
@@ -8,23 +6,18 @@ import PyQt4.QtCore as QtCore
|
||||
|
||||
import electrum
|
||||
from electrum.i18n import _
|
||||
from electrum import Wallet
|
||||
from electrum import bitcoin
|
||||
from electrum import util
|
||||
|
||||
import seed_dialog
|
||||
from network_dialog import NetworkDialog
|
||||
from util import *
|
||||
from password_dialog import PasswordDialog
|
||||
|
||||
from electrum.plugins import always_hook, run_hook
|
||||
from electrum.wallet import Wallet
|
||||
from electrum.mnemonic import prepare_seed
|
||||
|
||||
MSG_ENTER_ANYTHING = _("Please enter a seed phrase, a master key, a list of Bitcoin addresses, or a list of private keys")
|
||||
MSG_SHOW_MPK = _("Here is your master public key")
|
||||
MSG_ENTER_MPK = _("Please enter your master public key")
|
||||
MSG_ENTER_SEED_OR_MPK = _("Please enter a seed phrase or a master key (xpub or xprv)")
|
||||
MSG_VERIFY_SEED = _("Your seed is important!") + "\n" + _("To make sure that you have properly saved your seed, please retype it here.")
|
||||
|
||||
from electrum.wizard import (WizardBase, UserCancelled,
|
||||
MSG_ENTER_PASSWORD, MSG_RESTORE_PASSPHRASE,
|
||||
MSG_COSIGNER, MSG_ENTER_SEED_OR_MPK,
|
||||
MSG_SHOW_MPK, MSG_VERIFY_SEED)
|
||||
|
||||
class CosignWidget(QWidget):
|
||||
size = 120
|
||||
@@ -62,22 +55,95 @@ class CosignWidget(QWidget):
|
||||
|
||||
|
||||
|
||||
class InstallWizard(WindowModalDialog, MessageBoxMixin):
|
||||
class InstallWizard(WindowModalDialog, MessageBoxMixin, WizardBase):
|
||||
|
||||
def __init__(self, gui_object, storage):
|
||||
title = 'Electrum' + ' - ' + _('Install Wizard')
|
||||
def __init__(self, config, app, plugins):
|
||||
title = 'Electrum - ' + _('Install Wizard')
|
||||
WindowModalDialog.__init__(self, None, title=title)
|
||||
self.gui_object = gui_object
|
||||
self.app = gui_object.app
|
||||
self.config = gui_object.config
|
||||
self.network = gui_object.network
|
||||
self.storage = storage
|
||||
self.app = app
|
||||
self.config = config
|
||||
# Set for base base class
|
||||
self.plugins = plugins
|
||||
self.language_for_seed = config.get('language')
|
||||
self.setMinimumSize(575, 400)
|
||||
self.setMaximumSize(575, 400)
|
||||
self.connect(self, QtCore.SIGNAL('accept'), self.accept)
|
||||
self.stack = QStackedLayout()
|
||||
self.setLayout(self.stack)
|
||||
|
||||
def open_wallet(self, *args):
|
||||
'''Wrap the base wizard implementation with try/except blocks
|
||||
to give a sensible error message to the user.'''
|
||||
wallet = None
|
||||
try:
|
||||
wallet = super(InstallWizard, self).open_wallet(*args)
|
||||
except UserCancelled:
|
||||
self.print_error("wallet creation cancelled by user")
|
||||
except Exception as e:
|
||||
traceback.print_exc(file=stdout)
|
||||
self.show_error(str(e))
|
||||
return wallet
|
||||
|
||||
def remove_from_recently_open(self, filename):
|
||||
self.config.remove_from_recently_open(filename)
|
||||
|
||||
# Called by plugins
|
||||
def confirm(self, msg, icon=None):
|
||||
'''Returns True or False'''
|
||||
vbox = QVBoxLayout()
|
||||
self.set_layout(vbox)
|
||||
if icon:
|
||||
logo = QLabel()
|
||||
logo.setPixmap(icon)
|
||||
vbox.addWidget(logo)
|
||||
label = QLabel(msg)
|
||||
label.setWordWrap(True)
|
||||
vbox.addWidget(label)
|
||||
vbox.addStretch(1)
|
||||
vbox.addLayout(Buttons(CancelButton(self, _("Cancel")),
|
||||
OkButton(self, _("Next"))))
|
||||
if not self.exec_():
|
||||
raise UserCancelled
|
||||
|
||||
def show_and_verify_seed(self, seed, is_valid=None):
|
||||
"""Show the user their seed. Ask them to re-enter it. Return
|
||||
True on success."""
|
||||
self.show_seed(seed)
|
||||
self.app.clipboard().clear()
|
||||
self.verify_seed(seed, is_valid)
|
||||
|
||||
def pw_dialog(self, msg, kind):
|
||||
dialog = PasswordDialog(self, None, msg, kind)
|
||||
accepted, p, pass_text = dialog.run()
|
||||
if not accepted:
|
||||
raise UserCancelled
|
||||
return pass_text
|
||||
|
||||
def request_passphrase(self, device_text, restore=True):
|
||||
"""Request a passphrase for a wallet from the given device and
|
||||
confirm it. restore is True if restoring a wallet. Should return
|
||||
a unicode string."""
|
||||
if restore:
|
||||
msg = MSG_RESTORE_PASSPHRASE % device_text
|
||||
return unicode(self.pw_dialog(msg, PasswordDialog.PW_PASSPHRASE) or '')
|
||||
|
||||
def request_password(self, msg=None):
|
||||
"""Request the user enter a new password and confirm it. Return
|
||||
the password or None for no password."""
|
||||
return self.pw_dialog(msg or MSG_ENTER_PASSWORD, PasswordDialog.PW_NEW)
|
||||
|
||||
def query_hardware(self, choices, action):
|
||||
if action == 'create':
|
||||
msg = _('Select the hardware wallet to create')
|
||||
else:
|
||||
msg = _('Select the hardware wallet to restore')
|
||||
return self.choice(msg, choices)
|
||||
|
||||
def choose_server(self, network):
|
||||
# Show network dialog if config does not exist
|
||||
if self.config.get('server') is None:
|
||||
self.network_dialog(network)
|
||||
|
||||
def set_layout(self, layout):
|
||||
w = QWidget()
|
||||
w.setLayout(layout)
|
||||
@@ -85,7 +151,9 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin):
|
||||
self.stack.setCurrentWidget(w)
|
||||
self.show()
|
||||
|
||||
def restore_or_create(self):
|
||||
def query_create_or_restore(self):
|
||||
"""Returns a tuple (action, kind). Action is one of user_actions,
|
||||
or None if cancelled. kind is one of wallet_kinds."""
|
||||
vbox = QVBoxLayout()
|
||||
|
||||
main_label = QLabel(_("Electrum could not find an existing wallet."))
|
||||
@@ -120,14 +188,14 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin):
|
||||
|
||||
group2 = QButtonGroup()
|
||||
|
||||
self.wallet_types = [
|
||||
wallet_types = [
|
||||
('standard', _("Standard wallet")),
|
||||
('twofactor', _("Wallet with two-factor authentication")),
|
||||
('multisig', _("Multi-signature wallet")),
|
||||
('hardware', _("Hardware wallet")),
|
||||
]
|
||||
|
||||
for i, (wtype,name) in enumerate(self.wallet_types):
|
||||
for i, (wtype,name) in enumerate(wallet_types):
|
||||
if not filter(lambda x:x[0]==wtype, electrum.wallet.wallet_types):
|
||||
continue
|
||||
button = QRadioButton(gb2)
|
||||
@@ -146,51 +214,40 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin):
|
||||
self.raise_()
|
||||
|
||||
if not self.exec_():
|
||||
return None, None
|
||||
raise UserCancelled
|
||||
|
||||
action = 'create' if b1.isChecked() else 'restore'
|
||||
wallet_type = self.wallet_types[group2.checkedId()][0]
|
||||
wallet_type = wallet_types[group2.checkedId()][0]
|
||||
return action, wallet_type
|
||||
|
||||
|
||||
def verify_seed(self, seed, sid, func=None):
|
||||
r = self.enter_seed_dialog(MSG_VERIFY_SEED, sid, func)
|
||||
if not r:
|
||||
return
|
||||
if prepare_seed(r) != prepare_seed(seed):
|
||||
def verify_seed(self, seed, is_valid=None):
|
||||
while True:
|
||||
r = self.request_seed(MSG_VERIFY_SEED, is_valid)
|
||||
if prepare_seed(r) == prepare_seed(seed):
|
||||
return
|
||||
self.show_error(_('Incorrect seed'))
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def get_seed_text(self, seed_e):
|
||||
text = unicode(seed_e.toPlainText()).strip()
|
||||
text = ' '.join(text.split())
|
||||
return text
|
||||
|
||||
def is_any(self, text):
|
||||
return Wallet.is_seed(text) or Wallet.is_old_mpk(text) or Wallet.is_xpub(text) or Wallet.is_xprv(text) or Wallet.is_address(text) or Wallet.is_private_key(text)
|
||||
|
||||
def is_mpk(self, text):
|
||||
return Wallet.is_xpub(text) or Wallet.is_old_mpk(text)
|
||||
|
||||
def enter_seed_dialog(self, msg, sid, func=None):
|
||||
if func is None:
|
||||
func = self.is_any
|
||||
vbox, seed_e = seed_dialog.enter_seed_box(msg, self, sid)
|
||||
def request_seed(self, msg, is_valid=None):
|
||||
is_valid = is_valid or Wallet.is_any
|
||||
vbox, seed_e = seed_dialog.enter_seed_box(msg, self)
|
||||
vbox.addStretch(1)
|
||||
button = OkButton(self, _('Next'))
|
||||
vbox.addLayout(Buttons(CancelButton(self), button))
|
||||
button.setEnabled(False)
|
||||
seed_e.textChanged.connect(lambda: button.setEnabled(func(self.get_seed_text(seed_e))))
|
||||
def set_enabled():
|
||||
button.setEnabled(is_valid(self.get_seed_text(seed_e)))
|
||||
seed_e.textChanged.connect(set_enabled)
|
||||
self.set_layout(vbox)
|
||||
if not self.exec_():
|
||||
return
|
||||
raise UserCancelled
|
||||
return self.get_seed_text(seed_e)
|
||||
|
||||
|
||||
def multi_mpk_dialog(self, xpub_hot, n):
|
||||
def request_many(self, n, xpub_hot=None):
|
||||
vbox = QVBoxLayout()
|
||||
scroll = QScrollArea()
|
||||
scroll.setEnabled(True)
|
||||
@@ -203,75 +260,45 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin):
|
||||
innerVbox = QVBoxLayout()
|
||||
w.setLayout(innerVbox)
|
||||
|
||||
vbox0 = seed_dialog.show_seed_box(MSG_SHOW_MPK, xpub_hot, 'hot')
|
||||
innerVbox.addLayout(vbox0)
|
||||
entries = []
|
||||
if xpub_hot:
|
||||
vbox0 = seed_dialog.show_seed_box(MSG_SHOW_MPK, xpub_hot, 'hot')
|
||||
else:
|
||||
vbox0, seed_e1 = seed_dialog.enter_seed_box(MSG_ENTER_SEED_OR_MPK, self, 'hot')
|
||||
entries.append(seed_e1)
|
||||
innerVbox.addLayout(vbox0)
|
||||
|
||||
for i in range(n):
|
||||
msg = _("Please enter the master public key of cosigner") + ' %d'%(i+1)
|
||||
if xpub_hot:
|
||||
msg = MSG_COSIGNER % (i + 1)
|
||||
else:
|
||||
msg = MSG_ENTER_SEED_OR_MPK
|
||||
vbox2, seed_e2 = seed_dialog.enter_seed_box(msg, self, 'cold')
|
||||
innerVbox.addLayout(vbox2)
|
||||
entries.append(seed_e2)
|
||||
|
||||
vbox.addStretch(1)
|
||||
button = OkButton(self, _('Next'))
|
||||
vbox.addLayout(Buttons(CancelButton(self), button))
|
||||
button.setEnabled(False)
|
||||
f = lambda: button.setEnabled( map(lambda e: Wallet.is_xpub(self.get_seed_text(e)), entries) == [True]*len(entries))
|
||||
def get_texts():
|
||||
return [self.get_seed_text(entry) for entry in entries]
|
||||
def set_enabled():
|
||||
texts = get_texts()
|
||||
is_valid = Wallet.is_xpub if xpub_hot else Wallet.is_any
|
||||
all_valid = all(is_valid(text) for text in texts)
|
||||
if xpub_hot:
|
||||
texts.append(xpub_hot)
|
||||
has_dups = len(set(texts)) < len(texts)
|
||||
button.setEnabled(all_valid and not has_dups)
|
||||
for e in entries:
|
||||
e.textChanged.connect(f)
|
||||
e.textChanged.connect(set_enabled)
|
||||
self.set_layout(vbox)
|
||||
if not self.exec_():
|
||||
return
|
||||
return map(lambda e: self.get_seed_text(e), entries)
|
||||
raise UserCancelled
|
||||
return get_texts()
|
||||
|
||||
|
||||
def multi_seed_dialog(self, n):
|
||||
vbox = QVBoxLayout()
|
||||
scroll = QScrollArea()
|
||||
scroll.setEnabled(True)
|
||||
scroll.setWidgetResizable(True)
|
||||
vbox.addWidget(scroll)
|
||||
|
||||
w = QWidget()
|
||||
scroll.setWidget(w)
|
||||
|
||||
innerVbox = QVBoxLayout()
|
||||
w.setLayout(innerVbox)
|
||||
|
||||
vbox1, seed_e1 = seed_dialog.enter_seed_box(MSG_ENTER_SEED_OR_MPK, self, 'hot')
|
||||
innerVbox.addLayout(vbox1)
|
||||
entries = [seed_e1]
|
||||
for i in range(n):
|
||||
vbox2, seed_e2 = seed_dialog.enter_seed_box(MSG_ENTER_SEED_OR_MPK, self, 'cold')
|
||||
innerVbox.addLayout(vbox2)
|
||||
entries.append(seed_e2)
|
||||
vbox.addStretch(1)
|
||||
button = OkButton(self, _('Next'))
|
||||
vbox.addLayout(Buttons(CancelButton(self), button))
|
||||
button.setEnabled(False)
|
||||
f = lambda: button.setEnabled( map(lambda e: self.is_any(self.get_seed_text(e)), entries) == [True]*len(entries))
|
||||
for e in entries:
|
||||
e.textChanged.connect(f)
|
||||
self.set_layout(vbox)
|
||||
if not self.exec_():
|
||||
return
|
||||
return map(lambda e: self.get_seed_text(e), entries)
|
||||
|
||||
|
||||
def waiting_dialog(self, task, msg= _("Electrum is generating your addresses, please wait.")):
|
||||
def target():
|
||||
task()
|
||||
self.emit(QtCore.SIGNAL('accept'))
|
||||
|
||||
vbox = QVBoxLayout()
|
||||
self.waiting_label = QLabel(msg)
|
||||
vbox.addWidget(self.waiting_label)
|
||||
self.set_layout(vbox)
|
||||
t = threading.Thread(target = target)
|
||||
t.start()
|
||||
self.exec_()
|
||||
|
||||
|
||||
def network_dialog(self):
|
||||
def network_dialog(self, network):
|
||||
grid = QGridLayout()
|
||||
grid.setSpacing(5)
|
||||
label = QLabel(_("Electrum communicates with remote servers to get information about your transactions and addresses. The servers all fulfil the same purpose only differing in hardware. In most cases you simply want to let Electrum pick one at random if you have a preference though feel free to select a server manually.") + "\n\n" \
|
||||
@@ -296,31 +323,14 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin):
|
||||
return
|
||||
|
||||
if b2.isChecked():
|
||||
return NetworkDialog(self.network, self.config, None).do_exec()
|
||||
NetworkDialog(network, self.config, None).do_exec()
|
||||
else:
|
||||
self.config.set_key('auto_connect', True, True)
|
||||
self.network.auto_connect = True
|
||||
return
|
||||
network.auto_connect = True
|
||||
|
||||
|
||||
def show_message(self, msg, icon=None):
|
||||
def choice(self, msg, choices):
|
||||
vbox = QVBoxLayout()
|
||||
self.set_layout(vbox)
|
||||
if icon:
|
||||
logo = QLabel()
|
||||
logo.setPixmap(icon)
|
||||
vbox.addWidget(logo)
|
||||
vbox.addWidget(QLabel(msg))
|
||||
vbox.addStretch(1)
|
||||
vbox.addLayout(Buttons(CloseButton(self)))
|
||||
if not self.exec_():
|
||||
return None
|
||||
|
||||
|
||||
def choice(self, title, msg, choices):
|
||||
vbox = QVBoxLayout()
|
||||
self.set_layout(vbox)
|
||||
vbox.addWidget(QLabel(title))
|
||||
gb2 = QGroupBox(msg)
|
||||
vbox.addWidget(gb2)
|
||||
|
||||
@@ -337,15 +347,15 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin):
|
||||
if i==0:
|
||||
button.setChecked(True)
|
||||
vbox.addStretch(1)
|
||||
vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _('Next'))))
|
||||
next_button = OkButton(self, _('Next'))
|
||||
next_button.setEnabled(bool(choices))
|
||||
vbox.addLayout(Buttons(CancelButton(self), next_button))
|
||||
if not self.exec_():
|
||||
return
|
||||
raise UserCancelled
|
||||
wallet_type = choices[group2.checkedId()][0]
|
||||
return wallet_type
|
||||
|
||||
|
||||
def multisig_choice(self):
|
||||
|
||||
def query_multisig(self, action):
|
||||
vbox = QVBoxLayout()
|
||||
self.set_layout(vbox)
|
||||
vbox.addWidget(QLabel(_("Multi Signature Wallet")))
|
||||
@@ -379,178 +389,15 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin):
|
||||
vbox.addStretch(1)
|
||||
vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _('Next'))))
|
||||
if not self.exec_():
|
||||
return
|
||||
raise UserCancelled
|
||||
m = int(m_edit.value())
|
||||
n = int(n_edit.value())
|
||||
wallet_type = '%dof%d'%(m,n)
|
||||
return wallet_type
|
||||
|
||||
def show_seed(self, seed, sid):
|
||||
vbox = seed_dialog.show_seed_box_msg(seed, sid)
|
||||
def show_seed(self, seed):
|
||||
vbox = seed_dialog.show_seed_box_msg(seed, None)
|
||||
vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _("Next"))))
|
||||
self.set_layout(vbox)
|
||||
return self.exec_()
|
||||
|
||||
def password_dialog(self):
|
||||
from password_dialog import PasswordDialog
|
||||
msg = _("Please choose a password to encrypt your wallet keys.\n"
|
||||
"Leave these fields empty if you want to disable encryption.")
|
||||
dialog = PasswordDialog(self, None, _("Choose a password"), msg, True)
|
||||
return dialog.run()[2]
|
||||
|
||||
def run(self, action):
|
||||
if self.storage.file_exists and action != 'new':
|
||||
path = self.storage.path
|
||||
msg = _("The file '%s' contains an incompletely created wallet.\n"
|
||||
"Do you want to complete its creation now?") % path
|
||||
if not self.question(msg):
|
||||
if self.question(_("Do you want to delete '%s'?") % path):
|
||||
os.remove(path)
|
||||
self.show_warning(_('The file was removed'))
|
||||
return
|
||||
return
|
||||
self.show()
|
||||
if action == 'new':
|
||||
action, wallet_type = self.restore_or_create()
|
||||
else:
|
||||
wallet_type = None
|
||||
try:
|
||||
wallet = self.run_wallet_type(action, wallet_type)
|
||||
except BaseException as e:
|
||||
traceback.print_exc(file=sys.stdout)
|
||||
self.show_error(str(e))
|
||||
return
|
||||
return wallet
|
||||
|
||||
def run_wallet_type(self, action, wallet_type):
|
||||
if action in ['create', 'restore']:
|
||||
if wallet_type == 'multisig':
|
||||
wallet_type = self.multisig_choice()
|
||||
if not wallet_type:
|
||||
return
|
||||
elif wallet_type == 'hardware':
|
||||
hardware_wallets = []
|
||||
for item in electrum.wallet.wallet_types:
|
||||
t, name, description, loader = item
|
||||
if t == 'hardware':
|
||||
try:
|
||||
p = loader()
|
||||
except:
|
||||
util.print_error("cannot load plugin for:", name)
|
||||
continue
|
||||
if p:
|
||||
hardware_wallets.append((name, description))
|
||||
wallet_type = self.choice(_("Hardware Wallet"), 'Select your hardware wallet', hardware_wallets)
|
||||
|
||||
if not wallet_type:
|
||||
return
|
||||
elif wallet_type == 'twofactor':
|
||||
wallet_type = '2fa'
|
||||
if action == 'create':
|
||||
self.storage.put('wallet_type', wallet_type)
|
||||
|
||||
if action is None:
|
||||
return
|
||||
|
||||
if action == 'restore':
|
||||
wallet = self.restore(wallet_type)
|
||||
if not wallet:
|
||||
return
|
||||
action = None
|
||||
else:
|
||||
wallet = Wallet(self.storage)
|
||||
action = wallet.get_action()
|
||||
# fixme: password is only needed for multiple accounts
|
||||
password = None
|
||||
|
||||
# load wallet in plugins
|
||||
always_hook('installwizard_load_wallet', wallet, self)
|
||||
|
||||
while action is not None:
|
||||
util.print_error("installwizard:", wallet, action)
|
||||
|
||||
if action == 'create_seed':
|
||||
lang = self.config.get('language')
|
||||
seed = wallet.make_seed(lang)
|
||||
if not self.show_seed(seed, None):
|
||||
return
|
||||
self.app.clipboard().clear()
|
||||
if not self.verify_seed(seed, None):
|
||||
return
|
||||
password = self.password_dialog()
|
||||
wallet.add_seed(seed, password)
|
||||
wallet.create_master_keys(password)
|
||||
|
||||
elif action == 'add_cosigners':
|
||||
n = int(re.match('(\d+)of(\d+)', wallet.wallet_type).group(2))
|
||||
xpub1 = wallet.master_public_keys.get("x1/")
|
||||
r = self.multi_mpk_dialog(xpub1, n - 1)
|
||||
if not r:
|
||||
return
|
||||
for i, xpub in enumerate(r):
|
||||
wallet.add_master_public_key("x%d/"%(i+2), xpub)
|
||||
|
||||
elif action == 'create_accounts':
|
||||
wallet.create_main_account(password)
|
||||
self.waiting_dialog(wallet.synchronize)
|
||||
|
||||
else:
|
||||
f = always_hook('get_wizard_action', self, wallet, action)
|
||||
if not f:
|
||||
raise BaseException('unknown wizard action', action)
|
||||
r = f(wallet, self)
|
||||
if not r:
|
||||
return
|
||||
|
||||
# next action
|
||||
action = wallet.get_action()
|
||||
|
||||
|
||||
if self.network:
|
||||
# show network dialog if config does not exist
|
||||
if self.config.get('server') is None:
|
||||
self.network_dialog()
|
||||
else:
|
||||
self.show_warning(_('You are offline'))
|
||||
|
||||
|
||||
# start wallet threads
|
||||
wallet.start_threads(self.network)
|
||||
|
||||
if action == 'restore':
|
||||
self.waiting_dialog(lambda: wallet.wait_until_synchronized(self.waiting_label.setText))
|
||||
if self.network:
|
||||
msg = _("Recovery successful") if wallet.is_found() else _("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
|
||||
|
||||
|
||||
|
||||
def restore(self, t):
|
||||
if t == 'standard':
|
||||
text = self.enter_seed_dialog(MSG_ENTER_ANYTHING, None)
|
||||
if not text:
|
||||
return
|
||||
password = self.password_dialog() if Wallet.is_seed(text) or Wallet.is_xprv(text) or Wallet.is_private_key(text) else None
|
||||
wallet = Wallet.from_text(text, password, self.storage)
|
||||
elif re.match('(\d+)of(\d+)', t):
|
||||
n = int(re.match('(\d+)of(\d+)', t).group(2))
|
||||
key_list = self.multi_seed_dialog(n - 1)
|
||||
if not key_list:
|
||||
return
|
||||
password = self.password_dialog() if any(map(lambda x: Wallet.is_seed(x) or Wallet.is_xprv(x), key_list)) else None
|
||||
wallet = Wallet.from_multisig(key_list, password, self.storage, t)
|
||||
else:
|
||||
self.storage.put('wallet_type', t)
|
||||
# call the constructor to load the plugin (side effect)
|
||||
Wallet(self.storage)
|
||||
wallet = always_hook('installwizard_restore', self, self.storage)
|
||||
if not wallet:
|
||||
util.print_error("no wallet")
|
||||
return
|
||||
# create first keys offline
|
||||
self.waiting_dialog(wallet.synchronize)
|
||||
return wallet
|
||||
if not self.exec_():
|
||||
raise UserCancelled
|
||||
|
||||
@@ -41,8 +41,8 @@ from electrum.util import block_explorer, block_explorer_info, block_explorer_UR
|
||||
from electrum.util import format_satoshis, format_satoshis_plain, format_time
|
||||
from electrum.util import PrintError, NotEnoughFunds, StoreDict
|
||||
from electrum import Transaction, mnemonic
|
||||
from electrum import util, bitcoin, commands, Wallet
|
||||
from electrum import SimpleConfig, COIN_CHOOSERS, WalletStorage
|
||||
from electrum import util, bitcoin, commands
|
||||
from electrum import SimpleConfig, COIN_CHOOSERS
|
||||
from electrum import Imported_Wallet, paymentrequest
|
||||
|
||||
from amountedit import BTCAmountEdit, MyLineEdit, BTCkBEdit
|
||||
@@ -173,8 +173,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
self.fetch_alias()
|
||||
self.require_fee_update = False
|
||||
self.tx_notifications = []
|
||||
# load wallet
|
||||
self.load_wallet(wallet)
|
||||
self.connect_slots(gui_object.timer)
|
||||
|
||||
def diagnostic_name(self):
|
||||
return "%s/%s" % (PrintError.diagnostic_name(self),
|
||||
@@ -247,12 +247,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
|
||||
def load_wallet(self, wallet):
|
||||
self.wallet = wallet
|
||||
# backward compatibility
|
||||
self.update_wallet_format()
|
||||
self.update_recently_visited(wallet.storage.path)
|
||||
self.import_old_contacts()
|
||||
# address used to create a dummy transaction and estimate transaction fee
|
||||
a = self.wallet.addresses(False)
|
||||
self.dummy_address = a[0] if a else None
|
||||
self.accounts_expanded = self.wallet.storage.get('accounts_expanded',{})
|
||||
self.current_account = self.wallet.storage.get("current_account", None)
|
||||
self.history_list.update()
|
||||
@@ -269,14 +265,17 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
self.clear_receive_tab()
|
||||
self.receive_list.update()
|
||||
self.tabs.show()
|
||||
self.watching_only_changed()
|
||||
|
||||
# set geometry
|
||||
try:
|
||||
self.setGeometry(*self.wallet.storage.get("winpos-qt"))
|
||||
except:
|
||||
self.setGeometry(100, 100, 840, 400)
|
||||
self.watching_only_changed()
|
||||
self.show()
|
||||
|
||||
if self.config.get('hide_gui') and self.gui_object.tray.isVisible():
|
||||
self.hide()
|
||||
else:
|
||||
self.show()
|
||||
run_hook('load_wallet', wallet, self)
|
||||
self.warn_if_watching_only()
|
||||
|
||||
@@ -311,19 +310,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
self.contacts[l] = ('address', k)
|
||||
self.wallet.storage.put('contacts', None)
|
||||
|
||||
def update_wallet_format(self):
|
||||
# convert old-format imported keys
|
||||
if self.wallet.imported_keys:
|
||||
password = self.password_dialog(_("Please enter your password in order to update imported keys")) if self.wallet.use_encryption else None
|
||||
try:
|
||||
self.wallet.convert_imported_keys(password)
|
||||
except Exception as e:
|
||||
traceback.print_exc(file=sys.stdout)
|
||||
self.show_message(str(e))
|
||||
# call synchronize to regenerate addresses in case we are offline
|
||||
if self.wallet.get_master_public_keys() and self.wallet.addresses() == []:
|
||||
self.wallet.synchronize()
|
||||
|
||||
def open_wallet(self):
|
||||
wallet_folder = self.get_wallet_folder()
|
||||
filename = unicode(QFileDialog.getOpenFileName(self, "Select your wallet file", wallet_folder))
|
||||
@@ -347,14 +333,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
except (IOError, os.error), reason:
|
||||
self.show_critical(_("Electrum was unable to copy your wallet file to the specified location.") + "\n" + str(reason), title=_("Unable to create backup"))
|
||||
|
||||
def update_recently_visited(self, filename=None):
|
||||
def update_recently_visited(self, filename):
|
||||
recent = self.config.get('recently_open', [])
|
||||
if filename:
|
||||
if filename in recent:
|
||||
recent.remove(filename)
|
||||
recent.insert(0, filename)
|
||||
recent = recent[:5]
|
||||
self.config.set_key('recently_open', recent)
|
||||
if filename in recent:
|
||||
recent.remove(filename)
|
||||
recent.insert(0, filename)
|
||||
recent = recent[:5]
|
||||
self.config.set_key('recently_open', recent)
|
||||
self.recently_visited_menu.clear()
|
||||
for i, k in enumerate(sorted(recent)):
|
||||
b = os.path.basename(k)
|
||||
@@ -380,11 +365,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
if not filename:
|
||||
return
|
||||
full_path = os.path.join(wallet_folder, filename)
|
||||
storage = WalletStorage(full_path)
|
||||
if storage.file_exists:
|
||||
if os.path.exists(full_path):
|
||||
self.show_critical(_("File exists"))
|
||||
return
|
||||
self.gui_object.install_wizard(storage, 'new')
|
||||
self.gui_object.start_new_window(full_path, None)
|
||||
|
||||
def init_menubar(self):
|
||||
menubar = QMenuBar()
|
||||
@@ -396,7 +380,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
file_menu.addAction(_("&Save Copy"), self.backup_wallet).setShortcut(QKeySequence.SaveAs)
|
||||
file_menu.addSeparator()
|
||||
file_menu.addAction(_("&Quit"), self.close)
|
||||
self.update_recently_visited()
|
||||
|
||||
wallet_menu = menubar.addMenu(_("&Wallet"))
|
||||
wallet_menu.addAction(_("&New contact"), self.new_contact_dialog)
|
||||
@@ -1088,7 +1071,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
else:
|
||||
fee = self.fee_e.get_amount() if freeze_fee else None
|
||||
if not outputs:
|
||||
addr = self.payto_e.payto_address if self.payto_e.payto_address else self.dummy_address
|
||||
addr = self.payto_e.payto_address if self.payto_e.payto_address else None
|
||||
outputs = [('address', addr, amount)]
|
||||
try:
|
||||
tx = self.wallet.make_unsigned_transaction(self.get_coins(), outputs, self.config, fee)
|
||||
@@ -1853,7 +1836,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
'password. To disable wallet encryption, enter an empty new '
|
||||
'password.') if self.wallet.use_encryption
|
||||
else _('Your wallet keys are not encrypted'))
|
||||
d = PasswordDialog(self, self.wallet, _("Set Password"), msg, True)
|
||||
d = PasswordDialog(self, self.wallet, msg, PasswordDialog.PW_CHANGE)
|
||||
ok, password, new_password = d.run()
|
||||
if not ok:
|
||||
return
|
||||
|
||||
@@ -41,8 +41,11 @@ def check_password_strength(password):
|
||||
|
||||
class PasswordDialog(WindowModalDialog):
|
||||
|
||||
def __init__(self, parent, wallet, title, msg, new_pass):
|
||||
WindowModalDialog.__init__(self, parent, title)
|
||||
PW_NEW, PW_CHANGE, PW_PASSPHRASE = range(0, 3)
|
||||
titles = [_("Enter Password"), _("Change Password"), _("Enter Passphrase")]
|
||||
|
||||
def __init__(self, parent, wallet, msg, kind):
|
||||
WindowModalDialog.__init__(self, parent, self.titles[kind])
|
||||
self.wallet = wallet
|
||||
|
||||
self.pw = QLineEdit()
|
||||
@@ -51,41 +54,48 @@ class PasswordDialog(WindowModalDialog):
|
||||
self.new_pw.setEchoMode(2)
|
||||
self.conf_pw = QLineEdit()
|
||||
self.conf_pw.setEchoMode(2)
|
||||
self.kind = kind
|
||||
|
||||
vbox = QVBoxLayout()
|
||||
label = QLabel(msg)
|
||||
label = QLabel(msg + "\n")
|
||||
label.setWordWrap(True)
|
||||
|
||||
grid = QGridLayout()
|
||||
grid.setSpacing(8)
|
||||
grid.setColumnMinimumWidth(0, 70)
|
||||
grid.setColumnMinimumWidth(0, 150)
|
||||
grid.setColumnMinimumWidth(1, 100)
|
||||
grid.setColumnStretch(1,1)
|
||||
|
||||
logo = QLabel()
|
||||
logo.setAlignment(Qt.AlignCenter)
|
||||
|
||||
grid.addWidget(logo, 0, 0)
|
||||
grid.addWidget(label, 0, 1, 1, 2)
|
||||
vbox.addLayout(grid)
|
||||
|
||||
grid = QGridLayout()
|
||||
grid.setSpacing(8)
|
||||
grid.setColumnMinimumWidth(0, 250)
|
||||
grid.setColumnStretch(1,1)
|
||||
|
||||
if wallet and wallet.use_encryption:
|
||||
grid.addWidget(QLabel(_('Password')), 0, 0)
|
||||
grid.addWidget(self.pw, 0, 1)
|
||||
lockfile = ":icons/lock.png"
|
||||
if kind == self.PW_PASSPHRASE:
|
||||
vbox.addWidget(label)
|
||||
msgs = [_('Passphrase:'), _('Confirm Passphrase:')]
|
||||
else:
|
||||
self.pw = None
|
||||
lockfile = ":icons/unlock.png"
|
||||
logo.setPixmap(QPixmap(lockfile).scaledToWidth(36))
|
||||
logo_grid = QGridLayout()
|
||||
logo_grid.setSpacing(8)
|
||||
logo_grid.setColumnMinimumWidth(0, 70)
|
||||
logo_grid.setColumnStretch(1,1)
|
||||
|
||||
grid.addWidget(QLabel(_('New Password') if new_pass else _('Password')), 1, 0)
|
||||
logo = QLabel()
|
||||
logo.setAlignment(Qt.AlignCenter)
|
||||
|
||||
logo_grid.addWidget(logo, 0, 0)
|
||||
logo_grid.addWidget(label, 0, 1, 1, 2)
|
||||
vbox.addLayout(logo_grid)
|
||||
|
||||
m1 = _('New Password:') if kind == self.PW_NEW else _('Password:')
|
||||
msgs = [m1, _('Confirm Password:')]
|
||||
if wallet and wallet.use_encryption:
|
||||
grid.addWidget(QLabel(_('Current Password:')), 0, 0)
|
||||
grid.addWidget(self.pw, 0, 1)
|
||||
lockfile = ":icons/lock.png"
|
||||
else:
|
||||
lockfile = ":icons/unlock.png"
|
||||
logo.setPixmap(QPixmap(lockfile).scaledToWidth(36))
|
||||
|
||||
grid.addWidget(QLabel(msgs[0]), 1, 0)
|
||||
grid.addWidget(self.new_pw, 1, 1)
|
||||
|
||||
grid.addWidget(QLabel(_('Confirm Password')), 2, 0)
|
||||
grid.addWidget(QLabel(msgs[1]), 2, 0)
|
||||
grid.addWidget(self.conf_pw, 2, 1)
|
||||
vbox.addLayout(grid)
|
||||
|
||||
@@ -120,8 +130,10 @@ class PasswordDialog(WindowModalDialog):
|
||||
if not self.exec_():
|
||||
return False, None, None
|
||||
|
||||
password = unicode(self.pw.text()) if self.pw else None
|
||||
new_password = unicode(self.new_pw.text())
|
||||
new_password2 = unicode(self.conf_pw.text())
|
||||
if self.kind == self.PW_CHANGE:
|
||||
old_password = unicode(self.pw.text()) or None
|
||||
else:
|
||||
old_password = None
|
||||
new_password = unicode(self.new_pw.text()) or None
|
||||
|
||||
return True, password or None, new_password or None
|
||||
return True, old_password, new_password
|
||||
|
||||
Reference in New Issue
Block a user