From c0ca07b90bd9109b5e63ad3938feeb65e28e7bec Mon Sep 17 00:00:00 2001 From: Joseph Rana Date: Wed, 23 Apr 2025 16:59:03 +0545 Subject: [PATCH 1/2] fix: convert stake key hash into stake address before query --- api/.env.example | 4 +++- api/backend/app/services/agent_service.py | 18 +++++++++++++----- api/backend/config/application.py | 3 ++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/api/.env.example b/api/.env.example index 041a74a35..66cfbc8d6 100644 --- a/api/.env.example +++ b/api/.env.example @@ -5,4 +5,6 @@ AGENT_MNEMONIC= KAFKA_ENABLED=true METADATA_BASE_URL='https://metadata.drep.id/api' DB_SYNC_BASE_URL= -KAFKA_PREFIX= \ No newline at end of file +KAFKA_PREFIX= +#preview , mainnet , prepod ... defaults to mainnet +NETWORK='' \ No newline at end of file diff --git a/api/backend/app/services/agent_service.py b/api/backend/app/services/agent_service.py index d483659e6..82f0eeba5 100644 --- a/api/backend/app/services/agent_service.py +++ b/api/backend/app/services/agent_service.py @@ -280,11 +280,9 @@ async def return_agent_with_wallet_details(self, agent: AgentResponse): async with aiohttp.ClientSession() as session: async with asyncio.TaskGroup() as group: agent_configurations = group.create_task(self.trigger_service.list_triggers_by_agent_id(agent.id)) - wallet_balance = group.create_task(self.fetch_balance(wallet.stake_key_hash, session)) - drep_details = group.create_task(self.fetch_drep_details(wallet.stake_key_hash, session)) - delegation_details = group.create_task( - self.fetch_delegation_details(wallet.stake_key_hash, session) - ) + wallet_balance = group.create_task(self.fetch_balance(convert_stake_key_hash_to_address(wallet.stake_key_hash), session)) + drep_details = group.create_task(self.fetch_drep_details(convert_stake_key_hash_to_address(wallet.stake_key_hash), session)) + delegation_details = group.create_task(self.fetch_delegation_details(convert_stake_key_hash_to_address(wallet.stake_key_hash), session)) stake_address_details = group.create_task( self.fetch_stake_address_details(wallet.stake_key_hash, session) ) @@ -303,3 +301,13 @@ async def return_agent_with_wallet_details(self, agent: AgentResponse): is_stake_registered=stake_address_details.result().get("is_stake_registered"), stake_last_registered=stake_address_details.result().get("last_registered"), ) + + +def convert_stake_key_hash_to_address(stake_key_hash): + if stake_key_hash.startswith('e0') or stake_key_hash.startswith('e1'): + return stake_key_hash + else: + if api_settings.APP_ENV == "mainnet": + return 'e1' + stake_key_hash + else: + return 'e0' + stake_key_hash \ No newline at end of file diff --git a/api/backend/config/application.py b/api/backend/config/application.py index 1fd1cba32..35ee721cc 100644 --- a/api/backend/config/application.py +++ b/api/backend/config/application.py @@ -36,6 +36,7 @@ class Application(BaseSettings): KAFKA_BROKERS: str = "localhost:9092" KAFKA_ENABLED: bool = False KUBER_URL: str = "" + NETWORK: str = "mainnet" # All your additional application configuration should go either here or in # separate file in this submodule. @@ -56,4 +57,4 @@ class Config: env_prefix = "" -settings = Application() +settings = Application() \ No newline at end of file From e7c870dd775faa426255efdba8c6c7f31a8ebbed Mon Sep 17 00:00:00 2001 From: Joseph Rana Date: Wed, 23 Apr 2025 17:03:33 +0545 Subject: [PATCH 2/2] chore: run black lint --- api/backend/app/services/agent_service.py | 20 +++++++++++++------- api/backend/config/application.py | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/api/backend/app/services/agent_service.py b/api/backend/app/services/agent_service.py index 82f0eeba5..89689a0e6 100644 --- a/api/backend/app/services/agent_service.py +++ b/api/backend/app/services/agent_service.py @@ -280,9 +280,15 @@ async def return_agent_with_wallet_details(self, agent: AgentResponse): async with aiohttp.ClientSession() as session: async with asyncio.TaskGroup() as group: agent_configurations = group.create_task(self.trigger_service.list_triggers_by_agent_id(agent.id)) - wallet_balance = group.create_task(self.fetch_balance(convert_stake_key_hash_to_address(wallet.stake_key_hash), session)) - drep_details = group.create_task(self.fetch_drep_details(convert_stake_key_hash_to_address(wallet.stake_key_hash), session)) - delegation_details = group.create_task(self.fetch_delegation_details(convert_stake_key_hash_to_address(wallet.stake_key_hash), session)) + wallet_balance = group.create_task( + self.fetch_balance(convert_stake_key_hash_to_address(wallet.stake_key_hash), session) + ) + drep_details = group.create_task( + self.fetch_drep_details(convert_stake_key_hash_to_address(wallet.stake_key_hash), session) + ) + delegation_details = group.create_task( + self.fetch_delegation_details(convert_stake_key_hash_to_address(wallet.stake_key_hash), session) + ) stake_address_details = group.create_task( self.fetch_stake_address_details(wallet.stake_key_hash, session) ) @@ -302,12 +308,12 @@ async def return_agent_with_wallet_details(self, agent: AgentResponse): stake_last_registered=stake_address_details.result().get("last_registered"), ) - + def convert_stake_key_hash_to_address(stake_key_hash): - if stake_key_hash.startswith('e0') or stake_key_hash.startswith('e1'): + if stake_key_hash.startswith("e0") or stake_key_hash.startswith("e1"): return stake_key_hash else: if api_settings.APP_ENV == "mainnet": - return 'e1' + stake_key_hash + return "e1" + stake_key_hash else: - return 'e0' + stake_key_hash \ No newline at end of file + return "e0" + stake_key_hash diff --git a/api/backend/config/application.py b/api/backend/config/application.py index 35ee721cc..41836cc86 100644 --- a/api/backend/config/application.py +++ b/api/backend/config/application.py @@ -57,4 +57,4 @@ class Config: env_prefix = "" -settings = Application() \ No newline at end of file +settings = Application()