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