Ejemplo n.º 1
0
 def __init__(self, storage):
     BIP32_HD_Wallet.__init__(self, storage)
     self.transport = None
     self.client = None
     self.mpk = None
     self.device_checked = False
     self.force_watching_only = False
     always_hook('add_plugin', self)
Ejemplo n.º 2
0
 def __init__(self, storage):
     BIP32_HD_Wallet.__init__(self, storage)
     self.transport = None
     self.client = None
     self.mpk = None
     self.device_checked = False
     self.force_watching_only = False
     always_hook('add_plugin', self)
Ejemplo n.º 3
0
 def __init__(self, config, network, app=None):
     set_language(config.get('language'))
     self.network = network
     self.config = config
     self.windows = []
     self.efilter = OpenFileEventFilter(self.windows)
     if app is None:
         self.app = QApplication(sys.argv)
     self.app.installEventFilter(self.efilter)
     # let plugins know that we are using the qt gui
     always_hook('init_qt_app', self.app)
Ejemplo n.º 4
0
 def __init__(self, config, network, app=None):
     set_language(config.get('language'))
     self.network = network
     self.config = config
     self.windows = []
     self.efilter = OpenFileEventFilter(self.windows)
     if app is None:
         self.app = QApplication(sys.argv)
     self.app.installEventFilter(self.efilter)
     # let plugins know that we are using the qt gui
     always_hook('init_qt_app', self.app)
Ejemplo n.º 5
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):
                password = self.password_dialog()
                wallet = Wallet.from_private_key(text, password, self.storage)
            elif Wallet.is_seed(text):
                password = self.password_dialog()
                wallet = Wallet.from_seed(text, password, self.storage)
            else:
                raise BaseException('unknown wallet type')

        elif re.match('(\d+)of(\d+)', t):
            n = int(re.match('(\d+)of(\d+)', t).group(2))
            key_list = self.multi_seed_dialog(n - 1)
            if not key_list:
                return
            password = self.password_dialog() if any(
                map(lambda x: Wallet.is_seed(x) or Wallet.is_xprv(x),
                    key_list)) else None
            wallet = Wallet.from_multisig(key_list, password, self.storage, t)

        else:
            self.storage.put('wallet_type', t, False)
            # call the constructor to load the plugin (side effect)
            Wallet(self.storage)
            wallet = always_hook('installwizard_restore', self, self.storage)
            if not wallet:
                util.print_error("no wallet")
                return

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

        return wallet
Ejemplo n.º 6
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):
                password = self.password_dialog()
                wallet = Wallet.from_private_key(text, password, self.storage)
            elif Wallet.is_seed(text):
                password = self.password_dialog()
                wallet = Wallet.from_seed(text, password, self.storage)
            else:
                raise BaseException('unknown wallet type')

        elif t in ['2of2', '2of3']:
            key_list = self.multi_seed_dialog(1 if t == '2of2' else 2)
            if not key_list:
                return
            password = self.password_dialog() if any(
                map(lambda x: Wallet.is_seed(x) or Wallet.is_xprv(x),
                    key_list)) else None
            wallet = Wallet.from_multisig(key_list, password, self.storage)

        else:
            self.storage.put('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
Ejemplo n.º 7
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):
                    password = self.password_dialog()
                    wallet = Wallet.from_private_key(text, password, self.storage)
                elif Wallet.is_seed(text):
                    password = self.password_dialog()
                    wallet = Wallet.from_seed(text, password, self.storage)
                else:
                    raise BaseException('unknown wallet type')

            elif t in ['2of2', '2of3']:
                key_list = self.multi_seed_dialog(1 if t == '2of2' else 2)
                if not key_list:
                    return
                password = self.password_dialog() if any(map(lambda x: Wallet.is_seed(x) or Wallet.is_xprv(x), key_list)) else None
                wallet = Wallet.from_multisig(key_list, password, self.storage)

            else:
                self.storage.put('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
Ejemplo n.º 8
0
    def run(self, action, wallet_type):

        if action in ['create', 'restore']:
            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':
                lang = self.config.get('language')
                seed = wallet.make_seed(lang)
                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':
                wallet.create_main_account(password)
                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()
            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
Ejemplo n.º 9
0
    def run(self, action, wallet_type):

        if action in ['create', 'restore']:
            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':
                lang = self.config.get('language')
                seed = wallet.make_seed(lang)
                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':
                wallet.create_main_account(password)
                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()
            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