Skip to content

Commit 841a1a3

Browse files
committed
Fix: rename CHAINS_CONFIG_FILE to CONFIG_FILE to avoid getting issue by conf of chain
1 parent 59c845e commit 841a1a3

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/aleph/sdk/account.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def _load_account(
131131
elif private_key_path and private_key_path.is_file():
132132
if private_key_path:
133133
try:
134-
# Look for the account by private_key_path in CHAINS_CONFIG_FILE
135-
with open(settings.CHAINS_CONFIG_FILE, "r") as file:
134+
# Look for the account by private_key_path in CONFIG_FILE
135+
with open(settings.CONFIG_FILE, "r") as file:
136136
accounts = json.load(file)
137137

138138
matching_account = next(
@@ -159,13 +159,13 @@ def _load_account(
159159

160160
except FileNotFoundError:
161161
logger.warning(
162-
f"CHAINS_CONFIG_FILE not found, using default account type {account_type.__name__}"
162+
f"CONFIG_FILE not found, using default account type {account_type.__name__}"
163163
)
164164
except json.JSONDecodeError:
165165
logger.error(
166-
f"Invalid format in CHAINS_CONFIG_FILE, unable to load account info."
166+
f"Invalid format in CONFIG_FILE, unable to load account info."
167167
)
168-
raise ValueError(f"Invalid format in {settings.CHAINS_CONFIG_FILE}.")
168+
raise ValueError(f"Invalid format in {settings.CONFIG_FILE}.")
169169
except Exception as e:
170170
logger.error(f"Error loading accounts from config: {e}")
171171
raise ValueError(

src/aleph/sdk/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Settings(BaseSettings):
2525
description="Path to the mnemonic used to create Substrate keypairs",
2626
)
2727

28-
CHAINS_CONFIG_FILE: Path = Field(
28+
CONFIG_FILE: Path = Field(
2929
default=Path("chains_config.json"),
3030
description="Path to the JSON file containing chain account configurations",
3131
)
@@ -167,8 +167,8 @@ class Config:
167167
settings.PRIVATE_MNEMONIC_FILE = Path(
168168
settings.CONFIG_HOME, "private-keys", "substrate.mnemonic"
169169
)
170-
if str(settings.CHAINS_CONFIG_FILE) == "chains_config.json":
171-
settings.CHAINS_CONFIG_FILE = Path(
170+
if str(settings.CONFIG_FILE) == "chains_config.json":
171+
settings.CONFIG_FILE = Path(
172172
settings.CONFIG_HOME, "configs", "chains_config.json"
173173
)
174174

src/aleph/sdk/utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,15 +468,15 @@ async def save_json(file_path: Path, data: list):
468468

469469
async def add_chain_account(new_account: ChainAccount):
470470
"""Add a new chain account to the JSON file asynchronously."""
471-
accounts = await load_json(settings.CHAINS_CONFIG_FILE)
471+
accounts = await load_json(settings.CONFIG_FILE)
472472

473473
for account in accounts:
474474
if account["name"] == new_account.name:
475475
logger.error(f"Account with name {new_account.name} already exists.")
476476
raise ValueError(f"Account with name {new_account.name} already exists.")
477477

478478
accounts.append(new_account.dict())
479-
await save_json(settings.CHAINS_CONFIG_FILE, accounts)
479+
await save_json(settings.CONFIG_FILE, accounts)
480480

481481
logger.debug(
482482
f"Added account for {new_account.name} with chain {new_account.chain} and path {new_account.path}."
@@ -485,7 +485,7 @@ async def add_chain_account(new_account: ChainAccount):
485485

486486
async def get_chain_account(name: str) -> ChainAccount:
487487
"""Retrieve a chain account by name from the JSON file."""
488-
accounts = await load_json(settings.CHAINS_CONFIG_FILE)
488+
accounts = await load_json(settings.CONFIG_FILE)
489489

490490
for account in accounts:
491491
if account["name"] == name:
@@ -498,7 +498,7 @@ async def get_chain_account(name: str) -> ChainAccount:
498498

499499
async def get_chain_account_from_path(path: str) -> ChainAccount:
500500
"""Retrieve a chain account by name from the JSON file."""
501-
accounts = await load_json(settings.CHAINS_CONFIG_FILE)
501+
accounts = await load_json(settings.CONFIG_FILE)
502502

503503
for account in accounts:
504504
if account["path"] == path:
@@ -511,12 +511,12 @@ async def get_chain_account_from_path(path: str) -> ChainAccount:
511511

512512
async def update_chain_account(updated_account: ChainAccount):
513513
"""Update an existing chain account in the JSON file."""
514-
accounts = await load_json(settings.CHAINS_CONFIG_FILE)
514+
accounts = await load_json(settings.CONFIG_FILE)
515515

516516
for index, account in enumerate(accounts):
517517
if account["name"] == updated_account.name:
518518
accounts[index] = updated_account.dict()
519-
await save_json(settings.CHAINS_CONFIG_FILE, accounts)
519+
await save_json(settings.CONFIG_FILE, accounts)
520520
logger.debug(f"Updated account with name {updated_account.name}.")
521521
return
522522

@@ -526,15 +526,15 @@ async def update_chain_account(updated_account: ChainAccount):
526526

527527
async def delete_chain_account(name: str):
528528
"""Delete a chain account from the JSON file."""
529-
accounts = await load_json(settings.CHAINS_CONFIG_FILE)
529+
accounts = await load_json(settings.CONFIG_FILE)
530530

531531
updated_accounts = [account for account in accounts if account["name"] != name]
532532

533533
if len(updated_accounts) == len(accounts):
534534
logger.error(f"No account found with name {name}.")
535535
raise ValueError(f"No account found with name {name}.")
536536

537-
await save_json(settings.CHAINS_CONFIG_FILE, updated_accounts)
537+
await save_json(settings.CONFIG_FILE, updated_accounts)
538538
logger.debug(f"Deleted account with name {name}.")
539539

540540

0 commit comments

Comments
 (0)