Esempio n. 1
0
 def init_storage_from_path(self, path):
     self.storage = WalletStorage(path)
     self.basename = self.storage.basename()
     if not self.storage.file_exists():
         self.require_password = False
         self.message = _('Press Next to create')
     elif self.storage.is_encrypted():
         if not self.storage.is_encrypted_with_user_pw():
             raise Exception(
                 "Kivy GUI does not support this type of encrypted wallet files."
             )
         self.require_password = True
         self.pw_check = self.storage.check_password
         self.message = self.enter_pw_message
     else:
         # it is a bit wasteful load the wallet here and load it again in main_window,
         # but that is fine, because we are progressively enforcing storage encryption.
         db = WalletDB(self.storage.read(), manual_upgrades=False)
         if db.upgrade_done:
             self.storage.backup_old_version()
             self.app.show_backup_msg()
         if db.check_unfinished_multisig():
             self.require_password = False
         else:
             wallet = Wallet(db,
                             self.storage,
                             config=self.app.electrum_config)
             self.require_password = wallet.has_password()
             self.pw_check = wallet.check_password
         self.message = (self.enter_pw_message if self.require_password else
                         _('Wallet not encrypted'))
Esempio n. 2
0
    def __init__(self, config, daemon, plugins):
        colorama.init()
        self.config = config
        self.network = network = daemon.network
        if config.get('tor_auto_on', True):
            if network:
                proxy_modifiable = config.is_modifiable('proxy')
                if not proxy_modifiable or not network.detect_tor_proxy():
                    print(network.TOR_WARN_MSG_TXT)
                    c = ''
                    while c != 'y':
                        c = input("Continue without Tor (y/n)?")
                        if c == 'n':
                            exit()
        storage = WalletStorage(config.get_wallet_path())
        if not storage.file_exists:
            print("Wallet not found. try 'electrum-dash create'")
            exit()
        if storage.is_encrypted():
            password = getpass.getpass('Password:'******'Can not open unfinished multisig wallet')
            exit()

        if getattr(storage, 'backup_message', None):
            print(f'{storage.backup_message}\n')
            input('Press Enter to continue...')

        self.done = 0
        self.last_balance = ""

        self.str_recipient = ""
        self.str_description = ""
        self.str_amount = ""
        self.str_fee = ""

        self.wallet = Wallet(db, storage, config=config)
        self.wallet.start_network(self.network)
        self.contacts = self.wallet.contacts

        util.register_callback(self.on_network,
                               ['wallet_updated', 'network_updated', 'banner'])
        self.commands = [_("[h] - displays this help text"), \
                         _("[i] - display transaction history"), \
                         _("[o] - enter payment order"), \
                         _("[p] - print stored payment order"), \
                         _("[s] - send stored payment order"), \
                         _("[r] - show own receipt addresses"), \
                         _("[c] - display contacts"), \
                         _("[b] - print server banner"), \
                         _("[M] - start PrivateSend mixing"),
                         _("[S] - stop PrivateSend mixing"),
                         _("[l][f][a] - print PrivateSend log (filtered/all)"),
                         _("[q] - quit")]
        self.num_commands = len(self.commands)
Esempio n. 3
0
 def _start_wizard_to_select_or_create_wallet(
         self, path) -> Optional[Abstract_Wallet]:
     wizard = InstallWizard(self.config,
                            self.app,
                            self.plugins,
                            gui_object=self)
     try:
         path, storage = wizard.select_storage(path, self.daemon.get_wallet)
         # storage is None if file does not exist
         if storage is None:
             wizard.path = path  # needed by trustedcoin plugin
             wizard.run('new')
             storage, db = wizard.create_storage(path)
             if db.check_unfinished_multisig():
                 wizard.show_message(_('Saved unfinished multisig wallet'))
                 return
         else:
             db = WalletDB(storage.read(), manual_upgrades=False)
             if db.upgrade_done:
                 storage.backup_old_version()
             wizard.run_upgrades(storage, db)
         if getattr(storage, 'backup_message', None):
             custom_message_box(icon=QMessageBox.Warning,
                                parent=None,
                                title=_('Information'),
                                text=storage.backup_message)
             storage.backup_message = ''
         if db.check_unfinished_multisig():
             wizard.continue_multisig_setup(storage)
             storage, db = wizard.create_storage(storage.path)
             if db.check_unfinished_multisig():
                 wizard.show_message(_('Saved unfinished multisig wallet'))
                 return
     except (UserCancelled, GoBack):
         return
     except WalletAlreadyOpenInMemory as e:
         return e.wallet
     finally:
         wizard.terminate()
     # return if wallet creation is not complete
     if storage is None or db.get_action():
         return
     wallet = Wallet(db, storage, config=self.config)
     wallet.start_network(self.daemon.network)
     self.daemon.add_wallet(wallet)
     return wallet
