Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.env
__pycache__/
*.pyc
.venv/
venv/
*.egg-info/
dist/
build/
.pytest_cache/
storage/logs/events.json
storage/state/
167 changes: 167 additions & 0 deletions api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
"""
MUCIZEWORK MASTER API — v4.0 BLACK
Port: 5002 | Endpoints: /status, /graph, /events, /db
"""

import os
from typing import Any, Optional

from dotenv import load_dotenv
from fastapi import FastAPI, HTTPException, Query
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
import uvicorn

from engine import MucizeEngine

load_dotenv()

MZC_MODE = os.getenv("MZC_MODE", "BLACK")
MZC_PORT = int(os.getenv("MZC_PORT", "5002"))

app = FastAPI(
title="MUCIZEWORK MASTER ENGINE",
version="4.0",
description="Merkezi motor API — graph, event ve veri yönetimi",
)

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)

engine = MucizeEngine()


# =========================
# Pydantic request models
# =========================

class NodeInput(BaseModel):
node_id: str
data: dict[str, Any]


class EdgeInput(BaseModel):
source: str
target: str
weight: float = 1.0


class EventInput(BaseModel):
event_type: str
payload: dict[str, Any]


class WalletInput(BaseModel):
wallet_id: str
data: dict[str, Any]


class FlowInput(BaseModel):
source: str
target: str
amount: float
token: str = "MZC"


class PositionInput(BaseModel):
protocol: str
asset: str
amount: float
chain: str = "ethereum"


# =========================
# Status
# =========================

@app.get("/status")
async def get_status():
return engine.status()


# =========================
# Graph endpoints
# =========================

@app.get("/graph")
async def get_graph():
return engine.get_graph()


@app.post("/graph/node")
async def add_node(body: NodeInput):
node = engine.add_node(body.node_id, body.data)
return {"ok": True, "node": node}


@app.delete("/graph/node/{node_id}")
async def remove_node(node_id: str):
removed = engine.remove_node(node_id)
if not removed:
raise HTTPException(status_code=404, detail=f"Node '{node_id}' bulunamadi")
return {"ok": True, "removed": node_id}


@app.post("/graph/edge")
async def add_edge(body: EdgeInput):
edge = engine.add_edge(body.source, body.target, body.weight)
return {"ok": True, "edge": edge}


# =========================
# Events
# =========================

@app.get("/events")
async def get_events(limit: int = Query(default=50, ge=1, le=500)):
return engine.get_events(limit=limit)


@app.post("/events")
async def post_event(body: EventInput):
event = engine.log_custom_event(body.event_type, body.payload)
return {"ok": True, "event": event}


# =========================
# DB endpoints
# =========================

@app.get("/db")
async def get_db():
return engine.get_db()


@app.post("/db/wallet")
async def add_wallet(body: WalletInput):
wallet = engine.add_wallet(body.wallet_id, body.data)
return {"ok": True, "wallet": wallet}


@app.post("/db/flow")
async def add_flow(body: FlowInput):
flow = engine.add_flow(body.model_dump())
return {"ok": True, "flow": flow}


@app.post("/db/position")
async def add_position(body: PositionInput):
position = engine.add_position(body.model_dump())
return {"ok": True, "position": position}


# =========================
# Health
# =========================

@app.get("/health")
async def health():
return {"status": "alive", "mode": MZC_MODE, "port": MZC_PORT}


if __name__ == "__main__":
uvicorn.run("api:app", host="0.0.0.0", port=MZC_PORT, reload=True)
61 changes: 61 additions & 0 deletions api/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
MUCIZEWORK WEB4 Core Orchestrator — Final One-Block System
Port: 5002
"""

import sys
import os

sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))

from flask import Flask, jsonify, request
from wallet_cluster.cluster import WalletCluster
from radar.radar import Radar
from funding.trace import FundingTrace
from signature.engine import SignatureEngine

app = Flask(__name__)

cluster = WalletCluster()
radar = Radar()
funding = FundingTrace()
sig = SignatureEngine()


@app.route("/health")
def health():
return jsonify({"status": "online", "engine": "WEB4_BLACK_MUCIZEWORK"})


@app.route("/graph")
def graph():
return jsonify(cluster.graph())


@app.route("/radar")
def get_radar():
return jsonify(radar.scan())


@app.route("/funding")
def get_funding():
return jsonify(funding.trace())


@app.route("/flow", methods=["POST"])
def flow():
data = request.json
return jsonify({"status": "flow_added", "data": data})


@app.route("/sign", methods=["POST"])
def sign():
d = request.json
h = sig.verify(d.get("wallet"), d.get("message"), d.get("signature"))
return jsonify({"verify_hash": h})


if __name__ == "__main__":
print("WEB4 MUCIZEWORK ENGINE STARTED")
print("PORT: 5002")
app.run(port=5002, debug=False)
19 changes: 19 additions & 0 deletions clustering/cluster_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Clustering Engine — Wallet sınıflandırma (AJAN / MZC / MYK).
"""

import json

CLUSTERS = {
"AJAN": {"type": "execution"},
"MZC": {"type": "asset"},
"MYK": {"type": "treasury"},
}


def classify(wallet):
return CLUSTERS.get(wallet, {"type": "unknown"})


if __name__ == "__main__":
print("CLUSTER ENGINE ACTIVE")
Empty file added core/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions core/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"engine": "MUCIZEWORK_WEB4",
"mode": "BLACK",
"status": "ACTIVE"
}
3 changes: 3 additions & 0 deletions engine/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from engine.core import MucizeEngine

__all__ = ["MucizeEngine"]
Loading