2022-07-11 19:15:28 +02:00
|
|
|
import axios from 'axios';
|
|
|
|
import { Application, Request, Response } from 'express';
|
|
|
|
import config from '../../config';
|
|
|
|
import elementsParser from './elements-parser';
|
|
|
|
import icons from './icons';
|
2024-08-22 19:51:28 +00:00
|
|
|
import { handleError } from '../../utils/api';
|
2022-07-11 19:15:28 +02:00
|
|
|
|
|
|
|
class LiquidRoutes {
|
|
|
|
public initRoutes(app: Application) {
|
|
|
|
app
|
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'assets/icons', this.getAllLiquidIcon)
|
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'assets/featured', this.$getAllFeaturedLiquidAssets)
|
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'asset/:assetId/icon', this.getLiquidIcon)
|
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'assets/group/:id', this.$getAssetGroup)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (config.DATABASE.ENABLED) {
|
|
|
|
app
|
2024-01-20 15:15:15 +01:00
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'liquid/pegs', this.$getElementsPegs)
|
2022-07-11 19:15:28 +02:00
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'liquid/pegs/month', this.$getElementsPegsByMonth)
|
2024-02-12 11:34:47 +01:00
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'liquid/pegs/list/:count', this.$getPegsList)
|
2024-02-06 17:35:02 +01:00
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'liquid/pegs/volume', this.$getPegsVolumeDaily)
|
2024-02-12 11:34:47 +01:00
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'liquid/pegs/count', this.$getPegsCount)
|
2024-01-20 15:15:15 +01:00
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'liquid/reserves', this.$getFederationReserves)
|
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'liquid/reserves/month', this.$getFederationReservesByMonth)
|
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'liquid/reserves/addresses', this.$getFederationAddresses)
|
2024-02-09 16:26:59 +01:00
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'liquid/reserves/addresses/total', this.$getFederationAddressesNumber)
|
2024-01-20 15:15:15 +01:00
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'liquid/reserves/utxos', this.$getFederationUtxos)
|
2024-02-09 16:26:59 +01:00
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'liquid/reserves/utxos/total', this.$getFederationUtxosNumber)
|
2024-02-27 16:39:28 +01:00
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'liquid/reserves/utxos/expired', this.$getExpiredUtxos)
|
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'liquid/reserves/utxos/emergency-spent', this.$getEmergencySpentUtxos)
|
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'liquid/reserves/utxos/emergency-spent/stats', this.$getEmergencySpentUtxosStats)
|
2024-01-20 15:15:15 +01:00
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'liquid/reserves/status', this.$getFederationAuditStatus)
|
2022-07-11 19:15:28 +02:00
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private getLiquidIcon(req: Request, res: Response) {
|
|
|
|
const result = icons.getIconByAssetId(req.params.assetId);
|
|
|
|
if (result) {
|
|
|
|
res.setHeader('content-type', 'image/png');
|
|
|
|
res.setHeader('content-length', result.length);
|
|
|
|
res.send(result);
|
|
|
|
} else {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 404, 'Asset icon not found');
|
2022-07-11 19:15:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private getAllLiquidIcon(req: Request, res: Response) {
|
|
|
|
const result = icons.getAllIconIds();
|
|
|
|
if (result) {
|
|
|
|
res.json(result);
|
|
|
|
} else {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 404, 'Asset icons not found');
|
2022-07-11 19:15:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async $getAllFeaturedLiquidAssets(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const response = await axios.get(`${config.EXTERNAL_DATA_SERVER.LIQUID_API}/assets/featured`, { responseType: 'stream', timeout: 10000 });
|
|
|
|
response.data.pipe(res);
|
|
|
|
} catch (e) {
|
|
|
|
res.status(500).end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async $getAssetGroup(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const response = await axios.get(`${config.EXTERNAL_DATA_SERVER.LIQUID_API}/assets/group/${parseInt(req.params.id, 10)}`,
|
|
|
|
{ responseType: 'stream', timeout: 10000 });
|
|
|
|
response.data.pipe(res);
|
|
|
|
} catch (e) {
|
|
|
|
res.status(500).end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async $getElementsPegsByMonth(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const pegs = await elementsParser.$getPegDataByMonth();
|
2024-01-20 15:15:15 +01:00
|
|
|
res.header('Pragma', 'public');
|
|
|
|
res.header('Cache-control', 'public');
|
|
|
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 60 * 60).toUTCString());
|
2022-07-11 19:15:28 +02:00
|
|
|
res.json(pegs);
|
|
|
|
} catch (e) {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
2022-07-11 19:15:28 +02:00
|
|
|
}
|
|
|
|
}
|
2024-01-20 15:15:15 +01:00
|
|
|
|
|
|
|
private async $getFederationReservesByMonth(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const reserves = await elementsParser.$getFederationReservesByMonth();
|
|
|
|
res.header('Pragma', 'public');
|
|
|
|
res.header('Cache-control', 'public');
|
|
|
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 60 * 60).toUTCString());
|
|
|
|
res.json(reserves);
|
|
|
|
} catch (e) {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
2024-01-20 15:15:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async $getElementsPegs(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const currentSupply = await elementsParser.$getCurrentLbtcSupply();
|
|
|
|
res.header('Pragma', 'public');
|
|
|
|
res.header('Cache-control', 'public');
|
|
|
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 30).toUTCString());
|
|
|
|
res.json(currentSupply);
|
|
|
|
} catch (e) {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
2024-01-20 15:15:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async $getFederationReserves(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const currentReserves = await elementsParser.$getCurrentFederationReserves();
|
|
|
|
res.header('Pragma', 'public');
|
|
|
|
res.header('Cache-control', 'public');
|
|
|
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 30).toUTCString());
|
|
|
|
res.json(currentReserves);
|
|
|
|
} catch (e) {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
2024-01-20 15:15:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async $getFederationAuditStatus(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const auditStatus = await elementsParser.$getAuditStatus();
|
|
|
|
res.header('Pragma', 'public');
|
|
|
|
res.header('Cache-control', 'public');
|
|
|
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 30).toUTCString());
|
|
|
|
res.json(auditStatus);
|
|
|
|
} catch (e) {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
2024-01-20 15:15:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async $getFederationAddresses(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const federationAddresses = await elementsParser.$getFederationAddresses();
|
|
|
|
res.header('Pragma', 'public');
|
|
|
|
res.header('Cache-control', 'public');
|
|
|
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 30).toUTCString());
|
|
|
|
res.json(federationAddresses);
|
|
|
|
} catch (e) {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
2024-01-20 15:15:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-09 16:26:59 +01:00
|
|
|
private async $getFederationAddressesNumber(req: Request, res: Response) {
|
2024-01-20 15:15:15 +01:00
|
|
|
try {
|
2024-02-09 16:26:59 +01:00
|
|
|
const federationAddresses = await elementsParser.$getFederationAddressesNumber();
|
2024-01-20 15:15:15 +01:00
|
|
|
res.header('Pragma', 'public');
|
|
|
|
res.header('Cache-control', 'public');
|
2024-02-09 16:26:59 +01:00
|
|
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 30).toUTCString());
|
2024-01-20 15:15:15 +01:00
|
|
|
res.json(federationAddresses);
|
|
|
|
} catch (e) {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
2024-01-20 15:15:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async $getFederationUtxos(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const federationUtxos = await elementsParser.$getFederationUtxos();
|
|
|
|
res.header('Pragma', 'public');
|
|
|
|
res.header('Cache-control', 'public');
|
|
|
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 30).toUTCString());
|
|
|
|
res.json(federationUtxos);
|
|
|
|
} catch (e) {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
2024-01-20 15:15:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-27 16:39:28 +01:00
|
|
|
private async $getExpiredUtxos(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const expiredUtxos = await elementsParser.$getExpiredUtxos();
|
|
|
|
res.header('Pragma', 'public');
|
|
|
|
res.header('Cache-control', 'public');
|
|
|
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 30).toUTCString());
|
|
|
|
res.json(expiredUtxos);
|
|
|
|
} catch (e) {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
2024-02-27 16:39:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-09 16:26:59 +01:00
|
|
|
private async $getFederationUtxosNumber(req: Request, res: Response) {
|
2024-01-20 15:15:15 +01:00
|
|
|
try {
|
2024-02-09 16:26:59 +01:00
|
|
|
const federationUtxos = await elementsParser.$getFederationUtxosNumber();
|
2024-01-20 15:15:15 +01:00
|
|
|
res.header('Pragma', 'public');
|
|
|
|
res.header('Cache-control', 'public');
|
2024-02-09 16:26:59 +01:00
|
|
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 30).toUTCString());
|
2024-01-20 15:15:15 +01:00
|
|
|
res.json(federationUtxos);
|
|
|
|
} catch (e) {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
2024-01-20 15:15:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-27 16:39:28 +01:00
|
|
|
private async $getEmergencySpentUtxos(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const emergencySpentUtxos = await elementsParser.$getEmergencySpentUtxos();
|
|
|
|
res.header('Pragma', 'public');
|
|
|
|
res.header('Cache-control', 'public');
|
|
|
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 30).toUTCString());
|
|
|
|
res.json(emergencySpentUtxos);
|
|
|
|
} catch (e) {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
2024-02-27 16:39:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async $getEmergencySpentUtxosStats(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const emergencySpentUtxos = await elementsParser.$getEmergencySpentUtxosStats();
|
|
|
|
res.header('Pragma', 'public');
|
|
|
|
res.header('Cache-control', 'public');
|
|
|
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 30).toUTCString());
|
|
|
|
res.json(emergencySpentUtxos);
|
|
|
|
} catch (e) {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
2024-02-27 16:39:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-12 11:34:47 +01:00
|
|
|
private async $getPegsList(req: Request, res: Response) {
|
2024-01-30 11:11:30 +01:00
|
|
|
try {
|
2024-02-12 11:34:47 +01:00
|
|
|
const recentPegs = await elementsParser.$getPegsList(parseInt(req.params?.count));
|
2024-01-30 11:11:30 +01:00
|
|
|
res.header('Pragma', 'public');
|
|
|
|
res.header('Cache-control', 'public');
|
|
|
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 30).toUTCString());
|
2024-02-12 11:34:47 +01:00
|
|
|
res.json(recentPegs);
|
2024-01-30 11:11:30 +01:00
|
|
|
} catch (e) {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
2024-01-30 11:11:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-06 17:35:02 +01:00
|
|
|
private async $getPegsVolumeDaily(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const pegsVolume = await elementsParser.$getPegsVolumeDaily();
|
|
|
|
res.header('Pragma', 'public');
|
|
|
|
res.header('Cache-control', 'public');
|
|
|
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 30).toUTCString());
|
|
|
|
res.json(pegsVolume);
|
|
|
|
} catch (e) {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
2024-02-06 17:35:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-12 11:34:47 +01:00
|
|
|
private async $getPegsCount(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const pegsCount = await elementsParser.$getPegsCount();
|
|
|
|
res.header('Pragma', 'public');
|
|
|
|
res.header('Cache-control', 'public');
|
|
|
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 30).toUTCString());
|
|
|
|
res.json(pegsCount);
|
|
|
|
} catch (e) {
|
2024-08-22 19:51:28 +00:00
|
|
|
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
2024-02-12 11:34:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 19:15:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new LiquidRoutes();
|