Merge pull request #671 from lbryio/chainqueryExtenalChannels
Allow external channels to load via chainquery
This commit is contained in:
commit
bc58ddcca7
4 changed files with 40 additions and 38 deletions
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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';
|
||||||
|
|
|
@ -6,7 +6,7 @@ const chainquery = require('chainquery');
|
||||||
const getClaimIdByChannel = async (channelName, channelClaimId, claimName) => {
|
const getClaimIdByChannel = async (channelName, channelClaimId, claimName) => {
|
||||||
logger.debug(`getClaimIdByChannel(${channelName}, ${channelClaimId}, ${claimName})`);
|
logger.debug(`getClaimIdByChannel(${channelName}, ${channelClaimId}, ${claimName})`);
|
||||||
|
|
||||||
let channelId = await chainquery.claim.queries.getLongClaimIdFromShortClaimId(channelName, channelClaimId);
|
let channelId = await chainquery.claim.queries.getLongClaimId(channelName, channelClaimId);
|
||||||
|
|
||||||
if(channelId === null) {
|
if(channelId === null) {
|
||||||
channelId = await db.Certificate.getLongChannelId(channelName, channelClaimId);
|
channelId = await db.Certificate.getLongChannelId(channelName, channelClaimId);
|
||||||
|
|
Loading…
Reference in a new issue