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-GMC", 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)
Ejemplo n.º 2
0
    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-GMC", 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)
Ejemplo n.º 3
0
    def __init__(self):
        global wallet
        self.qr_data = None
        storage = WalletStorage('/sdcard/electrum-gmc/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 on_release(wallet, seed, _dlg, _btn):
            ti_password = _dlg.ids.ti_password
            ti_new_password = _dlg.ids.ti_new_password
            ti_confirm_password = _dlg.ids.ti_confirm_password
            if _btn != _dlg.ids.next:
                if mode == 'restore':
                    # back is disabled cause seed is already set
                    return
                _dlg.close()
                if not instance:
                    # back on create
                    Factory.CreateRestoreDialog(
                        on_release=self.on_creatrestore_complete).open()
                return

            # Confirm
            wallet_name = _dlg.ids.ti_wallet_name.text
            new_password = unicode(ti_new_password.text)
            new_password2 = unicode(ti_confirm_password.text)

            if new_password != new_password2:
                # passwords don't match
                ti_password.text = ""
                ti_new_password.text = ""
                ti_confirm_password.text = ""
                if ti_password.disabled:
                    ti_new_password.focus = True
                else:
                    ti_password.focus = True
                return app.show_error(_('Passwords do not match'), duration=.5)

            if not new_password:
                new_password = None

            if mode == 'restore':
                wallet = Wallet.from_seed(seed, self.storage)
                password = (unicode(ti_password.text)
                            if wallet and wallet.use_encryption else
                            None)

                def on_complete(*l):
                    wallet.create_accounts(new_password)
                    self.load_network(wallet, mode='restore')
                    _dlg.close()

                self.waiting_dialog(lambda: wallet.add_seed(seed, new_password),
                                    msg=_("saving seed"),
                                    on_complete=on_complete)
                return

            if not instance:
                # create mode
                _dlg.close()
                seed = wallet.make_seed()

                return self.show_seed(password=new_password, wallet=wallet,
                                      wallet_name=wallet_name, mode=mode,
                                      seed=seed)

            # change password mode
            try:
                seed = wallet.decode_seed(password)
            except BaseException:
                return app.show_error(_('Incorrect Password'), duration=.5)

            # test carefully
            try:
                wallet.update_password(seed, password, new_password)
            except BaseException:
                return app.show_error(_('Failed to update password'), exit=True)
            else:
                app.show_info_bubble(
                    text=_('Password successfully updated'), duration=1,
                    pos=_btn.pos)
            _dlg.close()

            if instance is None:  # in initial phase
                self.load_wallet()
            self.app.update_wallet()
Ejemplo n.º 5
0
        def on_release(wallet, seed, _dlg, _btn):
            ti_password = _dlg.ids.ti_password
            ti_new_password = _dlg.ids.ti_new_password
            ti_confirm_password = _dlg.ids.ti_confirm_password
            if _btn != _dlg.ids.next:
                if mode == 'restore':
                    # back is disabled cause seed is already set
                    return
                _dlg.close()
                if not instance:
                    # back on create
                    Factory.CreateRestoreDialog(
                        on_release=self.on_creatrestore_complete).open()
                return

            # Confirm
            wallet_name = _dlg.ids.ti_wallet_name.text
            new_password = unicode(ti_new_password.text)
            new_password2 = unicode(ti_confirm_password.text)

            if new_password != new_password2:
                # passwords don't match
                ti_password.text = ""
                ti_new_password.text = ""
                ti_confirm_password.text = ""
                if ti_password.disabled:
                    ti_new_password.focus = True
                else:
                    ti_password.focus = True
                return app.show_error(_('Passwords do not match'), duration=.5)

            if not new_password:
                new_password = None

            if mode == 'restore':
                wallet = Wallet.from_seed(seed, self.storage)
                password = (unicode(ti_password.text)
                            if wallet and wallet.use_encryption else None)

                def on_complete(*l):
                    wallet.create_accounts(new_password)
                    self.load_network(wallet, mode='restore')
                    _dlg.close()

                self.waiting_dialog(
                    lambda: wallet.add_seed(seed, new_password),
                    msg=_("saving seed"),
                    on_complete=on_complete)
                return

            if not instance:
                # create mode
                _dlg.close()
                seed = wallet.make_seed()

                return self.show_seed(password=new_password,
                                      wallet=wallet,
                                      wallet_name=wallet_name,
                                      mode=mode,
                                      seed=seed)

            # change password mode
            try:
                seed = wallet.decode_seed(password)
            except BaseException:
                return app.show_error(_('Incorrect Password'), duration=.5)

            # test carefully
            try:
                wallet.update_password(seed, password, new_password)
            except BaseException:
                return app.show_error(_('Failed to update password'),
                                      exit=True)
            else:
                app.show_info_bubble(text=_('Password successfully updated'),
                                     duration=1,
                                     pos=_btn.pos)
            _dlg.close()

            if instance is None:  # in initial phase
                self.load_wallet()
            self.app.update_wallet()