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