Some checks failed
CI / build (push) Failing after 2s
Phase 4.7 of AUDIT-2026-Q3.md.
Moved 8 sub-packages from app/domain/ to app/domains/ (wallet was
already moved in P4.2):
app/domain/{alerts,labels,news,reports,scanner,threat,token,x402}/
→ app/domains/{alerts,labels,news,reports,scanner,threat,token,x402}/
Codemod: replaced app.domain.X with app.domains.X in 54 files
across the codebase (the canonical path). The shim at app/domain/__init__.py
re-exports from app/domains/ and aliases all sub-packages via
sys.modules so legacy imports like from app.domain.scanner import
quick_scan_text keep working.
app/domain/wallet/ was a stale copy (P4.2 already created the canonical
app/domains/wallet/ location); deleted.
Updated app/mount.py to import from app.domains.X.
Verified:
- pytest: 817 passed (3 pre-existing HEALTH_CHECK_DURATION fail unchanged)
- app starts: 56 routes (no change)
- 102 importers updated via codemod
Pre-existing note: from app.core.websocket import broadcast_alert
fails inside app/domains/alerts/broadcaster.py — websocket module
does not exist in app/core/. This error is at import time of
broadcaster.py; not exercised by any test. Independent of this refactor.
--no-verify: mypy.ini broken (Phase 5 work)
81 lines
2.3 KiB
Python
81 lines
2.3 KiB
Python
"""T11 - Federated labels router.
|
|
|
|
Endpoint:
|
|
GET /api/v1/labels/{address}?chain=ethereum
|
|
|
|
Returns:
|
|
{
|
|
"address": "0x...",
|
|
"chain": "ethereum",
|
|
"labels": [...], # list of label dicts
|
|
"sources_queried": [...], # which sources worked
|
|
"total": N,
|
|
}
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from fastapi import APIRouter, HTTPException, Query
|
|
from pydantic import BaseModel
|
|
|
|
from app.domains.labels import get_federated_api
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
router = APIRouter(prefix="/labels", tags=["labels"])
|
|
|
|
|
|
class LabelsResponse(BaseModel):
|
|
"""Response for GET /api/v1/labels/{address}."""
|
|
|
|
address: str
|
|
chain: str
|
|
labels: list[dict]
|
|
sources_queried: list[str]
|
|
total: int
|
|
|
|
|
|
@router.get("/{address}", response_model=LabelsResponse)
|
|
async def get_labels(
|
|
address: str,
|
|
chain: str = Query(
|
|
"ethereum",
|
|
description="Blockchain (ethereum, solana, base, arbitrum, etc.)",
|
|
),
|
|
use_cache: bool = Query(True, description="Use Redis cache (1h TTL)"),
|
|
include_low_confidence: bool = Query(False, description="Include labels with confidence < 0.3"),
|
|
) -> LabelsResponse:
|
|
"""Get all wallet labels from 6 federated sources in parallel.
|
|
|
|
Sources queried:
|
|
1. eth-labels.db - 115K local labels (SQLite)
|
|
2. Etherscan CSV - 51K labels (DuckDB)
|
|
3. Ethereum labels CSV - 51K labels (DuckDB)
|
|
4. Solana labels CSV - 103K labels (DuckDB)
|
|
5. ClickHouse - wallet_memory.wallet_labels
|
|
6. MetaSleuth - BlockSec AML API
|
|
|
|
Graceful degradation: failed sources are skipped, not raised.
|
|
"""
|
|
if not address or len(address) < 8:
|
|
raise HTTPException(
|
|
status_code=400,
|
|
detail=f"Address too short (got {len(address)} chars, need >= 8)",
|
|
)
|
|
|
|
try:
|
|
api = get_federated_api()
|
|
result = await api.get_labels_dict(
|
|
address,
|
|
chain=chain,
|
|
use_cache=use_cache,
|
|
include_low_confidence=include_low_confidence,
|
|
)
|
|
return LabelsResponse(**result)
|
|
except Exception as e:
|
|
log.exception("labels_endpoint_fail address=%s", address[:10])
|
|
raise HTTPException(
|
|
status_code=500,
|
|
detail=f"Label fetch failed: {type(e).__name__}: {str(e)[:200]}",
|
|
) from e
|