filter txs broadcasted in the last 24hs only
This commit is contained in:
parent
3db28a4e2d
commit
3d7a12f3ab
|
@ -943,15 +943,12 @@ WalletService.prototype._getUtxosForCurrentWallet = function(addresses, cb) {
|
|||
},
|
||||
function(next) {
|
||||
var fromTs = Math.floor(Date.now() / 1000) - 24 * 3600;
|
||||
self.storage.fetchTxs(self.walletId, {
|
||||
self.storage.fetchBroadcastedTxs(self.walletId, {
|
||||
minTs: fromTs,
|
||||
limit: 100
|
||||
}, function(err, txs) {
|
||||
if (err) return next(err);
|
||||
var broadcasted = _.filter(txs, {
|
||||
status: 'broadcasted'
|
||||
});
|
||||
var spentInputs = _.map(_.flatten(_.pluck(broadcasted, 'inputs')), utxoKey);
|
||||
var spentInputs = _.map(_.flatten(_.pluck(txs, 'inputs')), utxoKey);
|
||||
_.each(spentInputs, function(input) {
|
||||
if (utxoIndex[input]) {
|
||||
utxoIndex[input].spent = true;
|
||||
|
|
|
@ -296,6 +296,43 @@ Storage.prototype.fetchTxs = function(walletId, opts, cb) {
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* fetchBroadcastedTxs. Times are in UNIX EPOCH (seconds)
|
||||
*
|
||||
* @param walletId
|
||||
* @param opts.minTs
|
||||
* @param opts.maxTs
|
||||
* @param opts.limit
|
||||
*/
|
||||
Storage.prototype.fetchBroadcastedTxs = function(walletId, opts, cb) {
|
||||
var self = this;
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
var tsFilter = {};
|
||||
if (_.isNumber(opts.minTs)) tsFilter.$gte = opts.minTs;
|
||||
if (_.isNumber(opts.maxTs)) tsFilter.$lte = opts.maxTs;
|
||||
|
||||
var filter = {
|
||||
walletId: walletId,
|
||||
status: 'broadcasted',
|
||||
};
|
||||
if (!_.isEmpty(tsFilter)) filter.broadcastedOn = tsFilter;
|
||||
|
||||
var mods = {};
|
||||
if (_.isNumber(opts.limit)) mods.limit = opts.limit;
|
||||
|
||||
this.db.collection(collections.TXS).find(filter, mods).sort({
|
||||
createdOn: -1
|
||||
}).toArray(function(err, result) {
|
||||
if (err) return cb(err);
|
||||
if (!result) return cb();
|
||||
var txs = _.map(result, function(tx) {
|
||||
return Model.TxProposal.fromObj(tx);
|
||||
});
|
||||
return self._completeTxData(walletId, txs, cb);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves notifications after a specific id or from a given ts (whichever is more recent).
|
||||
|
|
Loading…
Reference in New Issue