示例#1
0
 def _get_wallet_path(self, wallet_name: str) -> str:
     esv_wallets_dir = os.path.join(app_state.config.electrum_path(),
                                    "wallets")
     wallet_path = os.path.join(esv_wallets_dir, wallet_name)
     wallet_path = os.path.normpath(wallet_path)
     if wallet_name != get_wallet_name_from_path(wallet_path):
         raise RPCError("wallet_name must not be a path")
     if not os.path.exists(wallet_path):
         raise RPCError(f"{wallet_path}: wallet_name does not exist")
     return wallet_path
示例#2
0
 def _get_recently_opened_wallets(self):
     return [{
         'name':
         get_wallet_name_from_path(file_path),
         'path':
         file_path,
         'is_encrypted':
         WalletStorage(file_path, manual_upgrades=True).is_encrypted,
     } for file_path in app_state.config.get('recently_open', [])
             if os.path.exists(file_path)]
示例#3
0
    def _get_recently_opened_wallets(self) -> Dict[str, Any]:
        results = []
        for file_path in app_state.config.get('recently_open', []):
            if os.path.exists(file_path) and categorise_file(
                    file_path) != StorageKind.HYBRID:
                results.append({
                    'name': get_wallet_name_from_path(file_path),
                    'path': file_path,
                })

        return results
示例#4
0
def create_file_state(wallet_path: str) -> Optional[FileState]:
    if not os.path.exists(wallet_path):
        return None

    try:
        storage = WalletStorage(wallet_path)
    except Exception:
        logger.exception("problem looking at selected wallet '%s'",
                         wallet_path)
        return None

    is_too_modern = False
    try:
        storage_info = categorise_file(wallet_path)
        if storage_info.kind == StorageKind.HYBRID:
            return None

        wallet_action = WalletAction.OPEN
        password_state = PasswordState.UNKNOWN

        if storage_info.kind == StorageKind.FILE:
            text_store = storage.get_text_store()
            try:
                text_store.attempt_load_data()
            except IOError:
                # IOError: storage.py:load_data() raises when selected file cannot be parsed.
                return None
            if storage.get("use_encryption"):
                # If there is a password and the wallet is not encrypted, then the private data
                # is encrypted.
                password_state = PasswordState.PASSWORDED
            elif text_store.is_encrypted():
                # If there is a password and the wallet is encrypted, then the private data is
                # encrypted and the file is encrypted.
                password_state = PasswordState.PASSWORDED | PasswordState.ENCRYPTED
            else:
                # Neither the private data is encrypted or the file itself.
                password_state = PasswordState.NONE
        else:
            assert storage_info.kind == StorageKind.DATABASE
            password_state = PasswordState.PASSWORDED
            database_store = storage.get_database_store()
            is_too_modern = database_store.get("migration") > MIGRATION_CURRENT

        requires_upgrade = storage.requires_split(
        ) or storage.requires_upgrade()
    finally:
        storage.close()

    name = get_wallet_name_from_path(wallet_path)
    modification_time = os.path.getmtime(wallet_path)
    return FileState(name, wallet_path, wallet_action, storage_info.kind,
                     password_state, requires_upgrade, modification_time,
                     is_too_modern)