2018-10-30 21:53:29 +01:00
|
|
|
const db = require('server/models');
|
2018-12-14 18:42:37 +01:00
|
|
|
const chainquery = require('chainquery').default;
|
2018-04-27 18:54:36 +02:00
|
|
|
|
2018-10-30 21:53:29 +01:00
|
|
|
const getChannelData = async (channelName, channelClaimId) => {
|
|
|
|
let longChannelClaimId = await chainquery.claim.queries.getLongClaimId(channelName, channelClaimId).catch(() => false);
|
|
|
|
|
2018-11-11 01:11:12 +01:00
|
|
|
if (!longChannelClaimId) {
|
2018-10-30 21:53:29 +01:00
|
|
|
// Allow an error to throw here if this fails
|
|
|
|
longChannelClaimId = await db.Certificate.getLongChannelId(channelName, channelClaimId);
|
|
|
|
}
|
|
|
|
|
|
|
|
let shortChannelClaimId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(longChannelClaimId, channelName).catch(() => false);
|
|
|
|
|
2018-11-11 01:11:12 +01:00
|
|
|
if (!shortChannelClaimId) {
|
2018-10-30 21:53:29 +01:00
|
|
|
shortChannelClaimId = await db.Certificate.getShortChannelIdFromLongChannelId(longChannelClaimId, channelName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
channelName,
|
|
|
|
longChannelClaimId,
|
|
|
|
shortChannelClaimId,
|
|
|
|
};
|
2018-04-27 18:54:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = getChannelData;
|