Merge pull request #339 from matiu/feat/firstSeenTs
add firstSeenTs for sorting
This commit is contained in:
commit
bdb35b3b5f
@ -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();
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var imports = require('soop').imports();
|
var imports = require('soop').imports();
|
||||||
|
var _ = require('lodash');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
var BitcoreAddress = bitcore.Address;
|
var BitcoreAddress = bitcore.Address;
|
||||||
@ -115,7 +116,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,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +184,9 @@ Address.prototype.update = function(next, opts) {
|
|||||||
return !x.spentTxId;
|
return !x.spentTxId;
|
||||||
});
|
});
|
||||||
tDb.fillScriptPubKey(txOut, function() {
|
tDb.fillScriptPubKey(txOut, function() {
|
||||||
self.unspent = txOut.map(function(x) {
|
//_.filter will filterout unspend without scriptPubkey
|
||||||
|
//(probably from double spends)
|
||||||
|
self.unspent = _.filter(txOut.map(function(x) {
|
||||||
return {
|
return {
|
||||||
address: self.addrStr,
|
address: self.addrStr,
|
||||||
txid: x.txid,
|
txid: x.txid,
|
||||||
@ -193,7 +197,7 @@ Address.prototype.update = function(next, opts) {
|
|||||||
confirmations: x.isConfirmedCached ? (config.safeConfirmations) : x.confirmations,
|
confirmations: x.isConfirmedCached ? (config.safeConfirmations) : x.confirmations,
|
||||||
confirmationsFromCache: !!x.isConfirmedCached,
|
confirmationsFromCache: !!x.isConfirmedCached,
|
||||||
};
|
};
|
||||||
});
|
}), 'scriptPubKey');;
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -202,7 +206,6 @@ Address.prototype.update = function(next, opts) {
|
|||||||
});
|
});
|
||||||
if (txList)
|
if (txList)
|
||||||
self.transactions = txList;
|
self.transactions = txList;
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user