Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/sync_dev_after_v1_7_1 #352

Merged
merged 8 commits into from
Sep 23, 2024
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

All notable changes to this project will be documented in this file.

## [1.7.0] - 2024-09-18
## [1.7.1] - 2024-09-24
### Fixed
- Fixed logic to get the absolute ofac.json file path

## [1.7.0] - 2024-09-19
### Added
- Added OFAC restricted addresses validations

Expand Down
15 changes: 6 additions & 9 deletions pyinjective/ofac.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@
class OfacChecker:
def __init__(self):
self._ofac_list_path = self.get_ofac_list_path()
if not os.path.exists(self._ofac_list_path):
try:
with open(self._ofac_list_path, "r") as f:
self._ofac_list = set(json.load(f))
except Exception as e:
raise Exception(
"OFAC list is missing on the disk. Please, download it by running python3 pyinjective/ofac_list.py"
f"Error parsing OFAC list. Please, download it by running python3 pyinjective/ofac_list.py ({e})"
Comment on lines +15 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved error handling, but consider preserving the original exception.

The new try-except block enhances error handling when reading and parsing the OFAC list. The error message is now more informative, guiding users to download the list if needed.

To further improve exception handling and preserve the original traceback, consider using raise ... from e:

 try:
     with open(self._ofac_list_path, "r") as f:
         self._ofac_list = set(json.load(f))
 except Exception as e:
-    raise Exception(
-        f"Error parsing OFAC list. Please, download it by running python3 pyinjective/ofac_list.py ({e})"
-    )
+    raise Exception(
+        f"Error parsing OFAC list. Please, download it by running python3 pyinjective/ofac_list.py"
+    ) from e

This change will help maintain the full context of the original error while providing the custom error message.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try:
with open(self._ofac_list_path, "r") as f:
self._ofac_list = set(json.load(f))
except Exception as e:
raise Exception(
"OFAC list is missing on the disk. Please, download it by running python3 pyinjective/ofac_list.py"
f"Error parsing OFAC list. Please, download it by running python3 pyinjective/ofac_list.py ({e})"
try:
with open(self._ofac_list_path, "r") as f:
self._ofac_list = set(json.load(f))
except Exception as e:
raise Exception(
f"Error parsing OFAC list. Please, download it by running python3 pyinjective/ofac_list.py"
) from e

)

with open(self._ofac_list_path, "r") as f:
self._ofac_list = set(json.load(f))

@classmethod
def get_ofac_list_path(cls):
current_directory = os.getcwd()
while os.path.basename(current_directory) != "sdk-python":
current_directory = os.path.dirname(current_directory)
return os.path.join(os.path.join(current_directory, "pyinjective"), OFAC_LIST_FILENAME)
return os.path.join(os.path.dirname(__file__), OFAC_LIST_FILENAME)

@classmethod
async def download_ofac_list(cls):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "injective-py"
version = "1.7.0"
version = "1.8.0-pre"
description = "Injective Python SDK, with Exchange API Client"
authors = ["Injective Labs <[email protected]>"]
license = "Apache-2.0"
Expand Down
Loading