From 55929edb3d1ccd9187f815fe3a435baf3d0a16ef Mon Sep 17 00:00:00 2001 From: mhh Date: Wed, 13 Mar 2024 15:43:16 +0100 Subject: [PATCH 1/2] Remove double declaration of ethereum dependencies --- setup.cfg | 3 --- 1 file changed, 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index a41e52f4..caea4dc1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,9 +39,6 @@ install_requires = typing_extensions typer aleph-message~=0.4.3 - eth_account>=0.4.0 - # Required to fix a dependency issue with parsimonious and Python3.11 - eth_abi>=4.0.0; python_version>="3.11" python-magic # The usage of test_requires is discouraged, see `Dependency Management` docs # tests_require = pytest; pytest-cov From 19431fb448c29d6e7fb6fe443d713b36ba29482e Mon Sep 17 00:00:00 2001 From: mhh Date: Wed, 13 Mar 2024 15:58:26 +0100 Subject: [PATCH 2/2] Add conditional import for default value of `account_type` in `_load_account` to avoid importing `aleph.sdk.chains.ethereum` by default --- src/aleph/sdk/account.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/aleph/sdk/account.py b/src/aleph/sdk/account.py index 6ec08c83..a229a755 100644 --- a/src/aleph/sdk/account.py +++ b/src/aleph/sdk/account.py @@ -4,7 +4,6 @@ from typing import Optional, Type, TypeVar from aleph.sdk.chains.common import get_fallback_private_key -from aleph.sdk.chains.ethereum import ETHAccount from aleph.sdk.chains.remote import RemoteAccount from aleph.sdk.conf import settings from aleph.sdk.types import AccountFromPrivateKey @@ -28,7 +27,7 @@ def account_from_file(private_key_path: Path, account_type: Type[T]) -> T: def _load_account( private_key_str: Optional[str] = None, private_key_path: Optional[Path] = None, - account_type: Type[AccountFromPrivateKey] = ETHAccount, + account_type: Optional[Type[AccountFromPrivateKey]] = None, ) -> AccountFromPrivateKey: """Load private key from a string or a file. @@ -39,6 +38,27 @@ def _load_account( private_key_str and private_key_path ), "Private key should be a string or a filepath, not both." + account_types = { + "ETHAccount": "aleph.sdk.chains.ethereum", + "SOLAccount": "aleph.sdk.chains.sol", + "CSDKAccount": "aleph.sdk.chains.cosmos", + "DOTAccount": "aleph.sdk.chains.substrate", + } + + if not account_type: + for account_name, module_name in account_types.items(): + try: + account_type = getattr( + __import__(module_name, fromlist=[account_name]), account_name + ) + break + except ModuleNotFoundError: + pass + else: + raise ValueError( + "No account type found, please install one of the supported chains" + ) + if private_key_str: logger.debug("Using account from string") return account_from_hex_string(private_key_str, account_type)