From 0c63da3715fb6c134572abb98be7349159337df7 Mon Sep 17 00:00:00 2001 From: blnkoff Date: Tue, 16 Apr 2024 23:10:46 +0300 Subject: [PATCH] Fixing property `provider` in ``Defi` and adding properties to exceptions. --- evm_extras/abc.py | 2 +- evm_extras/exceptions.py | 69 +++++++++++++++++++++++++++++++++++++--- pyproject.toml | 2 +- 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/evm_extras/abc.py b/evm_extras/abc.py index 1165d2f..2d83a65 100644 --- a/evm_extras/abc.py +++ b/evm_extras/abc.py @@ -50,7 +50,7 @@ def provider(self) -> AsyncWeb3: :return: An instance of AsyncWeb3. """ - return self.provider + return self._provider @property def version(self) -> int | None: diff --git a/evm_extras/exceptions.py b/evm_extras/exceptions.py index e699809..a952bdb 100644 --- a/evm_extras/exceptions.py +++ b/evm_extras/exceptions.py @@ -4,9 +4,24 @@ class ContractNotFound(ValueError): """Raised when contract is not found in a specific network""" - def __init__(self, defi: str, destination_network: str, supported_networks: list[str]): - super().__init__(f"Contract is not found in {destination_network}. {defi} supports the following networks: " + def __init__(self, defi: str, dest_network: str, supported_networks: list[str]): + super().__init__(f"Contract is not found in {dest_network}. {defi} supports the following networks: " f"{', '.join(supported_networks)}") + self.__defi = defi + self.__supported_networks = supported_networks + self.__dest_network = dest_network + + @property + def defi(self) -> str: + return self.__defi + + @property + def dest_network(self) -> str: + return self.__dest_network + + @property + def supported_networks(self) -> list[str] | tuple[str]: + return self.__supported_networks class InvalidToken(TypeError): @@ -16,9 +31,55 @@ def __init__(self, token: Any, network: str, defi: str, supported_tokens: list[s super().__init__(f"Token {token} is not supported in {network} or in a contract as a whole for " f"using in {defi}. This contract supports: {', '.join(supported_tokens)}") + self.__token = token + self.__supported_tokens = supported_tokens + self.__defi = defi + + @property + def network(self) -> str: + return self.__token + + @property + def token(self) -> Any: + return self.__token + + @property + def defi(self) -> str: + return self.__defi + + @property + def supported_tokens(self) -> list[str] | tuple[str]: + return self.__supported_tokens + class InvalidRoute(ValueError): """Raised when provided token route is invalid""" - def __init__(self, input_token: str, output_token: str, source_network: str, destination_network: str, defi: str): - super().__init__(f"Token route {input_token} ({source_network}) --> {output_token} ({destination_network}) is " + def __init__(self, input_token: str, output_token: str, src_network: str, dest_network: str, defi: str): + super().__init__(f"Token route {input_token} [{src_network}] --> {output_token} [{dest_network}] is " f"not valid for {defi}") + + self.__input_token = input_token + self.__output_token = output_token + self.__src_network = src_network + self.__dest_network = dest_network + self.__defi = defi + + @property + def input_token(self) -> str: + return self.__input_token + + @property + def output_token(self) -> str: + return self.__output_token + + @property + def src_network(self) -> str: + return self.__src_network + + @property + def dest_network(self) -> str: + return self.__dest_network + + @property + def defi(self) -> str: + return self.__defi diff --git a/pyproject.toml b/pyproject.toml index 4dcfc35..1d54f36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = 'evm_extras' -version = '0.1.2' +version = '0.1.3' description = 'The package containing utilities to develop Web3-based projects' authors = ['Alexey '] license = 'MIT'