2018-12-14 18:42:37 +01:00
|
|
|
const chainquery = require('chainquery').default;
|
2018-09-26 03:20:59 +02:00
|
|
|
const getClaimData = require('server/utils/getClaimData');
|
2018-04-27 18:54:36 +02:00
|
|
|
const { returnPaginatedChannelClaims } = require('./channelPagination.js');
|
|
|
|
|
2019-01-24 01:22:32 +01:00
|
|
|
const getChannelClaims = async (channelName, channelLongId, page) => {
|
|
|
|
let channelShortId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(
|
|
|
|
channelLongId,
|
|
|
|
channelName
|
|
|
|
);
|
2018-10-22 21:36:57 +02:00
|
|
|
let channelClaims;
|
2019-01-24 01:22:32 +01:00
|
|
|
if (channelLongId) {
|
2019-01-26 01:37:07 +01:00
|
|
|
channelClaims = await chainquery.claim.queries.getAllChannelClaims(channelLongId);
|
2018-10-22 21:36:57 +02:00
|
|
|
}
|
2019-01-24 01:22:32 +01:00
|
|
|
/*
|
|
|
|
Put mempool unconfirmed claims at the beginning
|
|
|
|
*/
|
2018-11-12 14:25:48 +01:00
|
|
|
const split = channelClaims.reduce(
|
2019-01-24 01:22:32 +01:00
|
|
|
(acc, val) =>
|
|
|
|
val.dataValues.height === 0
|
|
|
|
? { ...acc, zero: acc.zero.concat(val) }
|
|
|
|
: { ...acc, nonzero: acc.nonzero.concat(val) },
|
2018-11-12 14:25:48 +01:00
|
|
|
{ zero: [], nonzero: [] }
|
|
|
|
);
|
|
|
|
channelClaims = split.zero.concat(split.nonzero);
|
|
|
|
|
2019-01-24 01:22:32 +01:00
|
|
|
const processingChannelClaims = channelClaims
|
|
|
|
? channelClaims.map(claim => getClaimData(claim, channelName, channelShortId))
|
|
|
|
: [];
|
2018-10-10 18:28:53 +02:00
|
|
|
const processedChannelClaims = await Promise.all(processingChannelClaims);
|
2018-09-26 03:20:59 +02:00
|
|
|
|
2019-01-24 01:22:32 +01:00
|
|
|
return returnPaginatedChannelClaims(channelName, channelShortId, processedChannelClaims, page);
|
2018-04-27 18:54:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = getChannelClaims;
|