Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    def run(self, action = None):

        if action is None:
            action = self.restore_or_create()

        if action is None: 
            return

        if action == 'create':            
            t = self.choose_wallet_type()
            if t == '2of3':
                run_hook('create_cold_seed', self.storage, self)
                return


        if action in ['create', 'create2of3']:

            wallet = Wallet(self.storage)

            wallet.init_seed(None)
            seed = wallet.get_mnemonic(None)
            if not self.show_seed(seed, 'hot' if action == 'create2of3' else None):
                return
            if not self.verify_seed(seed):
                return
            ok, old_password, password = self.password_dialog(wallet)
            wallet.save_seed(password)

            if action == 'create2of3':
                run_hook('create_hot_seed', wallet, self)

            wallet.create_accounts(password)
            def create():
                wallet.synchronize()  # generate first addresses offline
            self.waiting_dialog(create)

        elif action == 'restore':
            seed = self.seed_dialog()
            if not Wallet.is_seed(seed):
                return
            wallet = Wallet.from_seed(seed, self.storage)
            ok, old_password, password = self.password_dialog(wallet)
            wallet.save_seed(password)
            wallet.create_accounts(password)

        elif action == 'watching':
            mpk = self.mpk_dialog()
            if not mpk:
                return
            wallet = Wallet.from_mpk(mpk, self.storage)

        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
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    def run(self, action):

        if action == 'new':
            action, wallet_type = self.restore_or_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

        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)

            elif action == 'add_cosigner':
                xpub_hot = wallet.master_public_keys.get("m/")
                r = self.multi_mpk_dialog(xpub_hot, 1)
                if not r:
                    return
                xpub_cold = r[0]
                wallet.add_master_public_key("cold/", xpub_cold)

            elif action == 'add_two_cosigners':
                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)

            elif action == 'create_accounts':
                wallet.create_accounts(password)
                self.waiting_dialog(wallet.synchronize)

            elif action == 'create_cold_seed':
                self.create_cold_seed(wallet)
                return

            else:
                 r = run_hook('install_wizard_action', self, wallet, action)
                 if not r: 
                     raise BaseException('unknown wizard action', action)

            # 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:
                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