Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
62 changes: 62 additions & 0 deletions apps/web/app/api/registry/specs/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { getSpecStore, getVerdictStore } from "@/lib/registry";
import type { RegisteredSpec } from "@orbital-stellar/abi-registry";
import { validateSpec } from "@orbital-stellar/abi-registry";

export const dynamic = "force-dynamic";

export async function GET() {
const specs = await getSpecStore().getAll();
const verdicts = await getVerdictStore().getAll();
const verdictMap = new Map(verdicts.map((v) => [v.contractId, v]));

const result = specs.map((spec) => ({
...spec,
latestVerdict: verdictMap.get(spec.contractId) ?? null,
}));

return Response.json(result);
}

export async function POST(req: Request) {
try {
const body = (await req.json()) as {
contractId: string;
spec: Record<string, unknown>;
publisher?: string;
};

if (!body.contractId || !body.spec) {
return Response.json(
{ error: "invalid_request", message: "contractId and spec are required" },
{ status: 400 },
);
}

const validation = validateSpec(body.spec);
if (!validation.valid) {
return Response.json(
{ error: "invalid_spec", message: validation.errors.join("; ") },
{ status: 400 },
);
}

const registered: RegisteredSpec = {
contractId: body.contractId,
spec: body.spec as RegisteredSpec["spec"],
publisher: body.publisher,
submittedAt: new Date().toISOString(),
};

await getSpecStore().register(registered);

return Response.json(registered, { status: 201 });
} catch (error) {
return Response.json(
{
error: "registration_failed",
message: error instanceof Error ? error.message : "Unknown error",
},
{ status: 500 },
);
}
}
21 changes: 21 additions & 0 deletions apps/web/app/api/registry/verdicts/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getVerdictStore } from "@/lib/registry";

export const dynamic = "force-dynamic";

export async function GET(req: Request) {
const { searchParams } = new URL(req.url);
const contractId = searchParams.get("contractId");

const store = getVerdictStore();

if (contractId) {
const verdict = await store.getLatest(contractId);
if (!verdict) {
return Response.json({ error: "not_found", message: "No verdict for this contract" }, { status: 404 });
}
return Response.json(verdict);
}

const verdicts = await store.getAll();
return Response.json(verdicts);
}
18 changes: 18 additions & 0 deletions apps/web/app/api/registry/verify/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { runVerification } from "@/lib/registry";

export const dynamic = "force-dynamic";

export async function POST() {
try {
const result = await runVerification();
return Response.json(result);
} catch (error) {
return Response.json(
{
error: "verification_failed",
message: error instanceof Error ? error.message : "Unknown error",
},
{ status: 500 },
);
}
}
Loading