Skip to content

Commit

Permalink
Testing iquidus#363
Browse files Browse the repository at this point in the history
  • Loading branch information
uaktags committed Jul 9, 2020
1 parent 822e633 commit 0915b39
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 78 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Plenty of code was inspired or pulled from various sources in the community incl
* [Sugarchain Explorer](https://1explorer.sugarchain.org/)
* [Florincoin](https://florincoin.info/info)
* [Maxcoin Explorer 1](https://explorer.maxcoinproject.net/)
* [Litecoin Plus Explorer 1](http://explorer.litecoinplus.co/)


*Note: If you would like your instance mentioned here contact me*
Expand Down
29 changes: 17 additions & 12 deletions lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,28 +499,33 @@ module.exports = {
},

get_last_txs_ajax: function(start, length, min, cb) {
Tx.countDocuments({'total': {$gte: min}}, function(err, count){
Tx.find({'total': {$gte: min}}).sort({blockindex: 'desc'}).skip(Number(start)).limit(Number(length)).exec(function(err, txs){
if (err) {
return cb(err);
} else {
return cb(txs, count);
}
});
lib.get_blockcount(function(blockcount) {

This comment has been minimized.

Copy link
@TheHolyRoger

TheHolyRoger Jul 16, 2020

Worth adding a comment in here to note that node blockcount can be higher than what's indexed in the explorer, but for the purposes of this query it's not an issue

var blockFrom = blockcount - Number(start);
if (settings.index.last_txs != 0) {
blockcount = settings.index.last_txs;
}
var q = {$and: [{total: {$gt: Number(min)}}, {blockindex: {$lte: blockFrom}}]};
Tx.find(q).sort({blockindex: -1}).limit(Number(length)).exec(function(err, txs) {
if (err) {
return cb(err);
} else {
return cb(txs, blockcount);
}
});
});
},

get_address_txs_ajax: function(hash, start, length, cb) {
var totalCount = 0;
AddressTx.find({a_id: hash}).countDocuments({}, function(err, count){
AddressTx.find({a_id: hash}).count(function(err, count){
if(err) {
return cb(err);
} else {
totalCount = count;
AddressTx.aggregate([
{ $match: { a_id: hash } },
{ $match: { a_id: hash } },
{ $sort: {blockindex: -1} },
{ $skip: Number(start) },
{ $skip: Number(start) },
{
$group: {
_id: '',
Expand All @@ -538,7 +543,7 @@ module.exports = {
if (err) {
return cb(err);
} else {
AddressTx.find({a_id: hash}).sort({blockindex: 'desc'}).skip(Number(start)).limit(Number(length)).exec(function (err, address_tx) {
AddressTx.find({a_id: hash}).sort({blockindex: -1}).skip(Number(start)).limit(Number(length)).exec(function (err, address_tx) {
if (err) {
return cb(err);
} else {
Expand Down
88 changes: 23 additions & 65 deletions scripts/peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ mongoose.connect(dbString, {
console.log('Aborting');
exit();
} else {
var peers = Array();
var cnt = 0;
request({
uri: 'http://127.0.0.1:' + settings.port + '/api/getpeerinfo',
json: true
Expand All @@ -208,73 +210,29 @@ mongoose.connect(dbString, {
var i = loop.iteration();
var address = body[i].addr.split(':')[0];
var port = body[i].addr.split(':')[1];
db.find_peer(address, function(peer) {
if (peer) {
if (isNaN(peer['port']) || peer['port'].length < 2 || peer['country'].length < 1) {
db.drop_peers(function() {
console.log('Saved peers missing ports or country, dropping peers. Re-reun this script afterwards.');
exit();
});
}
// peer already exists
loop.next();
} else {
request({
uri: 'https://freegeoip.app/json/' + address,
json: true
}, function(error, response, geo) {
db.create_peer({
address: address,
port: port,
protocol: body[i].version,
version: body[i].subver.replace('/', '').replace('/', ''),
country: geo.country_name
}, function() {
loop.next();
});
});
request({uri: 'https://freegeoip.app/json/' + address, json: true}, function (error, response, geo) {
if (address.startsWith('10.') || address.startsWith('192.168') || address.startsWith('172.16')) {
geo.country_name = '[private address]';
}
//end
var version = body[i].subver.replace('/', '').replace('/', '');
var semver = version.split(":")[1];
livepeers[i] = address;
db.find_peers(address, function(peer) {
if (peer.length) {
for (i = 0; i < peer.length; i++) {
// cmp(a,b)
// result 1 = a is greater than b
// result 0 = a is the same as b
// result -1 = a is less than b
if (cmp(peer[i].version.split(":")[1], semver) == -1) {
if (settings.peers.purge_on_run != true) {
db.delete_peer({
_id: peer[i]._id
});
}
create_peers(address, body[i].version, version);
console.log('Delete the db version:', peer[i].version.split(":")[1]); //remove
} else if (cmp(peer[i].version.split(":")[1], semver) == 0) {
console.log('Do nothing, they\'re the same');
} else {
//db.delete_peer({_id:peer[i]._id});
console.log('This should never occur, Live Version:', semver, " Is less than:", peer[i].version.split(":")[1]); //remove
}
}
loop.next();
} else {
create_peers(address, body[i].version, version);
peers[cnt++] = {
address: address,
port: port,
protocol: body[i].version,
version: body[i].subver.replace('/', '').replace('/', ''),
country: geo.country_name
};
loop.next();
});
}, function() {
// insert all at once after creation
db.drop_peers(function() {
console.log('Dropped, rebuilding...');
lib.syncLoop(cnt, function (loop) {
var i = loop.iteration();
db.create_peer(peers[i], function() {
loop.next();
}
});
}, function() {
db.get_peers(function(peers) {
for (var i = 0; i < peers.length; i++) {
if (!livepeers.includes(peers[i].address)) {
db.delete_peer({
address: peers[i].address
});
}
}
});
}, function() {
exit();
});
});
Expand Down
2 changes: 1 addition & 1 deletion views/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ html
function update_stats(){
$.ajax({url: '/ext/summary', success: function(json){
$("#supply").text(parseInt(parseFloat(json.data[0].supply).toFixed(0)).toLocaleString('en'));
$("#difficulty").text(parseFloat(json.data[0].difficulty).toFixed(2));
$("#difficulty").text(json.data[0].difficulty);
$("#difficultyHybrid").text(json.data[0].difficultyHybrid);
$("#hashrate").text(parseFloat(json.data[0].hashrate).toLocaleString('en'));
$("#lastPrice").text(parseFloat(json.data[0].lastPrice).toFixed(8) + ' #{settings.markets.exchange}'.toUpperCase());
Expand Down

0 comments on commit 0915b39

Please sign in to comment.