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

View File

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

View File

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