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.
389 lines
11 KiB
389 lines
11 KiB
// placeholder of API peers response
|
|
|
|
var coin_types = ['BTC', 'BTCD'];
|
|
|
|
|
|
var response = {
|
|
"peers": [
|
|
{
|
|
"ipaddr": "127.0.0.1",
|
|
"protover": 60013,
|
|
"relay": 1,
|
|
"height": 854849,
|
|
"rank": 0,
|
|
"usock": 4,
|
|
"ready": 1449777119,
|
|
"msgcounts": {
|
|
"version": 1,
|
|
"verack": 1,
|
|
"getaddr": 0,
|
|
"addr": 2,
|
|
"inv": 0,
|
|
"getdata": 0,
|
|
"notfound": 0,
|
|
"getblocks": 0,
|
|
"getheaders": 0,
|
|
"headers": 0,
|
|
"tx": 0,
|
|
"block": 0,
|
|
"mempool": 0,
|
|
"ping": 0,
|
|
"pong": 0,
|
|
"reject": 0,
|
|
"filterload": 0,
|
|
"filteradd": 0,
|
|
"filterclear": 0,
|
|
"merkleblock": 0,
|
|
"alert": 0
|
|
}
|
|
},
|
|
{
|
|
"ipaddr": "234.0.0.1",
|
|
"protover": 50013,
|
|
"relay": 1,
|
|
"height": 584849,
|
|
"rank": 1,
|
|
"usock": 4,
|
|
"ready": 1449777119,
|
|
"msgcounts": {
|
|
"version": 1,
|
|
"verack": 1,
|
|
"getaddr": 0,
|
|
"addr": 2,
|
|
"inv": 0,
|
|
"getdata": 0,
|
|
"notfound": 0,
|
|
"getblocks": 0,
|
|
"getheaders": 0,
|
|
"headers": 0,
|
|
"tx": 0,
|
|
"block": 0,
|
|
"mempool": 0,
|
|
"ping": 0,
|
|
"pong": 0,
|
|
"reject": 0,
|
|
"filterload": 0,
|
|
"filteradd": 0,
|
|
"filterclear": 0,
|
|
"merkleblock": 0,
|
|
"alert": 0
|
|
}
|
|
},
|
|
{
|
|
"ipaddr": "345.0.0.1",
|
|
"protover": 62013,
|
|
"relay": 1,
|
|
"height": 354849,
|
|
"rank": 1,
|
|
"usock": 4,
|
|
"ready": 1449777119,
|
|
"msgcounts": {
|
|
"version": 1,
|
|
"verack": 1,
|
|
"getaddr": 0,
|
|
"addr": 2,
|
|
"inv": 0,
|
|
"getdata": 0,
|
|
"notfound": 0,
|
|
"getblocks": 0,
|
|
"getheaders": 0,
|
|
"headers": 0,
|
|
"tx": 0,
|
|
"block": 0,
|
|
"mempool": 0,
|
|
"ping": 0,
|
|
"pong": 0,
|
|
"reject": 0,
|
|
"filterload": 0,
|
|
"filteradd": 0,
|
|
"filterclear": 0,
|
|
"merkleblock": 0,
|
|
"alert": 0
|
|
}
|
|
},
|
|
{
|
|
"ipaddr": "567.0.0.1",
|
|
"protover": 30013,
|
|
"relay": 1,
|
|
"height": 454849,
|
|
"rank": 0,
|
|
"usock": 4,
|
|
"ready": 1449777119,
|
|
"msgcounts": {
|
|
"version": 1,
|
|
"verack": 1,
|
|
"getaddr": 0,
|
|
"addr": 2,
|
|
"inv": 0,
|
|
"getdata": 0,
|
|
"notfound": 0,
|
|
"getblocks": 0,
|
|
"getheaders": 0,
|
|
"headers": 0,
|
|
"tx": 0,
|
|
"block": 0,
|
|
"mempool": 0,
|
|
"ping": 0,
|
|
"pong": 0,
|
|
"reject": 0,
|
|
"filterload": 0,
|
|
"filteradd": 0,
|
|
"filterclear": 0,
|
|
"merkleblock": 0,
|
|
"alert": 0
|
|
}
|
|
},
|
|
{
|
|
"ipaddr": "321.0.0.1",
|
|
"protover": 55013,
|
|
"relay": 1,
|
|
"height": 444849,
|
|
"rank": 2,
|
|
"usock": 4,
|
|
"ready": 1449777119,
|
|
"msgcounts": {
|
|
"version": 1,
|
|
"verack": 1,
|
|
"getaddr": 0,
|
|
"addr": 2,
|
|
"inv": 0,
|
|
"getdata": 0,
|
|
"notfound": 0,
|
|
"getblocks": 0,
|
|
"getheaders": 0,
|
|
"headers": 0,
|
|
"tx": 0,
|
|
"block": 0,
|
|
"mempool": 0,
|
|
"ping": 0,
|
|
"pong": 0,
|
|
"reject": 0,
|
|
"filterload": 0,
|
|
"filteradd": 0,
|
|
"filterclear": 0,
|
|
"merkleblock": 0,
|
|
"alert": 0
|
|
}
|
|
},
|
|
{
|
|
"ipaddr": "764.0.0.1",
|
|
"protover": 60013,
|
|
"relay": 1,
|
|
"height": 134849,
|
|
"rank": 2,
|
|
"usock": 4,
|
|
"ready": 3249777119,
|
|
"msgcounts": {
|
|
"version": 1,
|
|
"verack": 1,
|
|
"getaddr": 0,
|
|
"addr": 2,
|
|
"inv": 0,
|
|
"getdata": 0,
|
|
"notfound": 0,
|
|
"getblocks": 0,
|
|
"getheaders": 0,
|
|
"headers": 0,
|
|
"tx": 0,
|
|
"block": 0,
|
|
"mempool": 0,
|
|
"ping": 0,
|
|
"pong": 0,
|
|
"reject": 0,
|
|
"filterload": 0,
|
|
"filteradd": 0,
|
|
"filterclear": 0,
|
|
"merkleblock": 0,
|
|
"alert": 0
|
|
}
|
|
},
|
|
{
|
|
"ipaddr": "327.0.0.1",
|
|
"protover": 60013,
|
|
"relay": 1,
|
|
"height": 854849,
|
|
"rank": 3,
|
|
"usock": 4,
|
|
"ready": 1449777119,
|
|
"msgcounts": {
|
|
"version": 1,
|
|
"verack": 1,
|
|
"getaddr": 0,
|
|
"addr": 2,
|
|
"inv": 0,
|
|
"getdata": 0,
|
|
"notfound": 0,
|
|
"getblocks": 0,
|
|
"getheaders": 0,
|
|
"headers": 0,
|
|
"tx": 0,
|
|
"block": 0,
|
|
"mempool": 0,
|
|
"ping": 0,
|
|
"pong": 0,
|
|
"reject": 0,
|
|
"filterload": 0,
|
|
"filteradd": 0,
|
|
"filterclear": 0,
|
|
"merkleblock": 0,
|
|
"alert": 0
|
|
}
|
|
},
|
|
{
|
|
"ipaddr": "765.0.0.1",
|
|
"protover": 60013,
|
|
"relay": 1,
|
|
"height": 854849,
|
|
"rank": 0,
|
|
"usock": 4,
|
|
"ready": 1449777119,
|
|
"msgcounts": {
|
|
"version": 1,
|
|
"verack": 1,
|
|
"getaddr": 0,
|
|
"addr": 2,
|
|
"inv": 0,
|
|
"getdata": 0,
|
|
"notfound": 0,
|
|
"getblocks": 0,
|
|
"getheaders": 0,
|
|
"headers": 0,
|
|
"tx": 0,
|
|
"block": 0,
|
|
"mempool": 0,
|
|
"ping": 0,
|
|
"pong": 0,
|
|
"reject": 0,
|
|
"filterload": 0,
|
|
"filteradd": 0,
|
|
"filterclear": 0,
|
|
"merkleblock": 0,
|
|
"alert": 0
|
|
}
|
|
},
|
|
{
|
|
"ipaddr": "255.0.0.1",
|
|
"protover": 60013,
|
|
"relay": 1,
|
|
"height": 854849,
|
|
"rank": 2,
|
|
"usock": 4,
|
|
"ready": 1449777119,
|
|
"msgcounts": {
|
|
"version": 1,
|
|
"verack": 1,
|
|
"getaddr": 0,
|
|
"addr": 2,
|
|
"inv": 0,
|
|
"getdata": 0,
|
|
"notfound": 0,
|
|
"getblocks": 0,
|
|
"getheaders": 0,
|
|
"headers": 0,
|
|
"tx": 0,
|
|
"block": 0,
|
|
"mempool": 0,
|
|
"ping": 0,
|
|
"pong": 0,
|
|
"reject": 0,
|
|
"filterload": 0,
|
|
"filteradd": 0,
|
|
"filterclear": 0,
|
|
"merkleblock": 0,
|
|
"alert": 0
|
|
}
|
|
}
|
|
],
|
|
"maxpeers": 32,
|
|
"coin": "BTCD",
|
|
"tag": "12697016274367621769"
|
|
};
|
|
|
|
var favPeers = [];
|
|
|
|
var getHtmlRow = function (id, peer) {
|
|
var row = '';
|
|
row = '<tr data-id="' + id.toString() + '">';
|
|
row += '<td>' + peer.ipaddr + '</td>';
|
|
row += '<td>' + peer.cointype + '</td>';
|
|
row += '<td>' + peer.height + '</td>';
|
|
row += '<td>' + peer.rank + '</td>';
|
|
if ($.inArray(id, favPeers) == -1) {
|
|
row += '<td><button class="btn btn-xs btn-success btn-raised addPeerToFav" data-id="' + id.toString() + '"> + Favorite</button></td>';
|
|
// row += '<td><i class="material-icons addPeerToFav" data-id="' + id.toString() + '">bookmark_border</i></td>';
|
|
}
|
|
else {
|
|
row += '<td><button class="btn btn-xs btn-danger btn-raised removePeerFromFav" data-id="' + id.toString() + '"> - Unfavorite</button></td>';
|
|
// row += '<td><i class="material-icons removePeerFromFav" data-id="' + id.toString() + '">bookmark</i></td>'
|
|
}
|
|
|
|
row += '</tr>';
|
|
return row;
|
|
};
|
|
|
|
var addPeerToFav = function (id) {
|
|
if ($.inArray(id, favPeers) == -1) {
|
|
favPeers.push(parseInt(id));
|
|
console.log('@ peer faved', favPeers);
|
|
}
|
|
|
|
// refresh grid
|
|
renderPeersGrid(false);
|
|
};
|
|
|
|
var removePeerFromFav = function (id) {
|
|
for (var index = 0; index < favPeers.length; index++) {
|
|
if (id == favPeers[index]) {
|
|
favPeers.splice(index, 1);
|
|
console.log('@ peer unfaved', favPeers);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// refresh grid
|
|
renderPeersGrid(document.getElementById('cbShowFavoritePeers').checked);
|
|
};
|
|
|
|
var renderPeersGrid = function (favoritesOnly = false) {
|
|
|
|
console.log('@ peer print grid')
|
|
|
|
var peersTableAllHtml = '';
|
|
|
|
for (var i = 0; i < response.peers.length; i++) {
|
|
|
|
if (favoritesOnly == true && $.inArray(i, favPeers) == -1) {
|
|
continue;
|
|
}
|
|
|
|
response.peers[i].cointype = response.coin
|
|
peersTableAllHtml += getHtmlRow(i, response.peers[i]);
|
|
}
|
|
document.getElementById('peersTableBody').innerHTML = peersTableAllHtml;
|
|
};
|
|
|
|
document.getElementById('cbShowFavoritePeers').onclick = function () {
|
|
// if (document.getElementById('cbShowFavoritePeers').checked == true) {
|
|
|
|
// // document.getElementById('peersTableBody').style.display = 'none';
|
|
// // document.getElementById('peersTable_fav').style.display = 'block';
|
|
|
|
// $('#peersTableBody').hide();
|
|
// $('#peersTable_fav').show();
|
|
// }
|
|
// else {
|
|
|
|
// // document.getElementById('peersTableBody').style.display = 'block';
|
|
// // document.getElementById('peersTable_fav').style.display = 'none';
|
|
|
|
// $('#peersTableBody').show();
|
|
// $('#peersTable_fav').hide();
|
|
// }
|
|
|
|
renderPeersGrid(document.getElementById('cbShowFavoritePeers').checked);
|
|
};
|
|
|
|
var startPeerManagement = function () {
|
|
renderPeersGrid();
|
|
|
|
};
|