def main(self, url=None): storage = WalletStorage(self.config) if not storage.file_exists: action = self.restore_or_create() if not action: exit() self.wallet = wallet = Wallet(storage) gap = self.config.get('gap_limit', 5) if gap != 5: wallet.gap_limit = gap wallet.storage.put('gap_limit', gap, True) self.wallet.start_threads(self.network) if action == 'create': wallet.init_seed(None) wallet.save_seed() wallet.synchronize() # generate first addresses offline elif action == 'restore': seed = self.seed_dialog() wallet.init_seed(seed) wallet.save_seed() self.restore_wallet(wallet) else: exit() else: self.wallet = Wallet(storage) self.wallet.start_threads(self.network) w = ElectrumWindow(self.wallet, self.config, self.network) if url: w.set_url(url) gtk.main()
def __init__(self, _config, _network, plugins): global wallet, network, contacts, config network = _network config = _config network.register_callback('updated', update_callback) network.register_callback('connected', update_callback) network.register_callback('disconnected', update_callback) network.register_callback('disconnecting', update_callback) contacts = util.StoreDict(config, 'contacts') storage = WalletStorage(config.get_wallet_path()) if not storage.file_exists: action = self.restore_or_create() if not action: exit() password = droid.dialogGetPassword('Choose a password').result if password: password2 = droid.dialogGetPassword('Confirm password').result if password != password2: modal_dialog('Error', 'passwords do not match') exit() else: # set to None if it's an empty string password = None if action == 'create': wallet = Wallet(storage) seed = wallet.make_seed() modal_dialog('Your seed is:', seed) wallet.add_seed(seed, password) wallet.create_master_keys(password) wallet.create_main_account(password) elif action == 'restore': seed = self.seed_dialog() if not seed: exit() if not Wallet.is_seed(seed): exit() wallet = Wallet.from_seed(seed, password, storage) else: exit() msg = "Creating wallet" if action == 'create' else "Restoring wallet" droid.dialogCreateSpinnerProgress("Electrum", msg) droid.dialogShow() wallet.start_threads(network) if action == 'restore': wallet.wait_until_synchronized() else: wallet.synchronize() droid.dialogDismiss() droid.vibrate() else: wallet = Wallet(storage) wallet.start_threads(network)
def load_wallet_by_name(self, wallet_path): if not wallet_path: return self.stop_wallet() config = self.electrum_config storage = WalletStorage(wallet_path) Logger.info('Electrum: Check for existing wallet') if storage.file_exists: wallet = Wallet(storage) action = wallet.get_action() else: action = 'new' if action is not None: # start installation wizard Logger.debug( 'Electrum: Wallet not found. Launching install wizard') wizard = Factory.InstallWizard(config, self.network, storage) wizard.bind(on_wizard_complete=lambda instance, wallet: self. load_wallet(wallet)) wizard.run(action) else: wallet.start_threads(self.network) self.load_wallet(wallet) self.on_resume()
def main(self, url): storage = WalletStorage(self.config) if not storage.file_exists: import installwizard wizard = installwizard.InstallWizard(self.config, self.network, storage) wallet = wizard.run() if not wallet: exit() else: wallet = Wallet(storage) wallet.start_threads(self.network) self.main_window = w = ElectrumWindow(self.config, self.network) # plugins that need to change the GUI do it here run_hook('init') w.load_wallet(wallet) s = Timer() s.start() self.windows.append(w) if url: w.set_url(url) w.app = self.app w.connect_slots(s) w.update_wallet() self.app.exec_() wallet.stop_threads()
def __init__(self, config, network, storage): super(InstallWizard, self).__init__() self.config = config self.network = network self.storage = storage self.wallet = Wallet(self.storage) self.is_restore = False
def load_wallet_by_name(self, wallet_path): if not wallet_path: return config = self.electrum_config try: storage = WalletStorage(wallet_path) except IOError: self.show_error("Cannot read wallet file") return if storage.file_exists: wallet = Wallet(storage) action = wallet.get_action() else: action = 'new' if action is not None: # start installation wizard Logger.debug( 'Electrum: Wallet not found. Launching install wizard') wizard = Factory.InstallWizard(config, self.network, storage) wizard.bind(on_wizard_complete=lambda instance, wallet: self. load_wallet(wallet)) wizard.run(action) else: self.load_wallet(wallet) self.on_resume()
def load_wallet_file(self, filename): try: storage = WalletStorage(filename) except Exception as e: QMessageBox.information(None, _('Error'), str(e), _('OK')) return if not storage.file_exists: recent = self.config.get('recently_open', []) if filename in recent: recent.remove(filename) self.config.set_key('recently_open', recent) action = 'new' else: try: wallet = Wallet(storage) except BaseException as e: traceback.print_exc(file=sys.stdout) QMessageBox.warning(None, _('Warning'), str(e), _('OK')) return action = wallet.get_action() # run wizard if action is not None: wizard = InstallWizard(self.config, self.network, storage) wallet = wizard.run(action) # keep current wallet if not wallet: return else: wallet.start_threads(self.network) return wallet
def restore(self, t): if t == 'standard': text = self.enter_seed_dialog(MSG_ENTER_ANYTHING, None) if not text: return password = self.password_dialog( ) if Wallet.is_seed(text) or Wallet.is_xprv( text) or Wallet.is_private_key(text) else None wallet = Wallet.from_text(text, password, self.storage) elif re.match('(\d+)of(\d+)', t): n = int(re.match('(\d+)of(\d+)', t).group(2)) key_list = self.multi_seed_dialog(n - 1) if not key_list: return password = self.password_dialog() if any( map(lambda x: Wallet.is_seed(x) or Wallet.is_xprv(x), key_list)) else None wallet = Wallet.from_multisig(key_list, password, self.storage, t) else: self.storage.put('wallet_type', t, False) # call the constructor to load the plugin (side effect) Wallet(self.storage) wallet = always_hook('installwizard_restore', self, self.storage) if not wallet: util.print_error("no wallet") return # create first keys offline self.waiting_dialog(wallet.synchronize) return wallet
def main(self, url=None): storage = WalletStorage(self.config) if not storage.file_exists: action = self.restore_or_create() if not action: exit() self.wallet = wallet = Wallet(storage) gap = self.config.get('gap_limit', 5) if gap != 5: wallet.gap_limit = gap wallet.storage.put('gap_limit', gap, True) if action == 'create': seed = wallet.make_seed() show_seed_dialog(seed, None) r = change_password_dialog(False, None) password = r[2] if r else None wallet.add_seed(seed, password) wallet.create_master_keys(password) wallet.create_main_account(password) wallet.synchronize() # generate first addresses offline elif action == 'restore': seed = self.seed_dialog() if not seed: exit() r = change_password_dialog(False, None) password = r[2] if r else None wallet.add_seed(seed, password) wallet.create_master_keys(password) wallet.create_main_account(password) else: exit() else: self.wallet = Wallet(storage) action = None self.wallet.start_threads(self.network) if action == 'restore': self.restore_wallet(wallet) w = ElectrumWindow(self.wallet, self.config, self.network) if url: w.set_url(url) Gtk.main()
def main(self, url): storage = WalletStorage(self.config) if storage.file_exists: wallet = Wallet(storage) action = wallet.get_action() else: action = 'new' if action is not None: import installwizard wizard = installwizard.InstallWizard(self.config, self.network, storage) wallet = wizard.run(action) if not wallet: exit() else: wallet.start_threads(self.network) # init tray self.dark_icon = self.config.get("dark_icon", False) icon = QIcon(":icons/electrum_dark_icon.png") if self.dark_icon else QIcon(':icons/electrum_light_icon.png') self.tray = QSystemTrayIcon(icon, None) self.tray.setToolTip('Electrum') self.tray.activated.connect(self.tray_activated) self.build_tray_menu() self.tray.show() # main window self.main_window = w = ElectrumWindow(self.config, self.network, self) self.current_window = self.main_window #lite window self.init_lite() # plugins that need to change the GUI do it here run_hook('init') w.load_wallet(wallet) s = Timer() s.start() self.windows.append(w) if url: self.set_url(url) w.app = self.app w.connect_slots(s) w.update_wallet() self.app.exec_() # clipboard persistence # see http://www.mail-archive.com/[email protected]/msg17328.html event = QtCore.QEvent(QtCore.QEvent.Clipboard) self.app.sendEvent(self.app.clipboard(), event) wallet.stop_threads()
def __init__(self, config, daemon, plugins): self.config = config self.network = daemon.network self.preblockhash = self.network.get_pre_blockhash() storage = WalletStorage(config.get_wallet_path()) if not storage.file_exists(): print("Wallet not found. try 'electrum create'") exit() if storage.is_encrypted(): password = getpass.getpass('Password:'******'') self.encoding = locale.getpreferredencoding() self.stdscr = curses.initscr() curses.noecho() curses.cbreak() curses.start_color() curses.use_default_colors() curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE) curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_CYAN) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) self.stdscr.keypad(1) self.stdscr.border(0) self.maxy, self.maxx = self.stdscr.getmaxyx() self.set_cursor(0) self.w = curses.newwin(10, 50, 5, 5) set_verbosity(False) self.tab = 0 self.pos = 0 self.popup_pos = 0 self.str_recipient = "" self.str_description = "" self.str_amount = "" self.str_fee = "" self.history = None if self.network: self.network.register_callback(self.update, ['updated']) self.tab_names = [ _("History"), _("Send"), _("Receive"), _("Addresses"), _("Contacts"), _("Banner") ] self.num_tabs = len(self.tab_names)
def __init__(self, config, network): self.network = network self.config = config storage = WalletStorage(config) if not storage.file_exists: print "Wallet not found. try 'electrum create'" exit() self.wallet = Wallet(storage) self.wallet.start_threads(network)
def __init__(self, config, network, plugins): self.config = config self.network = network storage = WalletStorage(config.get_wallet_path()) if not storage.file_exists: print "Wallet not found. try 'electrum create'" exit() self.wallet = Wallet(storage) self.wallet.start_threads(self.network) self.contacts = StoreDict(self.config, 'contacts') locale.setlocale(locale.LC_ALL, '') self.encoding = locale.getpreferredencoding() self.stdscr = curses.initscr() curses.noecho() curses.cbreak() curses.start_color() curses.use_default_colors() curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE) curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_CYAN) self.stdscr.keypad(1) self.stdscr.border(0) self.maxy, self.maxx = self.stdscr.getmaxyx() self.set_cursor(0) self.w = curses.newwin(10, 50, 5, 5) set_verbosity(False) self.tab = 0 self.pos = 0 self.popup_pos = 0 self.str_recipient = "" self.str_description = "" self.str_amount = "" self.str_fee = "" self.history = None if self.network: self.network.register_callback('updated', self.update) self.network.register_callback('connected', self.refresh) self.network.register_callback('disconnected', self.refresh) self.network.register_callback('disconnecting', self.refresh) self.tab_names = [ _("History"), _("Send"), _("Receive"), _("Addresses"), _("Contacts"), _("Banner") ] self.num_tabs = len(self.tab_names)
def __init__(self, config, _network): global wallet, network network = _network network.register_callback('updated', update_callback) network.register_callback('connected', update_callback) network.register_callback('disconnected', update_callback) network.register_callback('disconnecting', update_callback) storage = WalletStorage(config) if not storage.file_exists: action = self.restore_or_create() if not action: exit() wallet = Wallet(storage) if action == 'create': wallet.init_seed(None) self.show_seed() wallet.save_seed() wallet.create_accounts() wallet.synchronize() # generate first addresses offline elif action == 'restore': seed = self.seed_dialog() if not seed: exit() wallet.init_seed(str(seed)) wallet.save_seed() else: exit() wallet.start_threads(network) if action == 'restore': if not self.restore_wallet(): exit() self.password_dialog() else: wallet = Wallet(storage) wallet.start_threads(network)
def __init__(self): global wallet self.qr_data = None storage = WalletStorage( {'wallet_path': '/sdcard/electrum/authenticator'}) if not storage.file_exists: action = self.restore_or_create() if not action: exit() password = droid.dialogGetPassword('Choose a password').result if password: password2 = droid.dialogGetPassword('Confirm password').result if password != password2: modal_dialog('Error', 'Passwords do not match') exit() else: password = None if action == 'create': wallet = Wallet(storage) seed = wallet.make_seed() modal_dialog('Your seed is:', seed) elif action == 'import': seed = self.seed_dialog() if not seed: exit() if not Wallet.is_seed(seed): exit() wallet = Wallet.from_seed(seed, storage) else: exit() wallet.add_seed(seed, password) wallet.create_master_keys(password) wallet.create_main_account(password) else: wallet = Wallet(storage)
def create_or_load_wallet(self): wallet = Wallet(self.storage) if not self.storage.file_exists: try: seed = wallet.make_seed() wallet.init_seed(seed) wallet.save_seed(self.__password__()) wallet.synchronize() config_entry = Configuration.objects.get() config_entry.wallet_seed = str(seed) config_entry.save() except Exception: exc_info = sys.exc_info() message = str(exc_info[0]) + ' - ' + str(exc_info[1]) utils.log_error('btc processor create or load wallet', message) return wallet
def on_start(self): ''' This is the start point of the kivy ui ''' Logger.info("dpi: {} {}".format(metrics.dpi, metrics.dpi_rounded)) win = Window win.bind(size=self.on_size, on_keyboard=self.on_keyboard) win.bind(on_key_down=self.on_key_down) # Register fonts without this you won't be able to use bold/italic... # inside markup. from kivy.core.text import Label Label.register('Roboto', 'data/fonts/Roboto.ttf', 'data/fonts/Roboto.ttf', 'data/fonts/Roboto-Bold.ttf', 'data/fonts/Roboto-Bold.ttf') if platform == 'android': # bind to keyboard height so we can get the window contents to # behave the way we want when the keyboard appears. win.bind(keyboard_height=self.on_keyboard_height) self.on_size(win, win.size) config = self.electrum_config storage = WalletStorage(config.get_wallet_path()) Logger.info('Electrum: Check for existing wallet') if storage.file_exists: wallet = Wallet(storage) action = wallet.get_action() else: action = 'new' if action is not None: # start installation wizard Logger.debug('Electrum: Wallet not found. Launching install wizard') wizard = Factory.InstallWizard(config, self.network, storage) wizard.bind(on_wizard_complete=self.on_wizard_complete) wizard.run(action) else: wallet.start_threads(self.network) self.on_wizard_complete(None, wallet) self.on_resume()
def on_creatrestore_complete(self, dialog, button): if not button: # soft back or escape button pressed return self.dispatch('on_wizard_complete', None) dialog.close() action = dialog.action if button == dialog.ids.create: wallet = Wallet(self.storage) self.password_dialog(wallet=wallet, mode='create') elif button == dialog.ids.restore: wallet = None self.restore_seed_dialog(wallet) else: self.dispatch('on_wizard_complete', None)
def on_creatrestore_complete(self, dialog, button): if not button: # soft back or escape button pressed return self.dispatch('on_wizard_complete', None) dialog.close() action = dialog.action if button == dialog.ids.create: # create # TODO take from UI instead of hardcoding #t = dialog.wallet_type t = 'standard' if t == 'standard': wallet = Wallet(self.storage) action = 'create' elif t == '2fa': wallet = Wallet_2of3(self.storage) run_hook('create_cold_seed', wallet, self) self.create_cold_seed(wallet) return elif t == '2of2': wallet = Wallet_2of2(self.storage) action = 'create_2of2_1' elif t == '2of3': wallet = Wallet_2of3(self.storage) action = 'create_2of3_1' if action in ['create_2fa_2', 'create_2of3_2']: wallet = Wallet_2of3(self.storage) if action in [ 'create', 'create_2of2_1', 'create_2fa_2', 'create_2of3_1' ]: self.password_dialog(wallet=wallet, mode=action) elif button == dialog.ids.restore: # restore wallet = None self.restore_seed_dialog(wallet) else: self.dispatch('on_wizard_complete', None)
def __init__(self, *, config, daemon, plugins): BaseElectrumGui.__init__(self, config=config, daemon=daemon, plugins=plugins) self.network = daemon.network storage = WalletStorage(config.get_wallet_path()) if not storage.file_exists(): print("Wallet not found. try 'electrum create'") exit() if storage.is_encrypted(): password = getpass.getpass('Password:', stream=None) storage.decrypt(password) db = WalletDB(storage.read(), manual_upgrades=False) self.done = 0 self.last_balance = "" self.str_recipient = "" self.str_description = "" self.str_amount = "" self.str_fee = "" self.wallet = Wallet(db, storage, config=config) # type: Optional[Abstract_Wallet] self.wallet.start_network(self.network) self.contacts = self.wallet.contacts self.register_callbacks() self.commands = [_("[h] - displays this help text"), \ _("[i] - display transaction history"), \ _("[o] - enter payment order"), \ _("[p] - print stored payment order"), \ _("[s] - send stored payment order"), \ _("[r] - show own receipt addresses"), \ _("[c] - display contacts"), \ _("[b] - print server banner"), \ _("[q] - quit")] self.num_commands = len(self.commands)
def __init__(self, config, daemon, plugins): self.config = config self.network = daemon.network storage = WalletStorage(config.get_wallet_path()) if not storage.file_exists: print("Wallet not found. try 'electrum-bitg create'") exit() if storage.is_encrypted(): password = getpass.getpass('Password:'******'wallet_updated', 'network_updated', 'banner']) self.commands = [_("[h] - displays this help text"), \ _("[i] - display transaction history"), \ _("[o] - enter payment order"), \ _("[p] - print stored payment order"), \ _("[s] - send stored payment order"), \ _("[r] - show own receipt addresses"), \ _("[c] - display contacts"), \ _("[b] - print server banner"), \ _("[q] - quit") ] self.num_commands = len(self.commands)
def __init__(self, config, network): self.network = network self.config = config storage = WalletStorage(config) if not storage.file_exists: print "Wallet not found. try 'electrum create'" exit() self.done = 0 self.last_balance = "" set_verbosity(False) self.str_recipient = "" self.str_description = "" self.str_amount = "" self.str_fee = "" self.wallet = Wallet(storage) self.wallet.start_threads(network) self.wallet.network.register_callback('updated', self.updated) self.wallet.network.register_callback('connected', self.connected) self.wallet.network.register_callback('disconnected', self.disconnected) self.wallet.network.register_callback('disconnecting', self.disconnecting) self.wallet.network.register_callback('peers', self.peers) self.wallet.network.register_callback('banner', self.print_banner) self.commands = [_("[h] - displays this help text"), \ _("[i] - display transaction history"), \ _("[o] - enter payment order"), \ _("[p] - print stored payment order"), \ _("[s] - send stored payment order"), \ _("[r] - show own receipt addresses"), \ _("[c] - display contacts"), \ _("[b] - print server banner"), \ _("[q] - quit") ] self.num_commands = len(self.commands)
def __init__(self, config, daemon, plugins): self.config = config self.network = daemon.network storage = WalletStorage(config.get_wallet_path()) if not storage.file_exists: print("Wallet not found. try 'pkpay create'") exit() if storage.is_encrypted(): password = getpass.getpass('Password:'******'wallet_updated', 'network_updated', 'banner']) self.commands = [_("[h] - displays this help text"), _("[i] - display transaction history"), _("[o] - enter payment order"), _("[p] - print stored payment order"), _("[s] - send stored payment order"), _("[r] - show own receipt addresses"), _("[c] - display contacts"), _("[b] - print server banner"), _("[q] - quit")] self.num_commands = len(self.commands)
def run(self): action = self.restore_or_create() if not action: exit() wallet = Wallet(self.storage) if action == 'create': wallet.init_seed(None) self.show_seed(wallet) if self.verify_seed(wallet): wallet.save_seed() wallet.create_accounts() # generate first addresses offline wallet.synchronize() else: return elif action == 'restore': # ask for seed and gap. sg = self.seed_dialog() if not sg: return seed, gap = sg if not seed: return wallet.gap_limit = gap wallet.init_seed(str(seed)) wallet.save_seed() elif action == 'watching': # ask for seed and gap. sg = self.mpk_dialog() if not sg: return mpk, gap = sg if not mpk: return wallet.gap_limit = gap wallet.seed = '' print eval(mpk) try: c0, K0 = eval(mpk) except: QMessageBox.warning(None, _('Error'), _('error'), _('OK')) return wallet.create_watching_only_wallet(c0, K0) else: raise #if not self.config.get('server'): self.network_dialog() # start wallet threads wallet.start_threads(self.network) if action == 'restore': try: keep_it = self.restore_wallet(wallet) wallet.fill_addressbook() except: import traceback traceback.print_exc(file=sys.stdout) exit() if not keep_it: return self.password_dialog(wallet) return wallet
def main(self, url): storage = WalletStorage(self.config) if storage.file_exists: wallet = Wallet(storage) action = wallet.get_action() else: action = 'new' if action is not None: import installwizard wizard = installwizard.InstallWizard(self.config, self.network, storage) wallet = wizard.run(action) if not wallet: return else: wallet.start_threads(self.network) # init tray if 1: self.dark_icon = self.config.get("dark_icon", False) icon = QIcon(":icons/electrum_dark_icon.png") if self.dark_icon else QIcon(':icons/electrum_light_icon.png') self.tray = QSystemTrayIcon(icon, None) self.tray.setToolTip('Reddcoin Electrum') self.tray.activated.connect(self.tray_activated) self.build_tray_menu() self.tray.show() else: self.tray = None # main window self.main_window = w = ElectrumWindow(self.config, self.network, self) self.current_window = self.main_window #lite window self.init_lite() # initial configuration if self.config.get('hide_gui') is True and self.tray.isVisible(): self.main_window.hide() self.lite_window.hide() else: if self.config.get('lite_mode') is True: self.go_lite() else: self.go_full() # plugins that need to change the GUI do it here run_hook('init_qt', self) w.load_wallet(wallet) s = Timer() s.start() self.windows.append(w) if url: self.set_url(url) w.app = self.app w.connect_slots(s) w.update_wallet() signal.signal(signal.SIGINT, lambda *args: self.app.quit()) self.app.exec_() if self.tray: self.tray.hide() # clipboard persistence # see http://www.mail-archive.com/[email protected]/msg17328.html event = QtCore.QEvent(QtCore.QEvent.Clipboard) self.app.sendEvent(self.app.clipboard(), event) w.close_wallet()
def main(self, url): last_wallet = self.config.get('gui_last_wallet') if last_wallet is not None and self.config.get('wallet_path') is None: if os.path.exists(last_wallet): self.config.cmdline_options[ 'default_wallet_path'] = last_wallet try: storage = WalletStorage(self.config.get_wallet_path()) except BaseException as e: QMessageBox.warning(None, _('Warning'), str(e), _('OK')) self.config.set_key('gui_last_wallet', None) return if storage.file_exists: try: wallet = Wallet(storage) except BaseException as e: QMessageBox.warning(None, _('Warning'), str(e), _('OK')) return action = wallet.get_action() else: action = 'new' if action is not None: wallet = self.run_wizard(storage, action) if not wallet: return else: wallet.start_threads(self.network) # init tray self.dark_icon = self.config.get("dark_icon", False) icon = QIcon( ":icons/electrum_dark_icon.png") if self.dark_icon else QIcon( ':icons/electrum_light_icon.png') self.tray = QSystemTrayIcon(icon, None) self.tray.setToolTip('Unobtainum Electrum') self.tray.activated.connect(self.tray_activated) self.build_tray_menu() self.tray.show() # main window self.main_window = w = ElectrumWindow(self.config, self.network, self) self.current_window = self.main_window #lite window self.init_lite() # plugins interact with main window run_hook('init_qt', self) w.load_wallet(wallet) # initial configuration if self.config.get('hide_gui') is True and self.tray.isVisible(): self.main_window.hide() self.lite_window.hide() else: if self.config.get('lite_mode') is True: self.go_lite() else: self.go_full() s = Timer() s.start() self.windows.append(w) if url: self.set_url(url) w.connect_slots(s) signal.signal(signal.SIGINT, lambda *args: self.app.quit()) self.app.exec_() if self.tray: self.tray.hide() # clipboard persistence # see http://www.mail-archive.com/[email protected]/msg17328.html event = QtCore.QEvent(QtCore.QEvent.Clipboard) self.app.sendEvent(self.app.clipboard(), event) w.close_wallet()
def run_and_get_wallet(self, get_wallet_from_daemon): vbox = QVBoxLayout() hbox = QHBoxLayout() hbox.addWidget(QLabel(_('Wallet') + ':')) self.name_e = QLineEdit() hbox.addWidget(self.name_e) button = QPushButton(_('Choose...')) hbox.addWidget(button) vbox.addLayout(hbox) self.msg_label = QLabel('') vbox.addWidget(self.msg_label) hbox2 = QHBoxLayout() self.pw_e = QLineEdit('', self) self.pw_e.setFixedWidth(150) self.pw_e.setEchoMode(2) self.pw_label = QLabel(_('Password') + ':') hbox2.addWidget(self.pw_label) hbox2.addWidget(self.pw_e) hbox2.addStretch() vbox.addLayout(hbox2) self.set_layout(vbox, title=_('Electrum wallet')) wallet_folder = os.path.dirname(self.storage.path) def on_choose(): path, __ = QFileDialog.getOpenFileName(self, "Select your wallet file", wallet_folder) if path: self.name_e.setText(path) def on_filename(filename): path = os.path.join(wallet_folder, filename) wallet_from_memory = get_wallet_from_daemon(path) try: if wallet_from_memory: self.storage = wallet_from_memory.storage else: self.storage = WalletStorage(path, manual_upgrades=True) self.next_button.setEnabled(True) except BaseException: traceback.print_exc(file=sys.stderr) self.storage = None self.next_button.setEnabled(False) if self.storage: if not self.storage.file_exists(): msg =_("This file does not exist.") + '\n' \ + _("Press 'Next' to create this wallet, or choose another file.") pw = False elif not wallet_from_memory: if self.storage.is_encrypted_with_user_pw(): msg = _("This file is encrypted with a password.") + '\n' \ + _('Enter your password or choose another file.') pw = True elif self.storage.is_encrypted_with_hw_device(): msg = _("This file is encrypted using a hardware device.") + '\n' \ + _("Press 'Next' to choose device to decrypt.") pw = False else: msg = _("Press 'Next' to open this wallet.") pw = False else: msg = _("This file is already open in memory.") + "\n" \ + _("Press 'Next' to create/focus window.") pw = False else: msg = _('Cannot read file') pw = False self.msg_label.setText(msg) if pw: self.pw_label.show() self.pw_e.show() self.pw_e.setFocus() else: self.pw_label.hide() self.pw_e.hide() button.clicked.connect(on_choose) self.name_e.textChanged.connect(on_filename) n = os.path.basename(self.storage.path) self.name_e.setText(n) while True: if self.storage.file_exists() and not self.storage.is_encrypted(): break if self.loop.exec_() != 2: # 2 = next return if not self.storage.file_exists(): break wallet_from_memory = get_wallet_from_daemon(self.storage.path) if wallet_from_memory: return wallet_from_memory if self.storage.file_exists() and self.storage.is_encrypted(): if self.storage.is_encrypted_with_user_pw(): password = self.pw_e.text() try: self.storage.decrypt(password) break except InvalidPassword as e: QMessageBox.information(None, _('Error'), str(e)) continue except BaseException as e: traceback.print_exc(file=sys.stdout) QMessageBox.information(None, _('Error'), str(e)) return elif self.storage.is_encrypted_with_hw_device(): try: self.run('choose_hw_device', HWD_SETUP_DECRYPT_WALLET) except InvalidPassword as e: QMessageBox.information( None, _('Error'), _('Failed to decrypt using this hardware device.') + '\n' + _('If you use a passphrase, make sure it is correct.' )) self.stack = [] return self.run_and_get_wallet(get_wallet_from_daemon) except BaseException as e: traceback.print_exc(file=sys.stdout) QMessageBox.information(None, _('Error'), str(e)) return if self.storage.is_past_initial_decryption(): break else: return else: raise Exception('Unexpected encryption version') path = self.storage.path if self.storage.requires_split(): self.hide() msg = _( "The wallet '{}' contains multiple accounts, which are no longer supported since Electrum 2.7.\n\n" "Do you want to split your wallet into multiple files?" ).format(path) if not self.question(msg): return file_list = '\n'.join(self.storage.split_accounts()) msg = _('Your accounts have been moved to' ) + ':\n' + file_list + '\n\n' + _( 'Do you want to delete the old file') + ':\n' + path if self.question(msg): os.remove(path) self.show_warning(_('The file was removed')) return if self.storage.requires_upgrade(): self.storage.upgrade() self.wallet = Wallet(self.storage) return self.wallet action = self.storage.get_action() if action and action != 'new': self.hide() msg = _("The file '{}' contains an incompletely created wallet.\n" "Do you want to complete its creation now?").format(path) if not self.question(msg): if self.question( _("Do you want to delete '{}'?").format(path)): os.remove(path) self.show_warning(_('The file was removed')) return self.show() if action: # self.wallet is set in run self.run(action) return self.wallet self.wallet = Wallet(self.storage) return self.wallet
def run(self, action): if action == 'new': action, t = self.restore_or_create() if action is None: return if action == 'create': if t == 'standard': wallet = Wallet(self.storage) elif t == '2fa': wallet = Wallet_2of3(self.storage) run_hook('create_cold_seed', wallet, self) self.create_cold_seed(wallet) return elif t == '2of2': wallet = Wallet_2of2(self.storage) action = 'create_2of2_1' elif t == '2of3': wallet = Wallet_2of3(self.storage) action = 'create_2of3_1' if action in ['create_2fa_2', 'create_2of3_2']: wallet = Wallet_2of3(self.storage) if action in ['create', 'create_2of2_1', 'create_2fa_2', 'create_2of3_1']: seed = wallet.make_seed() sid = None if action == 'create' else 'hot' if not self.show_seed(seed, sid): return if not self.verify_seed(seed, sid): return password = self.password_dialog() wallet.add_seed(seed, password) if action == 'create': wallet.create_accounts(password) self.waiting_dialog(wallet.synchronize) elif action == 'create_2of2_1': action = 'create_2of2_2' elif action == 'create_2of3_1': action = 'create_2of3_2' elif action == 'create_2fa_2': action = 'create_2fa_3' if action == 'create_2of2_2': xpub_hot = wallet.master_public_keys.get("m/") xpub = self.multi_mpk_dialog(xpub_hot, 1) if not xpub: return wallet.add_master_public_key("cold/", xpub) wallet.create_account() self.waiting_dialog(wallet.synchronize) if action == 'create_2of3_2': xpub_hot = wallet.master_public_keys.get("m/") r = self.multi_mpk_dialog(xpub_hot, 2) if not r: return xpub1, xpub2 = r wallet.add_master_public_key("cold/", xpub1) wallet.add_master_public_key("remote/", xpub2) wallet.create_account() self.waiting_dialog(wallet.synchronize) if action == 'create_2fa_3': run_hook('create_remote_key', wallet, self) if not wallet.master_public_keys.get("remote/"): return wallet.create_account() self.waiting_dialog(wallet.synchronize) if action == 'restore': if t == 'standard': text = self.enter_seed_dialog(MSG_ENTER_ANYTHING, None) if not text: return if Wallet.is_seed(text): password = self.password_dialog() wallet = Wallet.from_seed(text, self.storage) wallet.add_seed(text, password) wallet.create_accounts(password) elif Wallet.is_mpk(text): wallet = Wallet.from_mpk(text, self.storage) elif Wallet.is_address(text): wallet = Wallet.from_address(text, self.storage) elif Wallet.is_private_key(text): wallet = Wallet.from_private_key(text, self.storage) else: raise elif t in ['2fa', '2of2']: r = self.multi_seed_dialog(1) if not r: return text1, text2 = r password = self.password_dialog() if t == '2of2': wallet = Wallet_2of2(self.storage) elif t == '2of3': wallet = Wallet_2of3(self.storage) elif t == '2fa': wallet = Wallet_2of3(self.storage) if Wallet.is_seed(text1): wallet.add_seed(text1, password) if Wallet.is_seed(text2): wallet.add_cold_seed(text2, password) else: wallet.add_master_public_key("cold/", text2) elif Wallet.is_mpk(text1): if Wallet.is_seed(text2): wallet.add_seed(text2, password) wallet.add_master_public_key("cold/", text1) else: wallet.add_master_public_key("m/", text1) wallet.add_master_public_key("cold/", text2) if t == '2fa': run_hook('restore_third_key', wallet, self) wallet.create_account() elif t in ['2of3']: r = self.multi_seed_dialog(2) if not r: return text1, text2, text3 = r password = self.password_dialog() wallet = Wallet_2of3(self.storage) if Wallet.is_seed(text1): wallet.add_seed(text1, password) if Wallet.is_seed(text2): wallet.add_cold_seed(text2, password) else: wallet.add_master_public_key("cold/", text2) elif Wallet.is_mpk(text1): if Wallet.is_seed(text2): wallet.add_seed(text2, password) wallet.add_master_public_key("cold/", text1) else: wallet.add_master_public_key("m/", text1) wallet.add_master_public_key("cold/", text2) wallet.create_account() else: raise #if not self.config.get('server'): if self.network: if self.network.interfaces: self.network_dialog() else: QMessageBox.information(None, _('Warning'), _('You are offline'), _('OK')) self.network.stop() self.network = None # start wallet threads wallet.start_threads(self.network) if action == 'restore': self.waiting_dialog(lambda: wallet.restore(self.waiting_label.setText)) if self.network: if wallet.is_found(): QMessageBox.information(None, _('Information'), _("Recovery successful"), _('OK')) else: QMessageBox.information(None, _('Information'), _("No transactions found for this seed"), _('OK')) else: QMessageBox.information(None, _('Information'), _("This wallet was restored offline. It may contain more addresses than displayed."), _('OK')) return wallet
def run_wallet_type(self, action, wallet_type): if action in ['create', 'restore']: if wallet_type == 'multisig': wallet_type = self.multisig_choice() if not wallet_type: return elif wallet_type == 'hardware': hardware_wallets = [] for item in electrum.wallet.wallet_types: t, name, description, loader = item if t == 'hardware': try: p = loader() except: util.print_error("cannot load plugin for:", name) continue if p: hardware_wallets.append((name, description)) wallet_type = self.choice(_("Hardware Wallet"), 'Select your hardware wallet', hardware_wallets) if not wallet_type: return elif wallet_type == 'twofactor': wallet_type = '2fa' if action == 'create': self.storage.put('wallet_type', wallet_type, False) if action is None: return if action == 'restore': wallet = self.restore(wallet_type) if not wallet: return action = None else: wallet = Wallet(self.storage) action = wallet.get_action() # fixme: password is only needed for multiple accounts password = None # load wallet in plugins always_hook('installwizard_load_wallet', wallet, self) while action is not None: util.print_error("installwizard:", wallet, action) if action == 'create_seed': lang = self.config.get('language') seed = wallet.make_seed(lang) if not self.show_seed(seed, None): return if not self.verify_seed(seed, None): return password = self.password_dialog() wallet.add_seed(seed, password) wallet.create_master_keys(password) elif action == 'add_cosigners': n = int(re.match('(\d+)of(\d+)', wallet.wallet_type).group(2)) xpub1 = wallet.master_public_keys.get("x1/") r = self.multi_mpk_dialog(xpub1, n - 1) if not r: return for i, xpub in enumerate(r): wallet.add_master_public_key("x%d/" % (i + 2), xpub) elif action == 'create_accounts': wallet.create_main_account(password) self.waiting_dialog(wallet.synchronize) else: f = always_hook('get_wizard_action', self, wallet, action) if not f: raise BaseException('unknown wizard action', action) r = f(wallet, self) if not r: return # next action action = wallet.get_action() if self.network: if self.network.interfaces: self.network_dialog() else: QMessageBox.information(None, _('Warning'), _('You are offline'), _('OK')) self.network.stop() self.network = None # start wallet threads wallet.start_threads(self.network) if action == 'restore': self.waiting_dialog( lambda: wallet.restore(self.waiting_label.setText)) if self.network: msg = _("Recovery successful") if wallet.is_found() else _( "No transactions found for this seed") else: msg = _( "This wallet was restored offline. It may contain more addresses than displayed." ) QMessageBox.information(None, _('Information'), msg, _('OK')) return wallet
def run_and_get_wallet(self): vbox = QVBoxLayout() hbox = QHBoxLayout() hbox.addWidget(QLabel(_('Wallet') + ':')) self.name_e = QLineEdit() hbox.addWidget(self.name_e) button = QPushButton(_('Choose...')) hbox.addWidget(button) vbox.addLayout(hbox) self.msg_label = QLabel('') vbox.addWidget(self.msg_label) hbox2 = QHBoxLayout() self.pw_e = QLineEdit('', self) self.pw_e.setFixedWidth(150) self.pw_e.setEchoMode(2) self.pw_label = QLabel(_('Password') + ':') hbox2.addWidget(self.pw_label) hbox2.addWidget(self.pw_e) hbox2.addStretch() vbox.addLayout(hbox2) self.set_layout(vbox, title=_('Electrum wallet')) wallet_folder = os.path.dirname(self.storage.path) def on_choose(): path = unicode( QFileDialog.getOpenFileName(self, "Select your wallet file", wallet_folder)) if path: self.name_e.setText(path) def on_filename(filename): filename = unicode(filename) path = os.path.join(wallet_folder, filename.encode('utf8')) try: self.storage = WalletStorage(path) except IOError: self.storage = None if self.storage: if not self.storage.file_exists(): msg =_("This file does not exist.") + '\n' \ + _("Press 'Next' to create this wallet, or choose another file.") pw = False elif self.storage.file_exists() and self.storage.is_encrypted( ): msg = _("This file is encrypted.") + '\n' + _( 'Enter your password or choose another file.') pw = True else: msg = _("Press 'Next' to open this wallet.") pw = False else: msg = _('Cannot read file') pw = False self.msg_label.setText(msg) if pw: self.pw_label.show() self.pw_e.show() self.pw_e.setFocus() else: self.pw_label.hide() self.pw_e.hide() button.clicked.connect(on_choose) self.name_e.textChanged.connect(on_filename) n = os.path.basename(self.storage.path) self.name_e.setText(n.decode('utf8')) while True: if self.storage.file_exists() and not self.storage.is_encrypted(): break if self.loop.exec_() != 2: # 2 = next return if not self.storage.file_exists(): break if self.storage.file_exists() and self.storage.is_encrypted(): password = unicode(self.pw_e.text()) try: self.storage.decrypt(password) break except InvalidPassword as e: QMessageBox.information(None, _('Error'), str(e), _('OK')) continue except BaseException as e: traceback.print_exc(file=sys.stdout) QMessageBox.information(None, _('Error'), str(e), _('OK')) return path = self.storage.path if self.storage.requires_split(): self.hide() msg = _( "The wallet '%s' contains multiple accounts, which are no longer supported in Electrum 2.7.\n\n" "Do you want to split your wallet into multiple files?" % path) if not self.question(msg): return file_list = '\n'.join(self.storage.split_accounts()) msg = _('Your accounts have been moved to' ) + ':\n' + file_list + '\n\n' + _( 'Do you want to delete the old file') + ':\n' + path if self.question(msg): os.remove(path) self.show_warning(_('The file was removed')) return if self.storage.requires_upgrade(): self.hide() msg = _( "The format of your wallet '%s' must be upgraded for Electrum. This change will not be backward compatible" % path) if not self.question(msg): return self.storage.upgrade() self.show_warning(_('Your wallet was upgraded successfully')) self.wallet = Wallet(self.storage) return self.wallet action = self.storage.get_action() if action and action != 'new': self.hide() msg = _("The file '%s' contains an incompletely created wallet.\n" "Do you want to complete its creation now?") % path if not self.question(msg): if self.question(_("Do you want to delete '%s'?") % path): os.remove(path) self.show_warning(_('The file was removed')) return self.show() if action: # self.wallet is set in run self.run(action) return self.wallet self.wallet = Wallet(self.storage) return self.wallet