1
0

restore action-driven wizard logic

This commit is contained in:
ThomasV
2016-01-06 10:31:55 +01:00
parent 90a2fc1379
commit 5915b9b7e1
8 changed files with 43 additions and 27 deletions

View File

@@ -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

View File

@@ -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