rmi-backend/app/domains/labels/sources/ethereum_labels_csv.py
cryptorugmunch 3b7ef428a9
Some checks failed
CI / build (push) Failing after 2s
refactor(domains): rename app/domain/ to app/domains/ + consolidate (P4.7)
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)
2026-07-06 23:08:17 +02:00

67 lines
2.5 KiB
Python

"""Ethereum wallet labels CSV source - 51K EVM labels via DuckDB."""
from __future__ import annotations
import asyncio
import logging
from datetime import UTC, datetime
from app.domains.labels.models import Label, LabelSource
log = logging.getLogger(__name__)
CSV_PATH = "/home/dev/rmi/backend/data/wallet-labels-clean/wallet_labels_ethereum.csv"
async def query_ethereum_labels_csv(address: str, chain: str = "ethereum") -> list[Label]:
"""Query the ethereum wallet labels CSV via DuckDB.
Schema:
address,chain,source,name,entity_type,threat_group,risk_level,verified
"""
def _query() -> list[Label]:
from app.core.duckdb_analytics import DuckDBAnalytics
try:
d = DuckDBAnalytics()
try:
rows = d.query_parquet(
CSV_PATH,
"""
SELECT address, chain, source, name, entity_type, threat_group, risk_level, verified
FROM data
WHERE LOWER(address) = ?
LIMIT 20
""",
[address.lower()],
)
labels = []
for row in rows:
label_value = row.get("name") or row.get("entity_type")
if not label_value:
continue
chain_name = row.get("chain", chain).lower()
labels.append(
Label(
address=row["address"].lower(),
chain=chain_name,
label_type="entity",
label_value=label_value,
source=LabelSource.ETHEREUM_LABELS_CSV,
confidence=0.85,
verified_at=datetime.now(UTC),
attributes={
"entity_type": row.get("entity_type"),
"threat_group": row.get("threat_group"),
"risk_level": row.get("risk_level"),
"verified": row.get("verified"),
},
)
)
return labels
finally:
d.close()
except Exception as e:
log.warning("ethereum_labels_csv_query_fail address=%s err=%s", address[:10], e)
raise
return await asyncio.to_thread(_query)