scorum.api.setOptions({
url: 'https://prodnet.scorum.com/',
chain_id: "db4007d45f04c1403a7e66a5c66b5b1cdfc2dde8b5335d1d2f116d592ca3dbb1"
});
getProducers()
function filterProds() {
var search = document.getElementById('filter-prods').value;
document.querySelectorAll('.prod-row').forEach(function (row) {
if (search === "")
row.style.display = "table-row";
else if (row.childNodes[3].textContent.indexOf(search) > -1)
row.style.display = "table-row";
else
row.style.display = "none";
});
}
function setVotedFor() {
var account = document.getElementById('scr-account').value;
scorum.api.getAccounts([account], function(err, result) {
document.getElementById('voting-count').innerHTML = 30 - result[0].witness_votes.length;
result[0].witness_votes.forEach(witness => {
document.getElementsByName('vote-prods').forEach(e => {
if(e.value == witness)
e.checked = true;
});
})
});
}
function getProducers() {
var tbody = document.querySelector("#block-producers tbody");
tbody.innerHTML = '';
scorum.api.getWitnessesByVote("", 100, function(err, result) {
result.map((prod, i) => `
|
${prod.owner} |
${prettyNumber(prod.votes)} |
${prod.total_missed} |
${prod.running_version} |
${isOriginal(prod.created)} |
${DelegateURL(prod.url)} |
${isOnline(prod.signing_key)} |
${i+1} |
`)
.forEach(row => tbody.innerHTML += row);
document.getElementsByName('vote-prods').forEach(e => {
e.onclick = function() { processVote(e.value, e.checked); };
});
});
}
function DelegateURL(str) {
if (ValidURL(str))
return 'Link';
else
return '';
}
function ValidURL(str) {
var regex = /(http|https):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%!\-\/]))?/;
if(!regex .test(str)) {
return false;
} else {
return true;
}
}
function isOriginal(date) {
if (date == "1970-01-01T00:00:00")
return "Founder";
else
return date.substr(0, 7);
}
function isOnline(str) {
if (str == "SCR1111111111111111111111111111111114T1Anm")
return "Disabled";
else
return "Processing";
}
function prettyNumber(num) {
num = parseInt(parseInt(num) / 1e10 * 10.00);
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
}
function processVote(witness, approve) {
var account = document.getElementById('scr-account').value;
var wif = document.getElementById('private-key').value;
if(account && wif && witness) {
scorum.broadcast.accountWitnessVote(wif, account, witness, approve, function(err, result) {
document.getElementById('alerts').scrollIntoView();
//console.log(err, result);
if(err) {
document.getElementById('alerts').innerHTML += `${err.message.split('\n')[0]}
`;
} else {
document.getElementById('alerts').innerHTML += ``;
vcount = parseInt(document.getElementById('voting-count').innerHTML);
document.getElementById('voting-count').innerHTML = approve ? vcount - 1 : vcount + 1;
}
});
}
}