const axios = require('axios')
exports.endpoint = async (request, response) => {
const d = await axios.get('https://api.xrpscan.com/api/v1/validatorregistry')
const mapped = d.data.filter(r => r.chain === 'main' && r.unl && r.unl.length > 0).map(r => {
return {
domain: r.domain || r.domain_legacy,
last_seen: Math.abs((Number(new Date(r.last_seen)) - Number(new Date())) / 1000)
}
})
const offlineValidators = mapped.filter(d => d.last_seen > 6).map(d => d.domain)
response.end(JSON.stringify({
offlineValidators,
onlineValidators: mapped.filter(m => offlineValidators.indexOf(m.domain) < 0).map(d => d.domain)
}))
}