diff --git a/lib/database.js b/lib/database.js index 12443b352..2e6b8c350 100644 --- a/lib/database.js +++ b/lib/database.js @@ -75,70 +75,6 @@ function find_richlist(coin, cb) { }); } -/*function update_richlist(coin, hash, received, sent, cb){ - find_richlist(coin, function(richlist){ - f_richlist(richlist.balance, hash, received - sent, function(rl_balance){ - f_richlist(richlist.received, hash, received, function(rl_received){ - Richlist.update({coin: settings.coin}, { - received : sort_richlist(rl_received), - balance: sort_richlist(rl_balance), - }, function() { - return cb(); - }); - }); - }); - }); -}*/ - -/*function f_richlist(list, address, total, cb) { - //console.log(address); - is_unique(list, address, function(unique, index){ - if (unique == false) { - list.splice(index, 1); - process_richlist(list, address, total, function(list) { - return cb(list); - }); - } else { - process_richlist(list, address, total, function(list) { - return cb(list); - }); - } - }); -}*/ - -/*function process_richlist(list, address, total, cb) { - if (list.length > 0) { - if (total >= list[list.length-1].total) { - list.push({addresses: address, total: total}); - return cb(list); - } else if (list.length < 100){ - list.push({addresses: address, total: total}); - return cb(list); - } else { - return cb(list); - } - } else { - list.push({addresses: address, total: total}); - return cb(list); - } -}*/ - -/*function sort_richlist(list){ - list.sort(function(a, b) { - return b.total - a.total; - }); - - if (list.length > 100) { - return list.slice(0,100); - } else { - return list; - } -}*/ - - - - - function update_address(hash, txid, amount, type, cb) { find_address(hash, function(address) { //console.log(address); @@ -171,25 +107,24 @@ function update_address(hash, txid, amount, type, cb) { is_unique(tx_array, txid, function(unique, index) { if (unique == true) { tx_array.push(txid); - if (type == 'vin') { - sent = sent + amount; - } else { - received = received + amount; - } - //update_richlist(settings.coin, hash, received, sent, function() { - Address.update({a_id:hash}, { - txs: tx_array, - received: received, - sent: sent, - balance: received - sent, - }, function() { - //console.log('address updated: %s', hash); - return cb(); - }); - //}); + if ( tx_array.length > settings.txcount ) { + tx_array.shift(); + } + } + if (type == 'vin') { + sent = sent + amount; } else { + received = received + amount; + } + Address.update({a_id:hash}, { + txs: tx_array, + received: received, + sent: sent, + balance: received - sent, + }, function() { + //console.log('address updated: %s', hash); return cb(); - } + }); }); } else { var received = amount; diff --git a/lib/settings.js b/lib/settings.js index b6bb6c4dc..a2f0f7d8c 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -95,6 +95,7 @@ exports.genesis_tx = "65f705d2f385dc85763a317b3ec000063003d6b039546af5d8195a5ec2 exports.genesis_block = "b2926a56ca64e0cd2430347e383f63ad7092f406088b9b86d6d68c2a34baef51", exports.heavy = false, +exports.txcount = 100, exports.reloadSettings = function reloadSettings() { // Discover where the settings file lives var settingsFilename = "settings.json"; diff --git a/scripts/benchmark.js b/scripts/benchmark.js new file mode 100644 index 000000000..fcd1a9355 --- /dev/null +++ b/scripts/benchmark.js @@ -0,0 +1,49 @@ +require('nodetime').profile({ + accountKey: '823170bf6bf4c8e481c99238999316eec066dce9', + appName: 'IQUIDUS-BENCHMARK' +}); + +var mongoose = require('mongoose') + , db = require('../lib/database') + , Tx = require('../models/tx') + , Address = require('../models/address') + , settings = require('../lib/settings'); + + +var COUNT = 5000; //number of blocks to index + +function exit() { + mongoose.disconnect(); + process.exit(0); +} + +var dbString = "mongodb://" + settings.dbsettings.address; +dbString = dbString + ":" + settings.dbsettings.port; +dbString = dbString + "/IQUIDUS-BENCHMARK"; + +mongoose.connect(dbString, function(err) { + if (err) { + console.log('Unable to connect to database: %s', dbString); + console.log('Aborting'); + exit(); + } + Tx.remove({}, function(err) { + Address.remove({}, function(err2) { + var s_timer = new Date().getTime(); + db.update_tx_db(settings.coin, 1, COUNT, settings.update_timeout, function(){ + var e_timer = new Date().getTime(); + Tx.count({}, function(txerr, txcount){ + Address.count({}, function(aerr, acount){ + var stats = { + tx_count: txcount, + address_count: acount, + seconds: (e_timer - s_timer)/1000, + }; + console.log(stats); + exit(); + }); + }); + }); + }); + }); +}); \ No newline at end of file diff --git a/scripts/sync.js b/scripts/sync.js index 35f93ffdb..590b761f9 100644 --- a/scripts/sync.js +++ b/scripts/sync.js @@ -1,3 +1,8 @@ +require('nodetime').profile({ + accountKey: '823170bf6bf4c8e481c99238999316eec066dce9', + appName: 'Iquidus Explorer' + }); + var mongoose = require('mongoose') , db = require('../lib/database') , Tx = require('../models/tx') diff --git a/settings.json.template b/settings.json.template index 9795bf242..34ffd8d2d 100644 --- a/settings.json.template +++ b/settings.json.template @@ -85,7 +85,9 @@ "genesis_block": "b2926a56ca64e0cd2430347e383f63ad7092f406088b9b86d6d68c2a34baef51" //heavy (enable/disable additional heavy features) - "heavy": false + "heavy": false, + //amount of txs to index per address (stores latest n txs) + "txcount": 100 } \ No newline at end of file