Allow external channels to load via chainquery

This commit is contained in:
Shawn 2018-10-30 15:53:29 -05:00
parent a4b02b9f4b
commit 86a693b4f4
3 changed files with 39 additions and 37 deletions

View file

@ -1,28 +1,25 @@
const db = require('../../../../models'); const db = require('server/models');
const chainquery = require('chainquery');
const getChannelData = (channelName, channelClaimId) => { const getChannelData = async (channelName, channelClaimId) => {
return new Promise((resolve, reject) => { let longChannelClaimId = await chainquery.claim.queries.getLongClaimId(channelName, channelClaimId).catch(() => false);
let longChannelClaimId;
// 1. get the long channel Id (make sure channel exists) if(!longChannelClaimId) {
db.Certificate // Allow an error to throw here if this fails
.getLongChannelId(channelName, channelClaimId) longChannelClaimId = await db.Certificate.getLongChannelId(channelName, channelClaimId);
.then(fullClaimId => { }
longChannelClaimId = fullClaimId;
return db let shortChannelClaimId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(longChannelClaimId, channelName).catch(() => false);
.Certificate
.getShortChannelIdFromLongChannelId(fullClaimId, channelName); if(!shortChannelClaimId) {
}) shortChannelClaimId = await db.Certificate.getShortChannelIdFromLongChannelId(longChannelClaimId, channelName);
.then(shortChannelClaimId => { }
resolve({
channelName, return {
longChannelClaimId, channelName,
shortChannelClaimId, longChannelClaimId,
}); shortChannelClaimId,
}) };
.catch(error => {
reject(error);
});
});
}; };
module.exports = getChannelData; module.exports = getChannelData;

View file

@ -1,5 +1,6 @@
const { handleErrorResponse } = require('../../../utils/errorHandlers.js'); const { handleErrorResponse } = require('server/controllers/utils/errorHandlers.js');
const db = require('../../../../models'); const db = require('server/models');
const chainquery = require('chainquery');
/* /*
@ -7,14 +8,18 @@ route to get a short channel id from long channel Id
*/ */
const channelShortIdRoute = ({ ip, originalUrl, params }, res) => { const channelShortIdRoute = async ({ ip, originalUrl, params }, res) => {
db.Certificate.getShortChannelIdFromLongChannelId(params.longId, params.name) try {
.then(shortId => { let shortId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(params.longId, params.name).catch(() => false);
res.status(200).json(shortId);
}) if(!shortId) {
.catch(error => { shortId = await db.Certificate.getShortChannelIdFromLongChannelId(params.longId, params.name);
handleErrorResponse(originalUrl, ip, error, res); }
});
res.status(200).json(shortId);
} catch (error) {
handleErrorResponse(originalUrl, ip, error, res);
}
}; };
module.exports = channelShortIdRoute; module.exports = channelShortIdRoute;

View file

@ -1,9 +1,9 @@
const db = require('../../../../models'); const db = require('server/models');
const chainquery = require('chainquery'); const chainquery = require('chainquery');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js'); const { handleErrorResponse } = require('server/controllers/utils/errorHandlers.js');
const getClaimId = require('../../../utils/getClaimId.js'); const getClaimId = require('server/controllers/utils/getClaimId.js');
const NO_CHANNEL = 'NO_CHANNEL'; const NO_CHANNEL = 'NO_CHANNEL';
const NO_CLAIM = 'NO_CLAIM'; const NO_CLAIM = 'NO_CLAIM';