From 841a1a362df3d25ada23466850490eb68462a100 Mon Sep 17 00:00:00 2001 From: 1yam Date: Mon, 30 Sep 2024 15:19:43 +0200 Subject: [PATCH] Fix: rename CHAINS_CONFIG_FILE to CONFIG_FILE to avoid getting issue by conf of chain --- src/aleph/sdk/account.py | 10 +++++----- src/aleph/sdk/conf.py | 6 +++--- src/aleph/sdk/utils.py | 16 ++++++++-------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/aleph/sdk/account.py b/src/aleph/sdk/account.py index 73b928c1..1b47202b 100644 --- a/src/aleph/sdk/account.py +++ b/src/aleph/sdk/account.py @@ -131,8 +131,8 @@ def _load_account( elif private_key_path and private_key_path.is_file(): if private_key_path: try: - # Look for the account by private_key_path in CHAINS_CONFIG_FILE - with open(settings.CHAINS_CONFIG_FILE, "r") as file: + # Look for the account by private_key_path in CONFIG_FILE + with open(settings.CONFIG_FILE, "r") as file: accounts = json.load(file) matching_account = next( @@ -159,13 +159,13 @@ def _load_account( except FileNotFoundError: logger.warning( - f"CHAINS_CONFIG_FILE not found, using default account type {account_type.__name__}" + f"CONFIG_FILE not found, using default account type {account_type.__name__}" ) except json.JSONDecodeError: logger.error( - f"Invalid format in CHAINS_CONFIG_FILE, unable to load account info." + f"Invalid format in CONFIG_FILE, unable to load account info." ) - raise ValueError(f"Invalid format in {settings.CHAINS_CONFIG_FILE}.") + raise ValueError(f"Invalid format in {settings.CONFIG_FILE}.") except Exception as e: logger.error(f"Error loading accounts from config: {e}") raise ValueError( diff --git a/src/aleph/sdk/conf.py b/src/aleph/sdk/conf.py index 484c50c7..71628407 100644 --- a/src/aleph/sdk/conf.py +++ b/src/aleph/sdk/conf.py @@ -25,7 +25,7 @@ class Settings(BaseSettings): description="Path to the mnemonic used to create Substrate keypairs", ) - CHAINS_CONFIG_FILE: Path = Field( + CONFIG_FILE: Path = Field( default=Path("chains_config.json"), description="Path to the JSON file containing chain account configurations", ) @@ -167,8 +167,8 @@ class Config: settings.PRIVATE_MNEMONIC_FILE = Path( settings.CONFIG_HOME, "private-keys", "substrate.mnemonic" ) -if str(settings.CHAINS_CONFIG_FILE) == "chains_config.json": - settings.CHAINS_CONFIG_FILE = Path( +if str(settings.CONFIG_FILE) == "chains_config.json": + settings.CONFIG_FILE = Path( settings.CONFIG_HOME, "configs", "chains_config.json" ) diff --git a/src/aleph/sdk/utils.py b/src/aleph/sdk/utils.py index e4d3bc0a..4c818443 100644 --- a/src/aleph/sdk/utils.py +++ b/src/aleph/sdk/utils.py @@ -468,7 +468,7 @@ async def save_json(file_path: Path, data: list): async def add_chain_account(new_account: ChainAccount): """Add a new chain account to the JSON file asynchronously.""" - accounts = await load_json(settings.CHAINS_CONFIG_FILE) + accounts = await load_json(settings.CONFIG_FILE) for account in accounts: if account["name"] == new_account.name: @@ -476,7 +476,7 @@ async def add_chain_account(new_account: ChainAccount): raise ValueError(f"Account with name {new_account.name} already exists.") accounts.append(new_account.dict()) - await save_json(settings.CHAINS_CONFIG_FILE, accounts) + await save_json(settings.CONFIG_FILE, accounts) logger.debug( 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): async def get_chain_account(name: str) -> ChainAccount: """Retrieve a chain account by name from the JSON file.""" - accounts = await load_json(settings.CHAINS_CONFIG_FILE) + accounts = await load_json(settings.CONFIG_FILE) for account in accounts: if account["name"] == name: @@ -498,7 +498,7 @@ async def get_chain_account(name: str) -> ChainAccount: async def get_chain_account_from_path(path: str) -> ChainAccount: """Retrieve a chain account by name from the JSON file.""" - accounts = await load_json(settings.CHAINS_CONFIG_FILE) + accounts = await load_json(settings.CONFIG_FILE) for account in accounts: if account["path"] == path: @@ -511,12 +511,12 @@ async def get_chain_account_from_path(path: str) -> ChainAccount: async def update_chain_account(updated_account: ChainAccount): """Update an existing chain account in the JSON file.""" - accounts = await load_json(settings.CHAINS_CONFIG_FILE) + accounts = await load_json(settings.CONFIG_FILE) for index, account in enumerate(accounts): if account["name"] == updated_account.name: accounts[index] = updated_account.dict() - await save_json(settings.CHAINS_CONFIG_FILE, accounts) + await save_json(settings.CONFIG_FILE, accounts) logger.debug(f"Updated account with name {updated_account.name}.") return @@ -526,7 +526,7 @@ async def update_chain_account(updated_account: ChainAccount): async def delete_chain_account(name: str): """Delete a chain account from the JSON file.""" - accounts = await load_json(settings.CHAINS_CONFIG_FILE) + accounts = await load_json(settings.CONFIG_FILE) updated_accounts = [account for account in accounts if account["name"] != name] @@ -534,7 +534,7 @@ async def delete_chain_account(name: str): logger.error(f"No account found with name {name}.") raise ValueError(f"No account found with name {name}.") - await save_json(settings.CHAINS_CONFIG_FILE, updated_accounts) + await save_json(settings.CONFIG_FILE, updated_accounts) logger.debug(f"Deleted account with name {name}.")