add firstSeenTs for sorting

This commit is contained in:
Matias Alejo Garcia 2015-07-14 19:36:49 -03:00
parent b799cc7d6d
commit 90d5e57e7a
3 changed files with 15 additions and 9 deletions

View File

@ -143,9 +143,8 @@ exports.multitxs = function(req, res, next) {
if (to > nbTxs) to = nbTxs;
txs.sort(function(a, b) {
return (b.ts || b.ts) - (a.ts || a.ts);
return (b.firstSeenTs || b.ts) - (a.firstSeenTs || a.ts);
});
txs = txs.slice(from, to);
var txIndex = {};
@ -153,13 +152,17 @@ exports.multitxs = function(req, res, next) {
txIndex[tx.txid] = tx;
});
async.eachLimit(txs, RPC_CONCURRENCY, function(tx, callback) {
tDb.fromIdWithInfo(tx.txid, function(err, tx) {
async.eachLimit(txs, RPC_CONCURRENCY, function(tx2, callback) {
tDb.fromIdWithInfo(tx2.txid, function(err, tx) {
if (err) {
console.log(err);
return common.handleErrors(err, res);
}
if (tx && tx.info) {
if (tx2.firstSeenTs)
tx.info.firstSeenTs = tx2.firstSeenTs;
txIndex[tx.txid].info = tx.info;
} else
nbTxs--;
@ -192,6 +195,7 @@ exports.multitxs = function(req, res, next) {
async.eachLimit(as, RPC_CONCURRENCY, function(a, callback) {
a.update(function(err) {
if (err) callback(err);
txs.push(a.transactions);
callback();
}, {

View File

@ -115,7 +115,8 @@ Address.prototype._addTxItem = function(txItem, txList, includeInfo) {
addTx({
txid: txItem.txid,
ts: txItem.ts
ts: txItem.ts,
firstSeenTs: txItem.firstSeenTs,
});
}
@ -202,7 +203,6 @@ Address.prototype.update = function(next, opts) {
});
if (txList)
self.transactions = txList;
return next();
}
});

View File

@ -197,7 +197,6 @@ TransactionDb.prototype._fillOutpoints = function(txInfo, cb) {
return c_in(); // error not scalated
}
txInfo.firstSeenTs = ret.ts;
i.addr = ret.addr;
i.valueSat = ret.valueSat;
i.value = ret.valueSat / util.COIN;
@ -467,8 +466,11 @@ TransactionDb.prototype.fromAddr = function(addr, opts, cb) {
var k = data.key.split('-');
var index = k[3] + k[4];
if (!unique[index]) {
unique[index] = 1;
ret.push(self._parseAddrData(k, data, opts.ignoreCache));
unique[index] = self._parseAddrData(k, data, opts.ignoreCache);
ret.push(unique[index]);
} else {
// add first seen
unique[index].firstSeenTs = END_OF_WORLD_TS - parseInt(k[2]);
}
})
.on('error', cb)