Example #1
0
 def on_filename(filename):
     # FIXME? "filename" might contain ".." (etc) and hence sketchy path traversals are possible
     nonlocal temp_storage
     temp_storage = None
     msg = None
     if filename:
         path = os.path.join(wallet_folder, filename)
         wallet_from_memory = get_wallet_from_daemon(path)
         try:
             if wallet_from_memory:
                 temp_storage = wallet_from_memory.storage  # type: Optional[WalletStorage]
             else:
                 temp_storage = WalletStorage(path)
         except (StorageReadWriteError, WalletFileException) as e:
             msg = _('Cannot read file') + f'\n{repr(e)}'
         except Exception as e:
             self.logger.exception('')
             msg = _('Cannot read file') + f'\n{repr(e)}'
     else:
         msg = ""
     self.next_button.setEnabled(temp_storage is not None)
     user_needs_to_enter_password = False
     if temp_storage:
         if not temp_storage.file_exists():
             msg =_("This file does not exist.") + '\n' \
                   + _("Press 'Next' to create this wallet, or choose another file.")
         elif not wallet_from_memory:
             if temp_storage.is_encrypted_with_user_pw():
                 msg = _("This file is encrypted with a password.") + '\n' \
                       + _('Enter your password or choose another file.')
                 user_needs_to_enter_password = True
             elif temp_storage.is_encrypted_with_hw_device():
                 msg = _("This file is encrypted using a hardware device.") + '\n' \
                       + _("Press 'Next' to choose device to decrypt.")
             else:
                 msg = _("Press 'Next' to open this wallet.")
         else:
             msg = _("This file is already open in memory.") + "\n" \
                 + _("Press 'Next' to create/focus window.")
     if msg is None:
         msg = _('Cannot read file')
     msg_label.setText(msg)
     widget_create_new.setVisible(
         bool(temp_storage and temp_storage.file_exists()))
     if user_needs_to_enter_password:
         pw_label.show()
         pw_e.show()
         pw_e.setFocus()
     else:
         pw_label.hide()
         pw_e.hide()
Example #2
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:'******'')
        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)