Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: resolve CI failures — ruff lint, black format, bandit security
  • Loading branch information
devin-ai-integration[bot] committed Jul 1, 2026
commit bbad573b0edcf0780db86e8573e8fda01b5ef220
8 changes: 7 additions & 1 deletion api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import os
from typing import Any, Optional
from typing import Any

from dotenv import load_dotenv
from fastapi import FastAPI, HTTPException, Query
Expand Down Expand Up @@ -39,6 +39,7 @@
# Pydantic request models
# =========================


class NodeInput(BaseModel):
node_id: str
data: dict[str, Any]
Expand Down Expand Up @@ -78,6 +79,7 @@ class PositionInput(BaseModel):
# Status
# =========================


@app.get("/status")
async def get_status():
return engine.status()
Expand All @@ -87,6 +89,7 @@ async def get_status():
# Graph endpoints
# =========================


@app.get("/graph")
async def get_graph():
return engine.get_graph()
Expand Down Expand Up @@ -116,6 +119,7 @@ async def add_edge(body: EdgeInput):
# Events
# =========================


@app.get("/events")
async def get_events(limit: int = Query(default=50, ge=1, le=500)):
return engine.get_events(limit=limit)
Expand All @@ -131,6 +135,7 @@ async def post_event(body: EventInput):
# DB endpoints
# =========================


@app.get("/db")
async def get_db():
return engine.get_db()
Expand Down Expand Up @@ -158,6 +163,7 @@ async def add_position(body: PositionInput):
# Health
# =========================


@app.get("/health")
async def health():
return {"status": "alive", "mode": MZC_MODE, "port": MZC_PORT}
Expand Down
21 changes: 17 additions & 4 deletions apps/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# Ensure project root is importable
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))

from packages.models.envelope import ERROR_MAP, Envelope
from packages.models.envelope import Envelope
from packages.models.requests import FlowRequest, HashRequest, SignVerifyRequest
from packages.shared.config import get_settings
from packages.shared.logger import get_logger
Expand Down Expand Up @@ -63,6 +63,7 @@
# MIDDLEWARE
# =========================


@app.middleware("http")
async def request_middleware(request: Request, call_next):
request_id = request.headers.get("X-Request-ID", uuid.uuid4().hex)
Expand Down Expand Up @@ -98,6 +99,7 @@ async def request_middleware(request: Request, call_next):
# ERROR HANDLERS
# =========================


@app.exception_handler(404)
async def not_found_handler(request: Request, exc):
rid = getattr(request.state, "request_id", None)
Expand Down Expand Up @@ -126,6 +128,7 @@ async def internal_handler(request: Request, exc):
# OBSERVABILITY
# =========================


@app.get("/health/live", tags=["observability"])
async def health_live():
return {"status": "alive"}
Expand Down Expand Up @@ -159,6 +162,7 @@ async def metrics():

# --- HEALTH ---


