Put open_wallet back as class method.

This commit is contained in:
Neil Booth 2016-01-13 20:55:51 +09:00
parent cb8bc4ec73
commit 4c9b224d4c
3 changed files with 69 additions and 65 deletions

View File

@ -141,15 +141,15 @@ class InstallWizard(WindowModalDialog, WizardBase):
self.app.processEvents()
self.app.processEvents()
@classmethod
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)
wallet = InstallWizard.open_wallet(self, *args)
except UserCancelled:
self.print_error("wallet creation cancelled by user")
self.accept()
return wallet
def remove_from_recently_open(self, filename):

View File

@ -23,6 +23,7 @@ from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer, SimpleJSONRPCReq
from util import json_decode, DaemonThread
from wallet import WalletStorage, Wallet
from wizard import WizardBase
from commands import known_commands, Commands
from simple_config import SimpleConfig
@ -125,7 +126,8 @@ class Daemon(DaemonThread):
wallet = self.wallets[path]
else:
if get_wizard:
wallet = self.open_wallet_with_wizard(self.network, path, get_wizard)
wallet = WizardBase.open_wallet(self.network, path,
self.config, get_wizard)
else:
storage = WalletStorage(path)
wallet = Wallet(storage)
@ -134,57 +136,6 @@ class Daemon(DaemonThread):
self.wallets[path] = wallet
return wallet
def open_wallet_with_wizard(self, network, filename, get_wizard):
'''Instantiate wizard only if needed'''
storage = WalletStorage(filename)
need_sync = False
is_restore = False
self.wizard = None
def wizard():
if self.wizard is None:
self.wizard = get_wizard()
return self.wizard
if storage.file_exists:
wallet = Wallet(storage)
#self.update_wallet_format(wallet)
else:
cr, wallet = wizard().create_or_restore(storage)
if not wallet:
return
need_sync = True
is_restore = (cr == 'restore')
while True:
action = wallet.get_action()
if not action:
break
need_sync = True
wizard().run_wallet_action(wallet, action)
# Save the wallet after each action
wallet.storage.write()
if network:
# Show network dialog if config does not exist
if self.config.get('server') is None:
wizard().choose_server(network)
else:
wizard().show_warning(_('You are offline'))
if need_sync:
wizard().create_addresses(wallet)
# start wallet threads
if network:
wallet.start_threads(network)
if is_restore:
wizard().show_restore(wallet, network)
return wallet
def run_cmdline(self, config_options):
config = SimpleConfig(config_options)
cmdname = config.get('cmd')

View File

@ -119,7 +119,61 @@ class WizardBase(PrintError):
"""Show restore result"""
pass
@classmethod
def open_wallet(self, network, filename, config, create_wizard):
'''The main entry point of the wizard. Open a wallet from the given
filename. If the file doesn't exist launch the GUI-specific
install wizard proper, created by calling create_wizard().'''
storage = WalletStorage(filename)
need_sync = False
is_restore = False
self.my_wizard = None
def wizard():
if self.my_wizard is None:
self.my_wizard = create_wizard()
return self.my_wizard
if storage.file_exists:
wallet = Wallet(storage)
if wallet.imported_keys:
wizard().update_wallet_format(wallet)
else:
cr, wallet = wizard().create_or_restore(storage)
if not wallet:
return
need_sync = True
is_restore = (cr == 'restore')
while True:
action = wallet.get_action()
if not action:
break
need_sync = True
wizard().run_wallet_action(wallet, action)
# Save the wallet after each action
wallet.storage.write()
if network:
# Show network dialog if config does not exist
if config.get('server') is None:
wizard().choose_server(network)
else:
wizard().show_warning(_('You are offline'))
if need_sync:
wizard().create_addresses(wallet)
# start wallet threads
if network:
wallet.start_threads(network)
if is_restore:
wizard().show_restore(wallet, network)
self.my_wizard = None
return wallet
def run_wallet_action(self, wallet, action):
self.print_error("action %s on %s" % (action, wallet.basename()))
@ -233,18 +287,17 @@ class WizardBase(PrintError):
def update_wallet_format(self, wallet):
# Backwards compatibility: convert old-format imported keys
if wallet.imported_keys:
msg = _("Please enter your password in order to update "
"imported keys")
if wallet.use_encryption:
password = self.request_password(msg)
else:
password = None
msg = _("Please enter your password in order to update "
"imported keys")
if wallet.use_encryption:
password = self.request_password(msg)
else:
password = None
try:
wallet.convert_imported_keys(password)
except Exception as e:
self.show_error(str(e))
try:
wallet.convert_imported_keys(password)
except Exception as e:
self.show_error(str(e))
# Call synchronize to regenerate addresses in case we're offline
if wallet.get_master_public_keys() and not wallet.addresses():