Skip to content

Commit a1c7313

Browse files
authored
Fix wrong account config alert (#184)
1 parent c24a3cf commit a1c7313

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/aleph/sdk/account.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,35 @@ def _load_account(
9393
"""Load an account from a private key string or file, or from the configuration file."""
9494

9595
config = load_main_configuration(settings.CONFIG_FILE)
96-
chain_to_use = settings.DEFAULT_CHAIN
96+
default_chain = settings.DEFAULT_CHAIN
9797

9898
if not chain:
9999
if config and hasattr(config, "chain"):
100-
chain_to_use = config.chain
100+
chain = config.chain
101101
logger.debug(
102102
f"Detected {config.chain} account for path {settings.CONFIG_FILE}"
103103
)
104+
else:
105+
chain = default_chain
106+
logger.warning(
107+
f"No main configuration found on path {settings.CONFIG_FILE}, defaulting to {chain}"
108+
)
109+
else:
110+
chain = default_chain
104111

105112
# Loads configuration if no account_type is specified
106113
if not account_type:
107-
account_type = load_chain_account_type(chain_to_use)
108-
logger.warning(
109-
f"No main configuration data found in {settings.CONFIG_FILE}, defaulting to {account_type and account_type.__name__}"
114+
account_type = load_chain_account_type(chain)
115+
logger.debug(
116+
f"No account type specified defaulting to {account_type and account_type.__name__}"
110117
)
111118

112119
# Loads private key from a string
113120
if private_key_str:
114-
return account_from_hex_string(private_key_str, account_type, chain_to_use)
121+
return account_from_hex_string(private_key_str, account_type, chain)
115122
# Loads private key from a file
116123
elif private_key_path and private_key_path.is_file():
117-
return account_from_file(private_key_path, account_type, chain_to_use)
124+
return account_from_file(private_key_path, account_type, chain)
118125
# For ledger keys
119126
elif settings.REMOTE_CRYPTO_HOST:
120127
logger.debug("Using remote account")
@@ -129,7 +136,7 @@ def _load_account(
129136
else:
130137
new_private_key = get_fallback_private_key()
131138
account = account_from_hex_string(
132-
bytes.hex(new_private_key), account_type, chain_to_use
139+
bytes.hex(new_private_key), account_type, chain
133140
)
134141
logger.info(
135142
f"Generated fallback private key with address {account.get_address()}"

0 commit comments

Comments
 (0)