Skip to content
Permalink
Browse files

Historical Address Balance

  • Loading branch information
TheHolyRoger committed Dec 28, 2019
1 parent 8566ef6 commit 0ac734f4fe963621ab247abf4d27c6e4f22feba0
Showing with 37 additions and 26 deletions.
  1. +3 −0 CHANGELOG
  2. +1 −10 README.md
  3. +3 −0 UPGRADE
  4. +29 −15 lib/database.js
  5. +1 −1 models/addresstx.js
@@ -1,3 +1,6 @@
1.7.3
* Fixes for Historical Address Balance - seems to be fastest method that works along-side parallel indexing

1.7.2
* Index blocks in parallel - uses settings for task counts.
* Indexing is much faster (again).
@@ -1,4 +1,4 @@
Iquidus Explorer - 1.7.2
Iquidus Explorer - 1.7.3
================

An open source block explorer written in node.js.
@@ -113,15 +113,6 @@ Ensure mongodb is not exposed to the outside world via your mongo config or a fi
### Known Issues
**Address balance history is out of order.**

1.7.2 brings parallel block indexing (super fast) - but the new addition of Historical Address Balance is currently indexed out of order. Will fix it soon.

Only workaround at the moment is limit parallel block tasks to 1 (disable it)

https://github.com/iquidus/explorer/issues/330


**script is already running.**

If you receive this message when launching the sync script either a) a sync is currently in progress, or b) a previous sync was killed before it completed. If you are certian a sync is not in progress remove the index.pid and db_index.pid from the tmp folder in the explorer root directory.
@@ -1,5 +1,8 @@
Note: All updates require the explorer to be restarted

1.7.2 -> 1.7.3
* Reindex explorerdb (node --stack-size=15000 scripts/sync.js index reindex) required for Historical Address Balance

1.7.1 -> 1.7.2
* Add new settings to settings.json (see settings.json.template)
* block_parallel_tasks
@@ -85,11 +85,13 @@ function update_address(hash, blockheight, txid, amount, type, cb) {
} else {
if ( hash != 'coinbase' ) {
AddressTx.findOneAndUpdate({a_id: hash, txid: txid}, {
$inc: {
amount: addr_inc.balance
},
$set: {
a_id: hash,
blockindex: blockheight,
txid: txid,
amount: address.balance
txid: txid
}
}, {
new: true,
@@ -445,41 +447,56 @@ module.exports = {

get_address_txs_ajax: function(hash, start, length, cb) {
var totalCount = 0;
Address.findOne({a_id: hash}, function(err, addressTotalTxs) {

AddressTx.find({a_id: hash}).countDocuments({}, function(err, count){
if(err) {
return cb(err);
} else {
AddressTx.find({a_id: hash}).count({}, function(err, count){
if(err) {
totalCount = count;
AddressTx.aggregate([
{ $match: { a_id: hash } },
{ $sort: {blockindex: -1} },
{ $skip: Number(start) },
{
$group: {
_id: '',
balance: { $sum: '$amount' }
}
},
{
$project: {
_id: 0,
balance: '$balance'
}
},
{ $sort: {blockindex: -1} }
], function (err,balance_sum) {
if (err) {
return cb(err);
} else {
totalCount = count;
AddressTx.find({a_id: hash}).sort({blockindex: 'desc'}).skip(Number(start)).limit(Number(length)).exec(function (err, address_tx) {
if (err) {
return cb(err);
} else {
var txs = [];
var count = address_tx.length;
var running_balance = balance_sum[0].balance;

var txs = [];

lib.syncLoop(count, function (loop) {
var i = loop.iteration();
find_tx(address_tx[i].txid, function (tx) {
if (tx && !txs.includes(tx)) {
// tx = {...hashes[i], ...tx}
tx.balance = address_tx[i].amount;
tx.balance = running_balance;
txs.push(tx);
loop.next();
} else if (!txs.includes(tx)) {
// tx = {...hashes[i], ...tx}
tx.balance = address_tx[i].amount;
txs.push("1. Not found");
loop.next();
} else {
loop.next();
}
running_balance = running_balance - address_tx[i].amount;
})
}, function () {
return cb(txs, totalCount);
@@ -488,11 +505,8 @@ module.exports = {
});
}
});

}
});


},

create_market: function(coin, exchange, market, cb) {
@@ -764,7 +778,7 @@ module.exports = {
var blocks_to_scan = [];
var task_limit_blocks = settings.block_parallel_tasks;
if (task_limit_blocks < 1) { task_limit_blocks = 1; }
var task_limit_txs = 1
var task_limit_txs = 1;
for (i=start; i<(end+1); i++) {
blocks_to_scan.push(i);
}
@@ -6,7 +6,7 @@ var AddressTXSchema = new Schema({
blockindex: {type: Number, default: 0, index: true},
txid: { type: String, lowercase: true, index: true},
// renamed to amount instead of balance for future changes
amount: { type: Number, default: 0}
amount: { type: Number, default: 0, index: true}
}, {id: false});

module.exports = mongoose.model('AddressTx', AddressTXSchema);

0 comments on commit 0ac734f

Please sign in to comment.
You can’t perform that action at this time.