feat: migrate coordinator-api services and exchange CLI to use centralized aitbc package utilities
Some checks failed
Python Tests / test-python (push) Waiting to run
Security Scanning / security-scan (push) Waiting to run
Staking Tests / test-staking-integration (push) Blocked by required conditions
Staking Tests / test-staking-contract (push) Blocked by required conditions
Staking Tests / run-staking-test-runner (push) Blocked by required conditions
API Endpoint Tests / test-api-endpoints (push) Successful in 9s
CLI Tests / test-cli (push) Failing after 8s
Integration Tests / test-service-integration (push) Successful in 45s
Staking Tests / test-staking-service (push) Failing after 14m32s

- Replace logging.getLogger with aitbc.get_logger in analytics_service.py, staking_service.py, wallet_service.py
- Migrate payments.py from httpx to aitbc.AITBCHTTPClient for token escrow creation
- Add NetworkError exception handling in payments.py
- Remove async context manager and status code checks in favor of AITBCHTTPClient
- Update exchange.py CLI commands (create_pair, start_trading) to use
This commit is contained in:
aitbc
2026-04-24 23:37:21 +02:00
parent 3103debecf
commit 0ccd8ef995
5 changed files with 55 additions and 74 deletions

View File

@@ -3,12 +3,13 @@ Marketplace Analytics Service
Implements comprehensive analytics, insights, and reporting for the marketplace
"""
import logging
from datetime import datetime, timedelta
from typing import Any
from uuid import uuid4
logger = logging.getLogger(__name__)
from aitbc import get_logger
logger = get_logger(__name__)
from sqlmodel import Session, and_, select

View File

@@ -5,14 +5,11 @@ from sqlalchemy.orm import Session
"""Payment service for job payments"""
import logging
from datetime import datetime, timedelta
from __future__ import annotations
import httpx
from aitbc import get_logger
from aitbc import get_logger, AITBCHTTPClient, NetworkError
logger = get_logger(__name__)
@@ -71,9 +68,9 @@ class PaymentService:
"""Create an escrow for AITBC token payments"""
try:
# For AITBC tokens, we use the token contract escrow
async with httpx.AsyncClient() as client:
client = AITBCHTTPClient(timeout=10.0)
# Call exchange API to create token escrow
response = await client.post(
response = client.post(
f"{self.exchange_base_url}/api/v1/token/escrow/create",
json={
"amount": float(payment.amount),
@@ -83,8 +80,7 @@ class PaymentService:
},
)
if response.status_code == 200:
escrow_data = response.json()
escrow_data = response
payment.escrow_address = escrow_data.get("escrow_id")
payment.status = "escrowed"
payment.escrowed_at = datetime.utcnow()
@@ -103,9 +99,12 @@ class PaymentService:
self.session.commit()
logger.info(f"Created AITBC token escrow for payment {payment.id}")
else:
logger.error(f"Failed to create token escrow: {response.text}")
except NetworkError as e:
logger.error(f"Failed to create token escrow: {e}")
payment.status = "failed"
payment.updated_at = datetime.utcnow()
self.session.commit()
except Exception as e:
logger.error(f"Error creating token escrow: {e}")
payment.status = "failed"

View File

@@ -3,16 +3,16 @@ Staking Management Service
Business logic for AI agent staking system with reputation-based yield farming
"""
import logging
from datetime import datetime, timedelta
from typing import Any
from sqlalchemy import and_, func, select
from sqlalchemy.orm import Session
from aitbc import get_logger
from ..domain.bounty import AgentMetrics, AgentStake, PerformanceTier, StakeStatus, StakingPool
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
class StakingService:

View File

@@ -6,19 +6,18 @@ Service for managing agent wallets across multiple blockchain networks.
from __future__ import annotations
import logging
# In a real scenario, these would be proper cryptographic key generation utilities
import secrets
from sqlalchemy import select
from sqlmodel import Session
from aitbc import get_logger
from ..blockchain.contract_interactions import ContractInteractionService
from ..domain.wallet import AgentWallet, TokenBalance, TransactionStatus, WalletTransaction
from ..schemas.wallet import TransactionRequest, WalletCreate
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
class WalletService:

View File

@@ -590,23 +590,14 @@ def create_pair(ctx, pair: str, base_asset: str, quote_asset: str,
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
response = http_client.post(
f"{config.coordinator_url}/v1/exchange/create-pair",
json=pair_data,
timeout=10
)
if response.status_code == 200:
result = response.json()
result = http_client.post("/exchange/create-pair", json=pair_data)
success(f"Trading pair '{pair}' created successfully!")
success(f"Pair ID: {result.get('pair_id')}")
output(result, ctx.obj['output_format'])
else:
error(f"Failed to create trading pair: {response.status_code}")
if response.text:
error(f"Error details: {response.text}")
except Exception as e:
except NetworkError as e:
error(f"Network error: {e}")
except Exception as e:
error(f"Error: {e}")
@exchange.command()
@@ -629,23 +620,14 @@ def start_trading(ctx, pair: str, exchange: Optional[str], order_type: tuple):
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
response = http_client.post(
f"{config.coordinator_url}/v1/exchange/start-trading",
json=trading_data,
timeout=10
)
if response.status_code == 200:
result = response.json()
result = http_client.post("/exchange/start-trading", json=trading_data)
success(f"Trading started for pair '{pair}'!")
success(f"Order types: {', '.join(order_type)}")
output(result, ctx.obj['output_format'])
else:
error(f"Failed to start trading: {response.status_code}")
if response.text:
error(f"Error details: {response.text}")
except Exception as e:
except NetworkError as e:
error(f"Network error: {e}")
except Exception as e:
error(f"Error: {e}")
@exchange.command()