Put open_wallet back as class method.
This commit is contained in:
@@ -141,15 +141,15 @@ class InstallWizard(WindowModalDialog, WizardBase):
|
|||||||
self.app.processEvents()
|
self.app.processEvents()
|
||||||
self.app.processEvents()
|
self.app.processEvents()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def open_wallet(self, *args):
|
def open_wallet(self, *args):
|
||||||
'''Wrap the base wizard implementation with try/except blocks
|
'''Wrap the base wizard implementation with try/except blocks
|
||||||
to give a sensible error message to the user.'''
|
to give a sensible error message to the user.'''
|
||||||
wallet = None
|
wallet = None
|
||||||
try:
|
try:
|
||||||
wallet = super(InstallWizard, self).open_wallet(*args)
|
wallet = InstallWizard.open_wallet(self, *args)
|
||||||
except UserCancelled:
|
except UserCancelled:
|
||||||
self.print_error("wallet creation cancelled by user")
|
self.print_error("wallet creation cancelled by user")
|
||||||
self.accept()
|
|
||||||
return wallet
|
return wallet
|
||||||
|
|
||||||
def remove_from_recently_open(self, filename):
|
def remove_from_recently_open(self, filename):
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer, SimpleJSONRPCReq
|
|||||||
|
|
||||||
from util import json_decode, DaemonThread
|
from util import json_decode, DaemonThread
|
||||||
from wallet import WalletStorage, Wallet
|
from wallet import WalletStorage, Wallet
|
||||||
|
from wizard import WizardBase
|
||||||
from commands import known_commands, Commands
|
from commands import known_commands, Commands
|
||||||
from simple_config import SimpleConfig
|
from simple_config import SimpleConfig
|
||||||
|
|
||||||
@@ -125,7 +126,8 @@ class Daemon(DaemonThread):
|
|||||||
wallet = self.wallets[path]
|
wallet = self.wallets[path]
|
||||||
else:
|
else:
|
||||||
if get_wizard:
|
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:
|
else:
|
||||||
storage = WalletStorage(path)
|
storage = WalletStorage(path)
|
||||||
wallet = Wallet(storage)
|
wallet = Wallet(storage)
|
||||||
@@ -134,57 +136,6 @@ class Daemon(DaemonThread):
|
|||||||
self.wallets[path] = wallet
|
self.wallets[path] = wallet
|
||||||
return 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):
|
def run_cmdline(self, config_options):
|
||||||
config = SimpleConfig(config_options)
|
config = SimpleConfig(config_options)
|
||||||
cmdname = config.get('cmd')
|
cmdname = config.get('cmd')
|
||||||
|
|||||||
@@ -119,7 +119,61 @@ class WizardBase(PrintError):
|
|||||||
"""Show restore result"""
|
"""Show restore result"""
|
||||||
pass
|
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):
|
def run_wallet_action(self, wallet, action):
|
||||||
self.print_error("action %s on %s" % (action, wallet.basename()))
|
self.print_error("action %s on %s" % (action, wallet.basename()))
|
||||||
@@ -233,18 +287,17 @@ class WizardBase(PrintError):
|
|||||||
|
|
||||||
def update_wallet_format(self, wallet):
|
def update_wallet_format(self, wallet):
|
||||||
# Backwards compatibility: convert old-format imported keys
|
# Backwards compatibility: convert old-format imported keys
|
||||||
if wallet.imported_keys:
|
msg = _("Please enter your password in order to update "
|
||||||
msg = _("Please enter your password in order to update "
|
"imported keys")
|
||||||
"imported keys")
|
if wallet.use_encryption:
|
||||||
if wallet.use_encryption:
|
password = self.request_password(msg)
|
||||||
password = self.request_password(msg)
|
else:
|
||||||
else:
|
password = None
|
||||||
password = None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
wallet.convert_imported_keys(password)
|
wallet.convert_imported_keys(password)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.show_error(str(e))
|
self.show_error(str(e))
|
||||||
|
|
||||||
# Call synchronize to regenerate addresses in case we're offline
|
# Call synchronize to regenerate addresses in case we're offline
|
||||||
if wallet.get_master_public_keys() and not wallet.addresses():
|
if wallet.get_master_public_keys() and not wallet.addresses():
|
||||||
|
|||||||
Reference in New Issue
Block a user