Files
triangles-explorer/src/routes/search/+page.server.ts
T
sami7777 b6a4bd0418 Initial SvelteKit block explorer for Triangles blockchain
Full-featured explorer consuming the daemon REST API:
- Home dashboard with chain stats, latest blocks, staking info
- Block list with pagination and block detail pages
- Transaction detail with inputs/outputs tables
- Address lookup with balance, UTXOs, and tx history
- Staking dashboard with difficulty chart (Chart.js)
- Network info with peer table
- Mempool viewer
- API documentation page for all 30+ REST endpoints
- Search by block hash, height, txid, or address
- Dark theme with Tailwind CSS v4
- SSR via adapter-node for SEO

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 21:04:36 -07:00

39 lines
1004 B
TypeScript

import { getBlock, getTransaction, getBlockHashByHeight } from '$lib/api';
import { redirect, error } from '@sveltejs/kit';
import { isNumeric, isBlockHash } from '$lib/utils';
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ url }) => {
const q = url.searchParams.get('q')?.trim();
if (!q) error(400, 'No search query provided');
// Numeric: treat as block height
if (isNumeric(q)) {
try {
const { blockhash } = await getBlockHashByHeight(parseInt(q));
redirect(302, `/block/${blockhash}`);
} catch {
error(404, `Block at height ${q} not found`);
}
}
// 64-char hex: try block hash, then txid
if (isBlockHash(q)) {
try {
await getBlock(q);
redirect(302, `/block/${q}`);
} catch {
// Not a block, try as txid
}
try {
await getTransaction(q);
redirect(302, `/tx/${q}`);
} catch {
error(404, `No block or transaction found for ${q}`);
}
}
// Otherwise: try as address
redirect(302, `/address/${q}`);
};