Skip to content

Commit 0915b39

Browse files
committed
Testing iquidus#363
1 parent 822e633 commit 0915b39

4 files changed

Lines changed: 42 additions & 78 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Plenty of code was inspired or pulled from various sources in the community incl
2828
* [Sugarchain Explorer](https://1explorer.sugarchain.org/)
2929
* [Florincoin](https://florincoin.info/info)
3030
* [Maxcoin Explorer 1](https://explorer.maxcoinproject.net/)
31+
* [Litecoin Plus Explorer 1](http://explorer.litecoinplus.co/)
3132

3233

3334
*Note: If you would like your instance mentioned here contact me*

lib/database.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -499,28 +499,33 @@ module.exports = {
499499
},
500500

501501
get_last_txs_ajax: function(start, length, min, cb) {
502-
Tx.countDocuments({'total': {$gte: min}}, function(err, count){
503-
Tx.find({'total': {$gte: min}}).sort({blockindex: 'desc'}).skip(Number(start)).limit(Number(length)).exec(function(err, txs){
504-
if (err) {
505-
return cb(err);
506-
} else {
507-
return cb(txs, count);
508-
}
509-
});
502+
lib.get_blockcount(function(blockcount) {
503+
var blockFrom = blockcount - Number(start);
504+
if (settings.index.last_txs != 0) {
505+
blockcount = settings.index.last_txs;
506+
}
507+
var q = {$and: [{total: {$gt: Number(min)}}, {blockindex: {$lte: blockFrom}}]};
508+
Tx.find(q).sort({blockindex: -1}).limit(Number(length)).exec(function(err, txs) {
509+
if (err) {
510+
return cb(err);
511+
} else {
512+
return cb(txs, blockcount);
513+
}
514+
});
510515
});
511516
},
512517

513518
get_address_txs_ajax: function(hash, start, length, cb) {
514519
var totalCount = 0;
515-
AddressTx.find({a_id: hash}).countDocuments({}, function(err, count){
520+
AddressTx.find({a_id: hash}).count(function(err, count){
516521
if(err) {
517522
return cb(err);
518523
} else {
519524
totalCount = count;
520525
AddressTx.aggregate([
521-
{ $match: { a_id: hash } },
526+
{ $match: { a_id: hash } },
522527
{ $sort: {blockindex: -1} },
523-
{ $skip: Number(start) },
528+
{ $skip: Number(start) },
524529
{
525530
$group: {
526531
_id: '',
@@ -538,7 +543,7 @@ module.exports = {
538543
if (err) {
539544
return cb(err);
540545
} else {
541-
AddressTx.find({a_id: hash}).sort({blockindex: 'desc'}).skip(Number(start)).limit(Number(length)).exec(function (err, address_tx) {
546+
AddressTx.find({a_id: hash}).sort({blockindex: -1}).skip(Number(start)).limit(Number(length)).exec(function (err, address_tx) {
542547
if (err) {
543548
return cb(err);
544549
} else {

scripts/peers.js

Lines changed: 23 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ mongoose.connect(dbString, {
200200
console.log('Aborting');
201201
exit();
202202
} else {
203+
var peers = Array();
204+
var cnt = 0;
203205
request({
204206
uri: 'http://127.0.0.1:' + settings.port + '/api/getpeerinfo',
205207
json: true
@@ -208,73 +210,29 @@ mongoose.connect(dbString, {
208210
var i = loop.iteration();
209211
var address = body[i].addr.split(':')[0];
210212
var port = body[i].addr.split(':')[1];
211-
db.find_peer(address, function(peer) {
212-
if (peer) {
213-
if (isNaN(peer['port']) || peer['port'].length < 2 || peer['country'].length < 1) {
214-
db.drop_peers(function() {
215-
console.log('Saved peers missing ports or country, dropping peers. Re-reun this script afterwards.');
216-
exit();
217-
});
218-
}
219-
// peer already exists
220-
loop.next();
221-
} else {
222-
request({
223-
uri: 'https://freegeoip.app/json/' + address,
224-
json: true
225-
}, function(error, response, geo) {
226-
db.create_peer({
227-
address: address,
228-
port: port,
229-
protocol: body[i].version,
230-
version: body[i].subver.replace('/', '').replace('/', ''),
231-
country: geo.country_name
232-
}, function() {
233-
loop.next();
234-
});
235-
});
213+
request({uri: 'https://freegeoip.app/json/' + address, json: true}, function (error, response, geo) {
214+
if (address.startsWith('10.') || address.startsWith('192.168') || address.startsWith('172.16')) {
215+
geo.country_name = '[private address]';
236216
}
237-
//end
238-
var version = body[i].subver.replace('/', '').replace('/', '');
239-
var semver = version.split(":")[1];
240-
livepeers[i] = address;
241-
db.find_peers(address, function(peer) {
242-
if (peer.length) {
243-
for (i = 0; i < peer.length; i++) {
244-
// cmp(a,b)
245-
// result 1 = a is greater than b
246-
// result 0 = a is the same as b
247-
// result -1 = a is less than b
248-
if (cmp(peer[i].version.split(":")[1], semver) == -1) {
249-
if (settings.peers.purge_on_run != true) {
250-
db.delete_peer({
251-
_id: peer[i]._id
252-
});
253-
}
254-
create_peers(address, body[i].version, version);
255-
console.log('Delete the db version:', peer[i].version.split(":")[1]); //remove
256-
} else if (cmp(peer[i].version.split(":")[1], semver) == 0) {
257-
console.log('Do nothing, they\'re the same');
258-
} else {
259-
//db.delete_peer({_id:peer[i]._id});
260-
console.log('This should never occur, Live Version:', semver, " Is less than:", peer[i].version.split(":")[1]); //remove
261-
}
262-
}
263-
loop.next();
264-
} else {
265-
create_peers(address, body[i].version, version);
217+
peers[cnt++] = {
218+
address: address,
219+
port: port,
220+
protocol: body[i].version,
221+
version: body[i].subver.replace('/', '').replace('/', ''),
222+
country: geo.country_name
223+
};
224+
loop.next();
225+
});
226+
}, function() {
227+
// insert all at once after creation
228+
db.drop_peers(function() {
229+
console.log('Dropped, rebuilding...');
230+
lib.syncLoop(cnt, function (loop) {
231+
var i = loop.iteration();
232+
db.create_peer(peers[i], function() {
266233
loop.next();
267-
}
268-
});
269-
}, function() {
270-
db.get_peers(function(peers) {
271-
for (var i = 0; i < peers.length; i++) {
272-
if (!livepeers.includes(peers[i].address)) {
273-
db.delete_peer({
274-
address: peers[i].address
275-
});
276-
}
277-
}
234+
});
235+
}, function() {
278236
exit();
279237
});
280238
});

views/layout.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ html
2727
function update_stats(){
2828
$.ajax({url: '/ext/summary', success: function(json){
2929
$("#supply").text(parseInt(parseFloat(json.data[0].supply).toFixed(0)).toLocaleString('en'));
30-
$("#difficulty").text(parseFloat(json.data[0].difficulty).toFixed(2));
30+
$("#difficulty").text(json.data[0].difficulty);
3131
$("#difficultyHybrid").text(json.data[0].difficultyHybrid);
3232
$("#hashrate").text(parseFloat(json.data[0].hashrate).toLocaleString('en'));
3333
$("#lastPrice").text(parseFloat(json.data[0].lastPrice).toFixed(8) + ' #{settings.markets.exchange}'.toUpperCase());

0 commit comments

Comments
 (0)