initfmfijirfri

This commit is contained in:
ZOMBIIIIIII
2026-05-14 21:40:36 +03:00
parent 22059373a4
commit 079e271cc0
4 changed files with 257 additions and 27 deletions

View File

@@ -0,0 +1,36 @@
/**
* GET /api/tokens — реестр всех известных активов всех 5 сетей + native.
*
* Read-only. Источник — `lib/token-registry.ts`. Никаких RPC calls,
* никаких user-specific данных — только статический list контрактов с symbol + name.
*
* Optional query: ?chain=ETH|BSC|BTC|TRX|SOL — filter одной сетью.
*/
import { Router, Request, Response } from 'express';
import { getAllTokens } from '../lib/token-registry';
import { ALL_CHAINS } from '../services/wallet-generator.service';
import type { ChainCode } from '../lib/address-validators';
const router = Router();
const ALLOWED = new Set<ChainCode>(ALL_CHAINS);
router.get('/', (req: Request, res: Response) => {
const chainParam = req.query.chain;
let filterChain: ChainCode | undefined;
if (chainParam !== undefined && chainParam !== null && chainParam !== '') {
const upper = String(chainParam).toUpperCase();
if (!ALLOWED.has(upper as ChainCode)) {
res.status(400).json({
success: false,
error: `Invalid chain "${chainParam}" (allowed: ETH, BSC, BTC, TRX, SOL)`,
});
return;
}
filterChain = upper as ChainCode;
}
const data = getAllTokens(filterChain);
res.json({ success: true, data });
});
export default router;