Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    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
Exemplo n.º 3
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)
Exemplo n.º 4
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
Exemplo n.º 5
0
    def run(self):

        action = self.restore_or_create()
        if not action: exit()

        wallet = Wallet(self.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':
            wallet.init_seed(None)
            self.show_seed(wallet)
            if self.verify_seed(wallet):
                def create():
                    wallet.save_seed()
                    wallet.create_accounts()
                    wallet.synchronize()  # generate first addresses offline
                self.waiting_dialog(create)
            else:
                return
                
        elif action == 'restore':
            # ask for seed and gap.
            seed = self.seed_dialog()
            if not seed:
                return
            try:
                wallet.init_seed(seed)
            except:
                import traceback
                traceback.print_exc(file=sys.stdout)
                QMessageBox.warning(None, _('Error'), _('Incorrect seed'), _('OK'))
                return

            wallet.save_seed()

        elif action == 'watching':
            # ask for seed and gap.
            mpk = self.mpk_dialog()
            if not mpk:
                return
            wallet.seed = ''
            wallet.create_watching_only_wallet(mpk)


        else: raise
                
        #if not self.config.get('server'):
        if self.network:
            self.network_dialog()

        # 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'))

        self.password_dialog(wallet)

        return wallet
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
0
    def run(self):

        action = self.restore_or_create()
        if not action:
            exit()

        wallet = Wallet(self.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":
            wallet.init_seed(None)
            self.show_seed(wallet)
            if self.verify_seed(wallet):

                def create():
                    wallet.save_seed()
                    wallet.create_accounts()
                    wallet.synchronize()  # generate first addresses offline

                self.waiting_dialog(create)
            else:
                return

        elif action == "restore":
            # ask for seed and gap.
            seed = self.seed_dialog()
            if not seed:
                return
            wallet.init_seed(str(seed))
            wallet.save_seed()

        elif action == "watching":
            # ask for seed and gap.
            mpk = self.mpk_dialog()
            if not mpk:
                return
            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":

            def wait_for_wallet():
                wallet.set_up_to_date(False)
                while not wallet.is_up_to_date():
                    msg = "%s\n%s %d\n%s %.1f" % (
                        _("Please wait..."),
                        _("Addresses generated:"),
                        len(wallet.addresses(True)),
                        _("Kilobytes received:"),
                        self.network.interface.bytes_received / 1024.0,
                    )
                    self.waiting_label.setText(msg)
                    time.sleep(0.1)

            def wait_for_network():
                while not self.network.interface.is_connected:
                    msg = "%s \n" % (_("Connecting..."))
                    self.waiting_label.setText(msg)
                    time.sleep(0.1)

            def restore():
                # wait until we are connected, because the user might have selected another server
                wait_for_network()

                # try to restore old account
                wallet.create_old_account()
                wait_for_wallet()

                if wallet.is_found():
                    wallet.seed_version = 4
                    wallet.storage.put("seed_version", wallet.seed_version, True)
                else:
                    wallet.accounts.pop(0)
                    wallet.create_accounts()
                    wait_for_wallet()

            self.waiting_dialog(restore)

            if wallet.is_found():
                QMessageBox.information(None, _("Information"), _("Recovery successful"), _("OK"))
            else:
                QMessageBox.information(None, _("Information"), _("No transactions found for this seed"), _("OK"))

            wallet.fill_addressbook()

        self.password_dialog(wallet)

        return wallet
Exemplo n.º 9
0
    def run(self):

        action = self.restore_or_create()
        if not action: exit()

        wallet = Wallet(self.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':
            wallet.init_seed(None)
            self.show_seed(wallet)
            if self.verify_seed(wallet):
                def create():
                    wallet.save_seed()
                    wallet.create_accounts()
                    wallet.synchronize()  # generate first addresses offline
                self.waiting_dialog(create)
            else:
                return
                
        elif action == 'restore':
            # ask for seed and gap.
            seed = self.seed_dialog()
            if not seed:
                return
            wallet.init_seed(str(seed))
            wallet.save_seed()

        elif action == 'watching':
            # ask for seed and gap.
            K, chain = self.mpk_dialog()
            if not K or not chain:
                return
            wallet.seed = ''
            wallet.create_watching_only_wallet(chain,K)


        else: raise
                
        #if not self.config.get('server'):
        self.network_dialog()

        # start wallet threads
        wallet.start_threads(self.network)

        if action == 'restore':

            self.waiting_dialog(lambda: wallet.restore(self.waiting_label.setText))

            if wallet.is_found():
                QMessageBox.information(None, _('Information'), _("Recovery successful"), _('OK'))
            else:
                QMessageBox.information(None, _('Information'), _("No transactions found for this seed"), _('OK'))
            
            wallet.fill_addressbook()

        self.password_dialog(wallet)

        return wallet
Exemplo n.º 10
0
    def run(self):

        action = self.restore_or_create()
        if not action: 
            return

        #gap = self.config.get('gap_limit', 5)
        #if gap != 5:
        #    wallet.gap_limit = gap
        #    wallet.storage.put('gap_limit', gap, True)

        if action == 'create':
            wallet = Wallet(self.storage)
            wallet.init_seed(None)
            if not self.show_seed(wallet):
                return
            if not self.verify_seed(wallet):
                return
            ok, old_password, password = self.password_dialog(wallet)
            def create():
                wallet.save_seed(password)
                wallet.synchronize()  # generate first addresses offline
            self.waiting_dialog(create)

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

        elif action == 'watching':
            mpk = self.mpk_dialog()
            if not mpk:
                return
            wallet.seed = ''
            wallet.create_watching_only_wallet(mpk)

        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
Exemplo n.º 11
0
    def run(self):

        action = self.restore_or_create()
        if not action: exit()

        wallet = Wallet(self.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':
            wallet.init_seed(None)
            self.show_seed(wallet)
            if self.verify_seed(wallet):

                def create():
                    wallet.save_seed()
                    wallet.create_accounts()
                    wallet.synchronize()  # generate first addresses offline

                self.waiting_dialog(create)
            else:
                return

        elif action == 'restore':
            # ask for seed and gap.
            seed = self.seed_dialog()
            if not seed:
                return
            try:
                wallet.init_seed(seed)
            except:
                import traceback
                traceback.print_exc(file=sys.stdout)
                QMessageBox.warning(None, _('Error'), _('Incorrect seed'),
                                    _('OK'))
                return

            wallet.save_seed()

        elif action == 'watching':
            # ask for seed and gap.
            mpk = self.mpk_dialog()
            if not mpk:
                return
            wallet.seed = ''
            wallet.create_watching_only_wallet(mpk)

        else:
            raise

        #if not self.config.get('server'):
        if self.network:
            self.network_dialog()

        # 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'))

        self.password_dialog(wallet)

        return wallet