electrum

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

commit 5915b9b7e1d9ab5b29300b5586076c9337311dfc
parent 90a2fc1379808c2a2f91302bfaa82a32ecd43df3
Author: ThomasV <thomasv@electrum.org>
Date:   Wed,  6 Jan 2016 10:31:55 +0100

restore action-driven wizard logic

Diffstat:
Mgui/qt/installwizard.py | 14+++++++++++++-
Mlib/wallet.py | 16+++++++++-------
Mlib/wizard.py | 28+++++++++++++++-------------
Mplugins/ledger/ledger.py | 2+-
Mplugins/ledger/qt.py | 2+-
Mplugins/trezor/plugin.py | 2+-
Mplugins/trezor/qt_generic.py | 2+-
Mplugins/trustedcoin/trustedcoin.py | 4++--
8 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py @@ -147,7 +147,19 @@ class InstallWizard(WindowModalDialog, WizardBase): 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 create_addresses(self, wallet): + def task(): + wallet.synchronize() + self.emit(QtCore.SIGNAL('accept')) + t = threading.Thread(target = task) + t.start() + vbox = QVBoxLayout() + self.waiting_label = QLabel(MSG_GENERATING_WAIT) + vbox.addWidget(self.waiting_label) + self.set_layout(vbox) + self.raise_() + self.exec_() def set_layout(self, layout): w = QWidget() diff --git a/lib/wallet.py b/lib/wallet.py @@ -316,7 +316,7 @@ class Abstract_Wallet(PrintError): if removed: self.save_accounts() - def create_main_account(self, password): + def create_main_account(self): pass def synchronize(self): @@ -1545,6 +1545,8 @@ class Deterministic_Wallet(Abstract_Wallet): def get_action(self): if not self.get_master_public_key(): return 'create_seed' + if not self.accounts: + return 'create_main_account' def get_master_public_keys(self): out = {} @@ -1697,7 +1699,7 @@ class BIP32_HD_Wallet(BIP32_Wallet): return (self.can_create_accounts() and not self.show_account(self.last_account_id())) - def create_main_account(self, password): + def create_hd_account(self, password): # First check the password is valid (this raises if it isn't). if self.can_change_password(): self.check_password(password) @@ -1783,7 +1785,7 @@ class NewWallet(BIP32_Wallet, Mnemonic): root_derivation = "m/" wallet_type = 'standard' - def create_main_account(self, password): + def create_main_account(self): xpub = self.master_public_keys.get("x/") account = BIP32_Account({'xpub':xpub}) self.add_account('0', account) @@ -1810,7 +1812,7 @@ class Multisig_Wallet(BIP32_Wallet, Mnemonic): v['xpubs'] = [v['xpub'], v['xpub2']] self.accounts = {'0': Multisig_Account(v)} - def create_main_account(self, password): + def create_main_account(self): account = Multisig_Account({'xpubs': self.master_public_keys.values(), 'm': self.m}) self.add_account('0', account) @@ -1821,6 +1823,8 @@ class Multisig_Wallet(BIP32_Wallet, Mnemonic): for i in range(self.n): if self.master_public_keys.get("x%d/"%(i+1)) is None: return 'create_seed' if i == 0 else 'add_cosigners' + if not self.accounts: + return 'create_main_account' class OldWallet(Deterministic_Wallet): @@ -1864,7 +1868,7 @@ class OldWallet(Deterministic_Wallet): def get_master_public_keys(self): return {'Main Account':self.get_master_public_key()} - def create_main_account(self, password): + def create_main_account(self): mpk = self.storage.get("master_public_key") self.create_account(mpk) @@ -2031,7 +2035,6 @@ class Wallet(object): w = klass(storage) w.add_seed(seed, password) w.create_master_keys(password) - w.create_main_account(password) return w @staticmethod @@ -2091,7 +2094,6 @@ class Wallet(object): else: raise RunTimeError("Cannot handle text for multisig") wallet.set_use_encryption(password is not None) - wallet.create_main_account(password) return wallet @staticmethod diff --git a/lib/wizard.py b/lib/wizard.py @@ -152,15 +152,12 @@ class WizardBase(PrintError): return task = lambda: self.show_restore(wallet, network, cr) - action = wallet.get_action() - requires_action = action is not None - while action: - self.run_wallet_action(wallet, action) + while True: action = wallet.get_action() - - # Save the wallet after successful completion of actions. - # It will be saved again once synchronized. - if requires_action: + if not action: + break + self.run_wallet_action(wallet, action) + # Save the wallet after each action wallet.storage.write() if network: @@ -168,11 +165,10 @@ class WizardBase(PrintError): else: self.show_warning(_('You are offline')) + self.create_addresses(wallet) # start wallet threads if network: wallet.start_threads(network) - else: - wallet.synchronize() if task: task() @@ -263,14 +259,20 @@ class WizardBase(PrintError): return Wallet.from_multisig(key_list, password, storage, wallet_type) def create_seed(self, wallet): - '''The create_seed action creates a seed and then generates - wallet account(s).''' + '''The create_seed action creates a seed and generates + master keys.''' seed = wallet.make_seed(self.language_for_seed) self.show_and_verify_seed(seed) password = self.request_password() wallet.add_seed(seed, password) wallet.create_master_keys(password) - wallet.create_main_account(password) + + def create_main_account(self, wallet): + # FIXME: BIP44 restore requires password + wallet.create_main_account() + + def create_addresses(self, wallet): + wallet.synchronize() def add_cosigners(self, wallet): # FIXME: better handling of duplicate keys diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py @@ -449,7 +449,7 @@ class LedgerPlugin(BasePlugin): password = wizard.request_password() wallet.add_seed(seed, password) wallet.add_cosigner_seed(seed, 'x/', password, passphrase) - wallet.create_main_account(password) + wallet.create_hd_account(password) return wallet @hook diff --git a/plugins/ledger/qt.py b/plugins/ledger/qt.py @@ -24,7 +24,7 @@ class Plugin(LedgerPlugin): def on_create_wallet(self, wallet, wizard): self.handler = BTChipQTHandler(wizard) - wallet.create_main_account(None) + wallet.create_main_account() class BTChipQTHandler: diff --git a/plugins/trezor/plugin.py b/plugins/trezor/plugin.py @@ -327,7 +327,7 @@ class TrezorCompatiblePlugin(BasePlugin, ThreadJob): password = wizard.request_password() wallet.add_seed(seed, password) wallet.add_cosigner_seed(seed, 'x/', password, passphrase) - wallet.create_main_account(password) + wallet.create_hd_account(password) return wallet def sign_transaction(self, wallet, tx, prev_tx, xpub_path): diff --git a/plugins/trezor/qt_generic.py b/plugins/trezor/qt_generic.py @@ -159,7 +159,7 @@ def qt_plugin_class(base_plugin_class): assert type(wallet) == self.wallet_class wallet.handler = self.create_handler(wizard) self.select_device(wallet, wizard) - wallet.create_main_account(None) + wallet.create_main_account() @hook def receive_menu(self, menu, addrs, wallet): diff --git a/plugins/trustedcoin/trustedcoin.py b/plugins/trustedcoin/trustedcoin.py @@ -364,7 +364,7 @@ class TrustedCoinPlugin(BasePlugin): wallet.add_cosigner_seed(' '.join(words[n:]), 'x2/', password) restore_third_key(wallet) - wallet.create_main_account(password) + wallet.create_main_account() return wallet def create_remote_key(self, wallet, window): @@ -406,4 +406,4 @@ class TrustedCoinPlugin(BasePlugin): if self.setup_google_auth(window, short_id, otp_secret): wallet.add_master_public_key('x3/', xpub3) - wallet.create_main_account(None) + wallet.create_main_account()