Esempio n. 4
0
    def test_check_unfinished_multisig(self):
        d = {'wallet_type': 'standard', "seed_version": FINAL_SEED_VERSION}

        db = WalletDB(json.dumps(d), manual_upgrades=False)
        assert not db.check_unfinished_multisig()

        d['wallet_type'] = '2of3'
        d['x1/'] = d['x2/'] = d['x3/'] = 'some data'
        db = WalletDB(json.dumps(d), manual_upgrades=False)
        assert not db.check_unfinished_multisig()

        del d['x3/']
        db = WalletDB(json.dumps(d), manual_upgrades=False)
        assert db.check_unfinished_multisig()  # x1/, x2/ pass
        assert db.check_unfinished_multisig()

        del d['x2/']
        db = WalletDB(json.dumps(d), manual_upgrades=False)
        assert db.check_unfinished_multisig()  # x1/ pass
        assert db.check_unfinished_multisig()

        del d['x1/']
        db = WalletDB(json.dumps(d), manual_upgrades=False)
        assert not db.check_unfinished_multisig()  # no x1/ fails

        d['x1/'] = d['x3/'] = 'some data'
        db = WalletDB(json.dumps(d), manual_upgrades=False)
        assert not db.check_unfinished_multisig()  # x1/, x3/ fails

        d['x2/'] = 'some data'
        del d['x1/']
        db = WalletDB(json.dumps(d), manual_upgrades=False)
        assert not db.check_unfinished_multisig()  # x2/, x3/ fails
Esempio n. 5
0
    def test_continue_multisig_setup(self):
        wiz = self.wizard
        storage = WalletStorage(self.wallet_path)
        d = {'wallet_type': 'standard', "seed_version": FINAL_SEED_VERSION}
        d['wallet_type'] = '2of3'
        d['x1/'] = X1
        db = WalletDB(json.dumps(d), manual_upgrades=True)
        assert db.check_unfinished_multisig()
        db.write(storage)
        storage = WalletStorage(self.wallet_path)
        wiz.continue_multisig_setup(storage)
        assert wiz.unfinished_multisig
        assert wiz.unfinished_enc_version == StorageEncryptionVersion.PLAINTEXT
        assert not wiz.unfinished_check_password
        assert wiz.last_method == 'continue_multisig_setup_dialog'
        last_args = wiz.last_args
        assert last_args[0:2] == (2, 3)  # m, n
        assert last_args[2] == wiz.keystores  # keystores
        assert len(last_args[2]) == 1
        k1 = last_args[2][0]
        assert type(k1) == BIP32_KeyStore
        assert k1.get_root_fingerprint() == '3f635a63'
        assert last_args[3] == wiz.choose_keystore  # run_next

        d['x2/'] = X2
        db = WalletDB(json.dumps(d), manual_upgrades=True)
        assert db.check_unfinished_multisig()
        db.write(storage)
        storage = WalletStorage(self.wallet_path)
        wiz.continue_multisig_setup(storage)
        assert wiz.unfinished_multisig
        assert wiz.unfinished_enc_version == StorageEncryptionVersion.PLAINTEXT
        assert not wiz.unfinished_check_password
        assert wiz.last_method == 'continue_multisig_setup_dialog'
        last_args = wiz.last_args
        assert last_args[0:2] == (2, 3)  # m, n
        assert last_args[2] == wiz.keystores  # keystores
        assert len(last_args[2]) == 2
        k1, k2 = last_args[2]
        assert type(k1) == BIP32_KeyStore
        assert k1.get_root_fingerprint() == '3f635a63'
        assert type(k2) == BIP32_KeyStore
        assert k2.get_root_fingerprint() == 'e54b06c8'
        assert last_args[3] == wiz.choose_keystore  # run_next
Esempio n. 6
0
    def __init__(self, config: 'SimpleConfig', daemon: 'Daemon',
                 plugins: 'Plugins'):

        self.config = config
        self.network = network = daemon.network
        if config.get('tor_auto_on', True):
            if network:
                proxy_modifiable = config.is_modifiable('proxy')
                if not proxy_modifiable or not network.detect_tor_proxy():
                    print(network.TOR_WARN_MSG_TXT)
                    c = ''
                    while c != 'y':
                        c = input("Continue without Tor (y/n)?")
                        if c == 'n':
                            exit()
        storage = WalletStorage(config.get_wallet_path())
        if not storage.file_exists():
            print("Wallet not found. try 'electrum-dash create'")
            exit()
        if storage.is_encrypted():
            password = getpass.getpass('Password:'******'Can not open unfinished multisig wallet')
            exit()

        self.wallet = Wallet(db, storage, config=config)
        self.wallet.start_network(self.network)
        self.contacts = self.wallet.contacts

        locale.setlocale(locale.LC_ALL, '')
        self.encoding = locale.getpreferredencoding()

        self.stdscr = curses.initscr()
        curses.noecho()
        curses.cbreak()
        curses.start_color()
        curses.use_default_colors()
        curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
        curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_CYAN)
        curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE)
        self.stdscr.keypad(1)

        if getattr(storage, 'backup_message', None):
            msg_key = 'Press any key to continue...'
            self.stdscr.addstr(f'{storage.backup_message}\n\n{msg_key}')
            self.stdscr.getch()

        self.stdscr.border(0)
        self.maxy, self.maxx = self.stdscr.getmaxyx()
        self.set_cursor(0)
        self.w = curses.newwin(10, 50, 5, 5)

        console_stderr_handler.setLevel(logging.CRITICAL)
        self.tab = 0
        self.pos = 0
        self.popup_pos = 0

        self.str_recipient = ""
        self.str_description = ""
        self.str_amount = ""
        self.str_fee = ""
        self.history = None
        def_dip2 = not self.wallet.psman.unsupported
        self.show_dip2 = self.config.get('show_dip2_tx_type', def_dip2)

        util.register_callback(self.update,
                               ['wallet_updated', 'network_updated'])

        self.tab_names = [
            _("History"),
            _("Send"),
            _("Receive"),
            _("Addresses"),
            _("Contacts"),
            _("Banner")
        ]
        self.num_tabs = len(self.tab_names)