Example #1
0
    def add_chain_dialog(self):
        d = QDialog(self)
        d.setModal(1)
        d.setWindowTitle(_("Add Currency To Wallet"))

        pw = QLineEdit()
        pw.setEchoMode(2)

        vbox = QVBoxLayout()
        msg = _('Please enter your password to start using this currency')
        vbox.addWidget(QLabel(msg))

        grid = QGridLayout()
        grid.setSpacing(8)
        grid.addWidget(QLabel(_('Password')), 1, 0)
        grid.addWidget(pw, 1, 1)
        vbox.addLayout(grid)

        vbox.addLayout(ok_cancel_buttons(d))
        d.setLayout(vbox)

        always_hook('password_dialog', pw, grid, 1)
        if not d.exec_(): return
        return unicode(pw.text())
Example #2
0
    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):
                    wallet = Wallet.from_private_key(text, self.storage)
                elif Wallet.is_seed(text):
                    password = self.password_dialog()
                    wallet = Wallet.from_seed(text, self.storage)
                    wallet.add_seed(text, password)
                    wallet.create_master_keys(password)
                    wallet.create_main_account(password)
                else:
                    raise BaseException('unknown wallet type')

            elif t in ['2of2']:
                r = self.multi_seed_dialog(1)
                if not r:
                    return
                text1, text2 = r
                wallet = Wallet_2of2(self.storage)
                if Wallet.is_seed(text1) or Wallet.is_seed(text2):
                    password = self.password_dialog()
                else:
                    password = None

                if Wallet.is_seed(text2) and Wallet.is_xpub(text1):
                    c = text1
                    text1 = text2
                    text2 = c

                if Wallet.is_seed(text1):
                    wallet.add_seed(text1, password)
                    wallet.create_master_keys(password)
                else:
                    wallet.add_master_public_key("x1/", text1)

                if Wallet.is_seed(text2):
                    wallet.add_cosigner_seed(text2, "x2/", password)
                elif Wallet.is_xpub(text2):
                    wallet.add_master_public_key("x2/", text2)

                wallet.create_main_account(password)


            elif t in ['2of3']:
                r = self.multi_seed_dialog(2)
                if not r:
                    return
                text1, text2, text3 = r
                wallet = Wallet_2of3(self.storage)
                if Wallet.is_seed(text1) or Wallet.is_seed(text2) or Wallet.is_seed(text3):
                    password = self.password_dialog()
                else:
                    password = None

                if Wallet.is_xpub(text1) and Wallet.is_seed(text2):
                    temp = text1
                    text1 = text2
                    text2 = temp

                if Wallet.is_xpub(text1) and Wallet.is_seed(text3):
                    temp = text1
                    text1 = text3
                    text3 = temp

                if Wallet.is_seed(text1):
                    wallet.add_seed(text1, password)
                    wallet.create_master_keys(password)
                else:
                    wallet.add_master_public_key("x1/", text1)

                if Wallet.is_seed(text2):
                    wallet.add_cosigner_seed(text2, "x2/", password)
                elif Wallet.is_xpub(text2):
                    wallet.add_master_public_key("x2/", text2)

                if Wallet.is_seed(text3):
                    wallet.add_cosigner_seed(text3, "x3/", password)
                elif Wallet.is_xpub(text3):
                    wallet.add_master_public_key("x3/", text3)

                wallet.create_main_account(password)

            else:
                self.storage.put_above_chain('wallet_type', t)
                wallet = always_hook('installwizard_restore', self, self.storage)
                if not wallet:
                    return

            # create first keys offline
            self.waiting_dialog(wallet.synchronize)

            return wallet
Example #3
0
    def run(self, action):

        if action == 'new':
            action, wallet_type = self.restore_or_create()
            if wallet_type == 'multisig':
                wallet_type = self.choice(_("Multi Signature Wallet"), 'Select wallet type', [('2of2', _("2 of 2")),('2of3',_("2 of 3")),('mofn',_("M of N"))])
                if not wallet_type:
                    return
            elif wallet_type == 'hardware':
                hardware_wallets = map(lambda x:(x[1],x[2]), filter(lambda x:x[0]=='hardware', chainkey.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_above_chain('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':
                seed = wallet.make_seed()
                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_chain':
                if wallet.use_encryption == True:
                    password = self.add_chain_dialog()
                    # workaround pw_decode returning seed if no password is given
                    if password is None:
                        password = '******'
                else:
                    password = None
                try:
                    wallet.create_master_keys(password)
                except Exception:
                    QMessageBox.warning(self, _('Error'), ('Password is incorrect'), _('OK'))
                    return

            elif action == 'add_m_and_n':
                m, n = run_select_mn_dialog()
                if not m or not n:
                    return
                wallet.set_m_and_n(m, n)

            elif action == 'add_cosigner':
                xpub1 = wallet.master_public_keys.get("x1/")
                r = self.multi_mpk_dialog(xpub1, 1)
                if not r:
                    return
                xpub2 = r[0]
                wallet.add_master_public_key("x2/", xpub2)

            elif action == 'add_two_cosigners':
                xpub1 = wallet.master_public_keys.get("x1/")
                r = self.multi_mpk_dialog(xpub1, 2)
                if not r:
                    return
                xpub2, xpub3 = r
                wallet.add_master_public_key("x2/", xpub2)
                wallet.add_master_public_key("x3/", xpub3)

            elif 'add_x_cosigners' in action:
                xpub1 = wallet.master_public_keys.get("x1/")
                cosigners_num = action.split(':')[-1]
                r = self.multi_mpk_dialog(xpub1, int(cosigners_num))
                if not r:
                    return
                for i, xpub in enumerate(r):
                    wallet.add_master_public_key( "x{}/".format(i + 2), xpub )

            elif action == 'create_accounts':
                try:
                    wallet.create_main_account(password)
                except BaseException as e:
                    import traceback
                    traceback.print_exc(file=sys.stdout)
                    QMessageBox.information(None, _('Error'), str(e), _('OK'))
                    return
                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()
                # start wallet threads
                wallet.start_threads(self.network)
            else:
                QMessageBox.information(None, _('Warning'), _('You are offline'), _('OK'))


        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