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
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
Staking Tests / test-staking-integration (push) Has been cancelled
Staking Tests / test-staking-contract (push) Has been cancelled
Staking Tests / run-staking-test-runner (push) Has been cancelled

- 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,41 +68,43 @@ 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:
# Call exchange API to create token escrow
response = await client.post(
f"{self.exchange_base_url}/api/v1/token/escrow/create",
json={
"amount": float(payment.amount),
"currency": payment.currency,
"job_id": payment.job_id,
"timeout_seconds": 3600, # 1 hour
},
)
client = AITBCHTTPClient(timeout=10.0)
# Call exchange API to create token escrow
response = client.post(
f"{self.exchange_base_url}/api/v1/token/escrow/create",
json={
"amount": float(payment.amount),
"currency": payment.currency,
"job_id": payment.job_id,
"timeout_seconds": 3600, # 1 hour
},
)
if response.status_code == 200:
escrow_data = response.json()
payment.escrow_address = escrow_data.get("escrow_id")
payment.status = "escrowed"
payment.escrowed_at = datetime.utcnow()
payment.updated_at = datetime.utcnow()
escrow_data = response
payment.escrow_address = escrow_data.get("escrow_id")
payment.status = "escrowed"
payment.escrowed_at = datetime.utcnow()
payment.updated_at = datetime.utcnow()
# Create escrow record
escrow = PaymentEscrow(
payment_id=payment.id,
amount=payment.amount,
currency=payment.currency,
address=escrow_data.get("escrow_id"),
expires_at=datetime.utcnow() + timedelta(hours=1),
)
if escrow is not None:
self.session.add(escrow)
# Create escrow record
escrow = PaymentEscrow(
payment_id=payment.id,
amount=payment.amount,
currency=payment.currency,
address=escrow_data.get("escrow_id"),
expires_at=datetime.utcnow() + timedelta(hours=1),
)
if escrow is not None:
self.session.add(escrow)
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}")
self.session.commit()
logger.info(f"Created AITBC token escrow for payment {payment.id}")
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: