diff --git a/README.md b/README.md index 1720cf756..b20e39a2f 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ An open source block explorer written in node.js. * [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 f2f8afdbf..298278d53 100644 --- a/lib/database.js +++ b/lib/database.js @@ -435,28 +435,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: '', @@ -474,7 +479,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 17909f00e..c4bbddfec 100644 --- a/scripts/peers.js +++ b/scripts/peers.js @@ -23,37 +23,40 @@ mongoose.connect(dbString, function(err) { console.log('Aborting'); exit(); } else { + var peers = Array(); + var cnt = 0; request({uri: 'http://127.0.0.1:' + settings.port + '/api/getpeerinfo', json: true}, function (error, response, body) { lib.syncLoop(body.length, function (loop) { 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]'; } + peers[cnt++] = { + address: address, + port: port, + protocol: body[i].version, + version: body[i].subver.replace('/', '').replace('/', ''), + country: geo.country_name + }; + loop.next(); }); }, function() { - exit(); + + // 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() { + 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());