예제 #1
0
 def load_theme(self):
     """Load theme retrieved from wallet file."""
     try:
         theme_prefix, theme_path = self.themes[self.theme_name]
     except KeyError:
         util.print_error("Theme not found!", self.theme_name)
         return
     full_theme_path = "%s/%s/style.css" % (theme_prefix, theme_path)
     with open(full_theme_path) as style_file:
         qApp.setStyleSheet(style_file.read())
예제 #2
0
 def load_theme(self):
     """Load theme retrieved from wallet file."""
     try:
         theme_prefix, theme_path = self.themes[self.theme_name]
     except KeyError:
         util.print_error("Theme not found!", self.theme_name)
         return
     full_theme_path = "%s/%s/style.css" % (theme_prefix, theme_path)
     with open(full_theme_path) as style_file:
         qApp.setStyleSheet(style_file.read())
예제 #3
0
 def run(self):
     self.is_running = True
     while self.is_running:
         if not self.keyhash:
             time.sleep(2)
             continue
         if not self.message:
             try:
                 self.message = server.get(self.keyhash)
             except Exception as e:
                 util.print_error("cannot contact cosigner pool")
                 time.sleep(30)
                 continue
             if self.message:
                 self.parent.win.emit(SIGNAL("cosigner:receive"))
         # poll every 30 seconds
         time.sleep(30)
예제 #4
0
 def run(self):
     self.is_running = True
     while self.is_running:
         if not self.keyhash:
             time.sleep(2)
             continue
         if not self.message:
             try:
                 self.message = server.get(self.keyhash)
             except Exception as e:
                 util.print_error("cannot contact cosigner pool")
                 time.sleep(30)
                 continue
             if self.message:
                 self.parent.win.emit(SIGNAL("cosigner:receive"))
         # poll every 30 seconds
         time.sleep(30)
예제 #5
0
    def set_label(self, item,label, changed):
        if self.encode_password is None:
            return
        if not changed:
            return 
        try:
            bundle = {"label": {"external_id": self.encode(item), "text": self.encode(label)}}
            params = json.dumps(bundle)
            connection = httplib.HTTPConnection(self.target_host)
            connection.request("POST", ("/api/wallets/%s/labels.json?auth_token=%s" % (self.wallet_id, self.auth_token())), params, {'Content-Type': 'application/json'})

            response = connection.getresponse()
            if response.reason == httplib.responses[httplib.NOT_FOUND]:
                return
            response = json.loads(response.read())
        except socket.gaierror as e:
            print_error('Error connecting to service: %s ' %  e)
            return False
예제 #6
0
    def do_full_pull(self, force = False):
        connection = httplib.HTTPConnection(self.target_host)
        connection.request("GET", ("/api/wallets/%s/labels.json?auth_token=%s" % (self.wallet_id, self.auth_token())),"", {'Content-Type': 'application/json'})
        response = connection.getresponse()
        if response.status != 200:
            print_error("Cannot retrieve labels:", response.status, response.reason)
            return
        response = json.loads(response.read())
        if "error" in response:
            raise BaseException(_("Could not sync labels: %s" % response["error"]))

        for label in response:
            try:
                key = self.decode(label["external_id"])
            except:
                continue
            try:
                value = self.decode(label["text"])
            except:
                continue
            try:
                json.dumps(key)
                json.dumps(value)
            except:
                print_error('error: no json', key)
                continue
            if force or not self.wallet.labels.get(key):
                self.wallet.labels[key] = value
        self.wallet.storage.put('labels', self.wallet.labels)
        print_error("received %d labels"%len(response))
        self.window.labelsChanged.emit()
예제 #7
0
 def close_wallet(self):
     print_error("trezor: clear session")
     if self.wallet.client:
         self.wallet.client.clear_session()
예제 #8
0
def give_error(message):
    print_error(message)
    raise Exception(message)
예제 #9
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"))])
                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

        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_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 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 = run_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
예제 #10
0
 def close_wallet(self):
     print_error("trezor: clear session")
     if self.wallet.client:
         self.wallet.client.clear_session()
예제 #11
0
def give_error(message):
    print_error(message)
    raise Exception(message)
예제 #12
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"))])
                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

        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_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 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 = run_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
예제 #13
0
    def do_full_push(self):
        try:
            bundle = {"labels": {}}
            for key, value in self.wallet.labels.iteritems():
                try:
                    encoded_key = self.encode(key)
                except:
                    print_error('cannot encode', repr(key))
                    continue
                try:
                    encoded_value = self.encode(value)
                except:
                    print_error('cannot encode', repr(value))
                    continue
                bundle["labels"][encoded_key] = encoded_value

            params = json.dumps(bundle)
            connection = httplib.HTTPConnection(self.target_host)
            connection.request("POST", ("/api/wallets/%s/labels/batch.json?auth_token=%s" % (self.wallet_id, self.auth_token())), params, {'Content-Type': 'application/json'})

            response = connection.getresponse()
            if response.reason == httplib.responses[httplib.NOT_FOUND]:
                print_error('404 error' %  e)
                return
            try:
                response = json.loads(response.read())
            except ValueError as e:
                print_error('Error loading labelsync response: %s' %  e)
                return False

            if "error" in response:
                print_error('Error loading labelsync response.')
                return False

        except socket.gaierror as e:
            print_error('Error connecting to service: %s ' %  e)
            return False

        self.window.labelsChanged.emit()