diff --git a/lib/database.js b/lib/database.js index 3286c9e..9952188 100644 --- a/lib/database.js +++ b/lib/database.js @@ -338,7 +338,7 @@ module.exports = { oBurnAddresses.push("private_tx"); if(list == 'received') { - Address.find({a_id: { $nin: oBurnAddresses }}).sort({received: 'desc'}).limit(100).exec(function(err, addresses){ + Address.find({a_id: { $nin: oBurnAddresses }}, 'a_id balance received').sort({received: 'desc'}).limit(100).exec(function(err, addresses){ Richlist.updateOne({coin: settings.coin}, { received: addresses, }, function() { @@ -346,7 +346,7 @@ module.exports = { }); }); } else { //balance - Address.find({a_id: { $nin: oBurnAddresses }}).sort({balance: 'desc'}).limit(100).exec(function(err, addresses){ + Address.find({a_id: { $nin: oBurnAddresses }}, 'a_id balance received').sort({balance: 'desc'}).limit(100).exec(function(err, addresses){ Richlist.updateOne({coin: settings.coin}, { balance: addresses, }, function() { @@ -519,6 +519,17 @@ module.exports = { } }); }, + + // drops richlist data for given coin + delete_richlist: function(coin, cb) { + Richlist.findOneAndRemove({coin: coin}, function(err, exists) { + if(exists) { + return cb(true); + } else { + return cb(false); + } + }); + }, // checks richlist data exists for given coin check_richlist: function(coin, cb) { Richlist.findOne({coin: coin}, function(err, exists) { @@ -824,4 +835,4 @@ module.exports = { } }); } -}; +}; \ No newline at end of file diff --git a/scripts/sync.js b/scripts/sync.js index 7560ad7..5ea6040 100644 --- a/scripts/sync.js +++ b/scripts/sync.js @@ -49,6 +49,9 @@ if (process.argv[2] == 'index') { case 'reindex': mode = 'reindex'; break; + case 'reindex-rich': + mode = 'reindex-rich'; + break; default: usage(); } @@ -154,10 +157,12 @@ is_locked(function (exists) { }, function(err3) { Stats.updateOne({coin: settings.coin}, { last: 0, + count: 0, + supply: 0 }, function() { console.log('index cleared (reindex)'); }); - db.update_tx_db(settings.coin, 1, stats.count, settings.update_timeout, function(){ + db.update_tx_db(settings.coin, 1, stats.count, settings.check_timeout, function(){ db.update_richlist('received', function(){ db.update_richlist('balance', function(){ db.get_stats(settings.coin, function(nstats){ @@ -198,6 +203,34 @@ is_locked(function (exists) { }); }); }); + } else if (mode == 'reindex-rich') { + console.log('update started'); + db.update_tx_db(settings.coin, stats.last, stats.count, settings.check_timeout, function(){ + console.log('update finished'); + db.check_richlist(settings.coin, function(exists){ + if (exists == true) { + console.log('richlist entry found, deleting now..'); + } + db.delete_richlist(settings.coin, function(deleted) { + if (deleted == true) { + console.log('richlist entry deleted'); + } + db.create_richlist(settings.coin, function() { + console.log('richlist created.'); + db.update_richlist('received', function(){ + console.log('richlist updated received.'); + db.update_richlist('balance', function(){ + console.log('richlist updated balance.'); + db.get_stats(settings.coin, function(nstats){ + console.log('update complete (block: %s)', nstats.last); + exit(); + }); + }); + }); + }); + }); + }); + }); } }); });