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

Remove double declaration of ethereum dependencies #109

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 22 additions & 2 deletions src/aleph/sdk/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand All @@ -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)
Expand Down
Loading