def multi_mpk_dialog(self, xpub_hot, n): vbox = QVBoxLayout() scroll = QScrollArea() scroll.setEnabled(True) scroll.setWidgetResizable(True) vbox.addWidget(scroll) w = QWidget() scroll.setWidget(w) innerVbox = QVBoxLayout() w.setLayout(innerVbox) vbox0 = seed_dialog.show_seed_box(MSG_SHOW_MPK, xpub_hot, 'hot') innerVbox.addLayout(vbox0) entries = [] for i in range(n): msg = _("Please enter the master public key of cosigner") + ' %d'%(i+1) vbox2, seed_e2 = seed_dialog.enter_seed_box(msg, self, 'cold') innerVbox.addLayout(vbox2) entries.append(seed_e2) vbox.addStretch(1) button = OkButton(self, _('Next')) vbox.addLayout(Buttons(CancelButton(self), button)) button.setEnabled(False) f = lambda: button.setEnabled( map(lambda e: Wallet.is_xpub(self.get_seed_text(e)), entries) == [True]*len(entries)) for e in entries: e.textChanged.connect(f) self.set_layout(vbox) if not self.exec_(): return return map(lambda e: self.get_seed_text(e), entries)
def restore(self, t): if t == 'standard': text = self.enter_seed_dialog(MSG_ENTER_ANYTHING, None) if not text: return if Wallet.is_xprv(text): password = self.password_dialog() wallet = Wallet.from_xprv(text, password, self.storage) elif Wallet.is_old_mpk(text): wallet = Wallet.from_old_mpk(text, self.storage) elif Wallet.is_xpub(text): wallet = Wallet.from_xpub(text, self.storage) elif Wallet.is_address(text): wallet = Wallet.from_address(text, self.storage) elif Wallet.is_private_key(text): password = self.password_dialog() wallet = Wallet.from_private_key(text, password, self.storage) elif Wallet.is_seed(text): password = self.password_dialog() wallet = Wallet.from_seed(text, password, self.storage) else: raise BaseException('unknown wallet type') 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 run(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 = map(lambda x:(x[1],x[2]), filter(lambda x:x[0]=='hardware', electrum.wallet.wallet_types)) 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 is_mpk(self, text): return Wallet.is_xpub(text) or Wallet.is_old_mpk(text)
def is_any(self, text): return Wallet.is_seed(text) or Wallet.is_old_mpk(text) or Wallet.is_xpub(text) or Wallet.is_xprv(text) or Wallet.is_address(text) or Wallet.is_private_key(text)
def __init__(self): global wallet self.qr_data = None storage = WalletStorage('/sdcard/electrum-XSH/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, password, storage) else: exit() wallet.add_seed(seed, password) wallet.create_master_keys(password) wallet.create_main_account(password) else: wallet = Wallet(storage)
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('Electrum-XSH') 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()