(function() {
var C = window.ExplorerCommon;
async function loadValidators() {
C.setStatus('Loading…', 'warn');
try {
var data = await C.fetchJSON('/api/validators');
var validators = (data && Array.isArray(data.validators)) ? data.validators : [];
var quorum = validators.length > 0 ? Math.floor(2 * validators.length / 3) + 1 : 0;
document.getElementById('valCount').textContent = validators.length;
document.getElementById('quorumCount').textContent = quorum || '—';
var tbody = document.getElementById('valBody');
if (!validators.length) {
tbody.innerHTML = '
| No validators found. |
';
C.setStatus('No validators registered.', 'warn');
return;
}
var rows = '';
validators.forEach(function(v, i) {
var addr = v.address || '—';
var pubKey = v.pub_key || '—';
rows +=
'' +
'| ' + (i + 1) + ' | ' +
'' +
'' +
C.esc(addr) +
'' +
' | ' +
'' +
C.esc(C.short(pubKey, 32)) +
' | ' +
'' +
'' +
' Node' +
'' +
' | ' +
'
';
});
tbody.innerHTML = rows;
C.setStatus(
validators.length + ' validator' + (validators.length !== 1 ? 's' : '') +
' · quorum: ' + quorum,
'ok'
);
C.refreshIcons();
} catch (e) {
C.setStatus('Load failed: ' + e.message, 'err');
}
}
document.getElementById('refreshBtn').addEventListener('click', loadValidators);
loadValidators();
})();