From 0915b399dd21ec36cd1d4d850c92943ec8ee4dc2 Mon Sep 17 00:00:00 2001 From: Tim Garrity Date: Thu, 9 Jul 2020 18:35:30 -0400 Subject: [PATCH] Testing iquidus/explorer#363 --- README.md | 1 + lib/database.js | 29 +++++++++------- scripts/peers.js | 88 +++++++++++++----------------------------------- views/layout.pug | 2 +- 4 files changed, 42 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index 45e8f0364..d01307751 100644 --- a/README.md +++ b/README.md @@ -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* diff --git a/lib/database.js b/lib/database.js index c2c222207..9f8221a02 100644 --- a/lib/database.js +++ b/lib/database.js @@ -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) { + 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: '', @@ -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 { diff --git a/scripts/peers.js b/scripts/peers.js index 3e6af6e08..849702eb7 100644 --- a/scripts/peers.js +++ b/scripts/peers.js @@ -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 @@ -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(); }); }); diff --git a/views/layout.pug b/views/layout.pug index 88fa53535..51b002b2a 100644 --- a/views/layout.pug +++ b/views/layout.pug @@ -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());