Browse Source
filter txs broadcasted in the last 24hs only
activeAddress
Ivan Socolsky
9 years ago
No known key found for this signature in database
GPG Key ID: FAECE6A05FAA4F56
2 changed files with
39 additions and
5 deletions
-
lib/server.js
-
lib/storage.js
|
|
@ -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). |
|
|
|