You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.1 KiB
74 lines
2.1 KiB
|
|
|
|
getheads();
|
|
function getheads() {
|
|
let promised = fetch(api_url + 'getheads').
|
|
then(resp => resp.json()).
|
|
then(obj => {
|
|
let elem = document.getElementById('json');
|
|
elem.innerText = JSON.stringify(obj);
|
|
|
|
let list = '<ul>';
|
|
for (let b of obj.HEADs) {
|
|
console.log('getheads.b:',b);
|
|
let blk_url = api_url + `getblock?hash=${b.bkhash}`;
|
|
let content_url = api_url + `getblock?addr=${b.bkaddr}`;
|
|
let peerid = b.bkcontent.audit.peerid;
|
|
let whois_url = api_url + `whois?pub=${peerid}`
|
|
list += `<li><a href="${blk_url}">${b.bkhash}</a> by <a href="${whois_url}">${peerid}</a>: `+
|
|
`<a href="${content_url}">${b.bkaddr}</a> ${b.bkprev} pow:${b.pow}</li>`;
|
|
}
|
|
list += '</ul>';
|
|
elem = document.getElementById('list');
|
|
elem.innerHTML = list;
|
|
|
|
return obj;
|
|
}).
|
|
catch(console.error);
|
|
promised.then(obj => { console.log('obj:',obj); return obj; });
|
|
|
|
}
|
|
|
|
|
|
// ----------------------------------------------------
|
|
|
|
async function getnodes() {
|
|
let config = await fetch(api_url + 'config').
|
|
then(resp => resp.json()).
|
|
then(obj => { return obj.config }).
|
|
catch(console.error);
|
|
console.log('nodes.config:',config);
|
|
|
|
let n = 1;
|
|
let list = '<ul>';
|
|
let nodes = [];
|
|
for (node of config.nodes) {
|
|
console.log('nodes.node:',node);
|
|
let [ip,port] = node.split(':');
|
|
let info = await get_info(node);
|
|
nodes.push(info);
|
|
let url=`http://${node}`;
|
|
let status='offline';
|
|
let info_url = `${url}${api_url}getinfo`;
|
|
list += `<li>node${n} (:${port}) <a href="${url}">${node}</a> ${status} <a href="${info_url}">information</a></li>\n`;
|
|
console.log('nodes.info:',info);
|
|
n++;
|
|
}
|
|
list += '</ul>';
|
|
let elem = document.getElementById('list');
|
|
elem.innerHTML = list;
|
|
return nodes;
|
|
}
|
|
function get_info(node) {
|
|
let [ip,port] = node.split(':');
|
|
let remote_api_url = `http://${node}${api_url}`;
|
|
let promised = fetch(remote_api_url + 'getinfo').
|
|
then(resp => resp.json).
|
|
then(obj => { let info = obj.info; return info; }).
|
|
catch(console.error);
|
|
return promised;
|
|
}
|
|
|
|
|
|
|
|
console.log('heads.js loaded');
|