feat: migrate coordinator-api routers to use centralized aitbc package utilities
Some checks failed
Security Scanning / security-scan (push) Waiting to run
API Endpoint Tests / test-api-endpoints (push) Successful in 57s
CLI Tests / test-cli (push) Failing after 6s
Integration Tests / test-service-integration (push) Successful in 40s
Python Tests / test-python (push) Failing after 37s

- Replace logging.getLogger with aitbc.get_logger across all router files
- Migrate HTTP client usage from httpx to aitbc.AITBCHTTPClient in blockchain.py
- Add NetworkError exception handling from aitbc package
- Update blockchain status and sync status endpoints to use AITBCHTTPClient
- Add from __future__ import annotations to admin.py, client.py, governance.py
- Consistent logger initialization across 20+ router
This commit is contained in:
aitbc
2026-04-24 23:33:11 +02:00
parent 858790b89e
commit 3103debecf
38 changed files with 414 additions and 475 deletions

View File

@@ -742,6 +742,9 @@ def get_transactions(wallet_name: str, keystore_dir: Path = DEFAULT_KEYSTORE_DIR
except Exception as e:
print(f"Error: {e}")
return []
except Exception as e:
print(f"Error: {e}")
return []
def get_balance(wallet_name: str, rpc_url: str = DEFAULT_RPC_URL) -> Optional[Dict]:
@@ -808,12 +811,11 @@ def get_network_status(rpc_url: str = DEFAULT_RPC_URL) -> Optional[Dict]:
"""Get network status and health"""
try:
# Get head block
head_response = requests.get(f"{rpc_url}/rpc/head")
if head_response.status_code == 200:
return head_response.json()
else:
print(f"Error getting network status: {head_response.text}")
return None
http_client = AITBCHTTPClient(base_url=rpc_url, timeout=30)
return http_client.get("/rpc/head")
except NetworkError as e:
print(f"Error getting network status: {e}")
return None
except Exception as e:
print(f"Error: {e}")
return None
@@ -824,17 +826,16 @@ def get_blockchain_analytics(analytics_type: str, limit: int = 10, rpc_url: str
try:
if analytics_type == "blocks":
# Get recent blocks analytics
response = requests.get(f"{rpc_url}/rpc/head")
if response.status_code == 200:
head = response.json()
return {
"type": "blocks",
"current_height": head.get("height", 0),
"latest_block": head.get("hash", ""),
"timestamp": head.get("timestamp", ""),
"tx_count": head.get("tx_count", 0),
"status": "Active"
}
http_client = AITBCHTTPClient(base_url=rpc_url, timeout=30)
head = http_client.get("/rpc/head")
return {
"type": "blocks",
"current_height": head.get("height", 0),
"latest_block": head.get("hash", ""),
"timestamp": head.get("timestamp", ""),
"tx_count": head.get("tx_count", 0),
"status": "Active"
}
elif analytics_type == "supply":
# Get total supply info
@@ -980,12 +981,9 @@ def mining_operations(action: str, **kwargs) -> Optional[Dict]:
if action == "status":
# Query actual blockchain status from RPC
try:
response = requests.get(f"{rpc_url}/rpc/head", timeout=5)
if response.status_code == 200:
head_data = response.json()
actual_height = head_data.get('height', 0)
else:
actual_height = 0
http_client = AITBCHTTPClient(base_url=rpc_url, timeout=5)
head_data = http_client.get("/rpc/head")
actual_height = head_data.get('height', 0)
except Exception:
actual_height = 0
@@ -1001,12 +999,9 @@ def mining_operations(action: str, **kwargs) -> Optional[Dict]:
elif action == "rewards":
# Query actual blockchain height for reward calculation
try:
response = requests.get(f"{rpc_url}/rpc/head", timeout=5)
if response.status_code == 200:
head_data = response.json()
actual_height = head_data.get('height', 0)
else:
actual_height = 0
http_client = AITBCHTTPClient(base_url=rpc_url, timeout=5)
head_data = http_client.get("/rpc/head")
actual_height = head_data.get('height', 0)
except Exception:
actual_height = 0
@@ -1441,12 +1436,11 @@ def get_network_status(rpc_url: str = DEFAULT_RPC_URL) -> Optional[Dict]:
"""Get network status and health"""
try:
# Get head block
head_response = requests.get(f"{rpc_url}/rpc/head")
if head_response.status_code == 200:
return head_response.json()
else:
print(f"Error getting network status: {head_response.text}")
return None
http_client = AITBCHTTPClient(base_url=rpc_url, timeout=30)
return http_client.get("/rpc/head")
except NetworkError as e:
print(f"Error getting network status: {e}")
return None
except Exception as e:
print(f"Error: {e}")
return None
@@ -1457,17 +1451,16 @@ def get_blockchain_analytics(analytics_type: str, limit: int = 10, rpc_url: str
try:
if analytics_type == "blocks":
# Get recent blocks analytics
response = requests.get(f"{rpc_url}/rpc/head")
if response.status_code == 200:
head = response.json()
return {
"type": "blocks",
"current_height": head.get("height", 0),
"latest_block": head.get("hash", ""),
"timestamp": head.get("timestamp", ""),
"tx_count": head.get("tx_count", 0),
"status": "Active"
}
http_client = AITBCHTTPClient(base_url=rpc_url, timeout=30)
head = http_client.get("/rpc/head")
return {
"type": "blocks",
"current_height": head.get("height", 0),
"latest_block": head.get("hash", ""),
"timestamp": head.get("timestamp", ""),
"tx_count": head.get("tx_count", 0),
"status": "Active"
}
elif analytics_type == "supply":
# Get total supply info