@app.get("/api/v1/health", tags=["health"])
async def health(request: Request):
subsystems = {
Expand Down Expand Up @@ -191,7 +195,9 @@ def _check_service(service, name: str) -> dict:


def _check_db() -> dict:
db_path = os.path.join(os.path.dirname(__file__), "..", "..", "storage", "db", "db.json")
db_path = os.path.join(
os.path.dirname(__file__), "..", "..", "storage", "db", "db.json"
)
if os.path.exists(db_path):
return {"status": "ok"}
return {"status": "error", "detail": "db.json not found"}
Expand All @@ -205,6 +211,7 @@ def _check_rpc() -> dict:

# --- GRAPH ---


@app.get("/api/v1/graph", tags=["graph"])
async def graph(request: Request):
data = graph_service.get_graph()
Expand All @@ -214,6 +221,7 @@ async def graph(request: Request):

# --- RADAR ---


@app.get("/api/v1/radar", tags=["radar"])
async def radar(request: Request):
data = radar_service.scan()
Expand All @@ -223,6 +231,7 @@ async def radar(request: Request):

# --- FUNDING ---


@app.get("/api/v1/funding/{wallet}", tags=["funding"])
async def funding_wallet(request: Request, wallet: str):
data = funding_service.trace(wallet=wallet)
Expand All @@ -239,6 +248,7 @@ async def funding_all(request: Request):

# --- FLOW ---


@app.post("/api/v1/flow", tags=["flow"])
async def flow(request: Request, body: FlowRequest):
data = {
Expand All @@ -252,6 +262,7 @@ async def flow(request: Request, body: FlowRequest):

# --- HASH / SHA256 ---


@app.post("/api/v1/hash/sha256", tags=["signature"])
async def hash_sha256(request: Request, body: HashRequest):
digest = hashlib.sha256(body.input.encode("utf-8")).hexdigest()
Expand All @@ -262,6 +273,7 @@ async def hash_sha256(request: Request, body: HashRequest):

# --- SIGN / VERIFY ---


@app.post("/api/v1/sign/verify", tags=["signature"])
async def sign_verify(request: Request, body: SignVerifyRequest):
result = signature_service.verify(body.wallet, body.message, body.signature)
Expand All @@ -277,7 +289,8 @@ async def sign_verify(request: Request, body: SignVerifyRequest):
if __name__ == "__main__":
import uvicorn

print(f"WEB4 MUCIZEWORK ENGINE STARTED — API Contract v1")
print("WEB4 MUCIZEWORK ENGINE STARTED — API Contract v1")
print(f"PORT: {settings.port}")
print(f"DOCS: http://127.0.0.1:{settings.port}/docs")
uvicorn.run(app, host="0.0.0.0", port=settings.port)
host = os.environ.get("MZC_HOST", "0.0.0.0") # nosec B104
uvicorn.run(app, host=host, port=settings.port)
2 changes: 0 additions & 2 deletions clustering/cluster_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Clustering Engine — Wallet sınıflandırma (AJAN / MZC / MYK).
"""

import json

CLUSTERS = {
"AJAN": {"type": "execution"},
"MZC": {"type": "asset"},
Expand Down
6 changes: 3 additions & 3 deletions engine/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
"""

import json
import os
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Optional


STORAGE_DIR = Path(__file__).resolve().parent.parent / "storage"


Expand Down Expand Up @@ -123,7 +121,9 @@ def _log_event(self, event_type: str, payload: dict[str, Any]) -> dict[str, Any]
def get_events(self, limit: int = 50) -> list[dict[str, Any]]:
return self.events[-limit:]

def log_custom_event(self, event_type: str, payload: dict[str, Any]) -> dict[str, Any]:
def log_custom_event(
self, event_type: str, payload: dict[str, Any]
) -> dict[str, Any]:
return self._log_event(event_type, payload)

# ------------------------------------------------------------------
Expand Down
14 changes: 8 additions & 6 deletions funding/funding_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
@app.route("/flow", methods=["POST"])
def flow():
data = request.json
flows.append({
"from": data["from"],
"to": data["to"],
"amount": data["amount"],
"ts": time.time(),
})
flows.append(
{
"from": data["from"],
"to": data["to"],
"amount": data["amount"],
"ts": time.time(),
}
)
return jsonify({"status": "flow_added", "total": len(flows)})


Expand Down
36 changes: 24 additions & 12 deletions legacy/flask_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
# MIDDLEWARE
# =========================


@app.before_request
def before_request_handler():
g.request_id = request.headers.get("X-Request-ID", uuid.uuid4().hex)
Expand Down Expand Up @@ -107,6 +108,7 @@ def handle_500(e):
# HEALTH (enhanced)
# =========================


@v1.route("/health")
def health():
subsystems = {
Expand All @@ -117,13 +119,15 @@ def health():
"database": _check_db(),
}
all_ok = all(s["status"] == "ok" for s in subsystems.values())
return jsonify({
"status": "online" if all_ok else "degraded",
"engine": "WEB4_BLACK_MUCIZEWORK",
"version": API_VERSION,
"subsystems": subsystems,
"timestamp": time.time(),
})
return jsonify(
{
"status": "online" if all_ok else "degraded",
"engine": "WEB4_BLACK_MUCIZEWORK",
"version": API_VERSION,
"subsystems": subsystems,
"timestamp": time.time(),
}
)


def _check_graph():
Expand Down Expand Up @@ -169,6 +173,7 @@ def _check_db():
# GRAPH
# =========================


@v1.route("/graph")
def graph():
return jsonify(cluster.graph())
Expand All @@ -178,6 +183,7 @@ def graph():
# RADAR
# =========================


@v1.route("/radar")
def get_radar():
return jsonify(radar.scan())
Expand All @@ -187,6 +193,7 @@ def get_radar():
# FUNDING (with wallet path param)
# =========================


@v1.route("/funding/<wallet>")
def get_funding(wallet):
data = funding.trace(wallet=wallet)
Expand All @@ -203,6 +210,7 @@ def get_funding_all():
# FLOW
# =========================


@v1.route("/flow", methods=["POST"])
def flow():
data = request.json
Expand All @@ -219,6 +227,7 @@ def flow():
# HASH (SHA256)
# =========================


@v1.route("/hash/sha256", methods=["POST"])
def hash_sha256():
data = request.json
Expand All @@ -233,6 +242,7 @@ def hash_sha256():
# SIGN / VERIFY
# =========================


@v1.route("/sign/verify", methods=["POST"])
def sign_verify():
data = request.json
Expand All @@ -243,11 +253,13 @@ def sign_verify():
if missing:
return error_response(422, f"Eksik alanlar: {', '.join(missing)}")
result = sig.verify(data["wallet"], data["message"], data["signature"])
return jsonify({
"valid": result["valid"],
"hash": result["hash"],
"wallet": data["wallet"],
})
return jsonify(
{
"valid": result["valid"],
"hash": result["hash"],
"wallet": data["wallet"],
}
)


# =========================
Expand Down
4 changes: 3 additions & 1 deletion packages/models/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class Envelope(BaseModel):
error: Optional[ErrorDetail] = None

@classmethod
def ok(cls, data: Any, request_id: str | None = None, trace_id: str | None = None) -> "Envelope":
def ok(
cls, data: Any, request_id: str | None = None, trace_id: str | None = None
) -> "Envelope":
return cls(success=True, data=data, request_id=request_id, trace_id=trace_id)

@classmethod
Expand Down
1 change: 0 additions & 1 deletion packages/shared/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Configuration management via environment variables."""

import os
from functools import lru_cache

from pydantic import Field
Expand Down
Loading
Loading