2018-10-30 21:53:29 +01:00
|
|
|
const { handleErrorResponse } = require('server/controllers/utils/errorHandlers.js');
|
|
|
|
const db = require('server/models');
|
2018-12-14 18:42:37 +01:00
|
|
|
const chainquery = require('chainquery').default;
|
2018-03-28 03:25:23 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
route to get a short channel id from long channel Id
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2018-10-30 21:53:29 +01:00
|
|
|
const channelShortIdRoute = async ({ ip, originalUrl, params }, res) => {
|
|
|
|
try {
|
|
|
|
let shortId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(params.longId, params.name).catch(() => false);
|
|
|
|
|
2018-11-11 01:11:12 +01:00
|
|
|
if (!shortId) {
|
2018-10-30 21:53:29 +01:00
|
|
|
shortId = await db.Certificate.getShortChannelIdFromLongChannelId(params.longId, params.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
res.status(200).json(shortId);
|
|
|
|
} catch (error) {
|
|
|
|
handleErrorResponse(originalUrl, ip, error, res);
|
|
|
|
}
|
2018-03-28 03:25:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = channelShortIdRoute;
|