|
|
@ -2660,8 +2660,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) { |
|
|
|
if (opts.limit > Defaults.HISTORY_LIMIT) |
|
|
|
return cb(Errors.HISTORY_LIMIT_EXCEEDED); |
|
|
|
|
|
|
|
function decorate(txs, addresses, proposals, notes) { |
|
|
|
|
|
|
|
function decorate(wallet, txs, addresses, proposals, notes) { |
|
|
|
var indexedAddresses = _.indexBy(addresses, 'address'); |
|
|
|
var indexedProposals = _.indexBy(proposals, 'txid'); |
|
|
|
var indexedNotes = _.indexBy(notes, 'txid'); |
|
|
@ -2680,7 +2679,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) { |
|
|
|
address: item.address, |
|
|
|
amount: item.amount, |
|
|
|
isMine: !!address, |
|
|
|
isChange: address ? address.isChange : false, |
|
|
|
isChange: address ? (address.isChange || wallet.singleAddress) : false, |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
@ -2858,55 +2857,59 @@ WalletService.prototype.getTxHistory = function(opts, cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
// Get addresses for this wallet
|
|
|
|
self.storage.fetchAddresses(self.walletId, function(err, addresses) { |
|
|
|
self.getWallet({}, function(err, wallet) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (addresses.length == 0) return cb(null, []); |
|
|
|
|
|
|
|
var from = opts.skip || 0; |
|
|
|
var to = from + opts.limit; |
|
|
|
// Get addresses for this wallet
|
|
|
|
self.storage.fetchAddresses(self.walletId, function(err, addresses) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (addresses.length == 0) return cb(null, []); |
|
|
|
|
|
|
|
var from = opts.skip || 0; |
|
|
|
var to = from + opts.limit; |
|
|
|
|
|
|
|
|
|
|
|
async.waterfall([ |
|
|
|
async.waterfall([ |
|
|
|
|
|
|
|
function(next) { |
|
|
|
getNormalizedTxs(addresses, from, to, next); |
|
|
|
}, |
|
|
|
function(txs, next) { |
|
|
|
// Fetch all proposals in [t - 7 days, t + 1 day]
|
|
|
|
var minTs = _.min(txs.items, 'time').time - 7 * 24 * 3600; |
|
|
|
var maxTs = _.max(txs.items, 'time').time + 1 * 24 * 3600; |
|
|
|
|
|
|
|
async.parallel([ |
|
|
|
|
|
|
|
function(done) { |
|
|
|
self.storage.fetchTxs(self.walletId, { |
|
|
|
minTs: minTs, |
|
|
|
maxTs: maxTs |
|
|
|
}, done); |
|
|
|
}, |
|
|
|
function(done) { |
|
|
|
self.storage.fetchTxNotes(self.walletId, { |
|
|
|
minTs: minTs |
|
|
|
}, done); |
|
|
|
}, |
|
|
|
], function(err, res) { |
|
|
|
return next(err, { |
|
|
|
txs: txs, |
|
|
|
txps: res[0], |
|
|
|
notes: res[1] |
|
|
|
function(next) { |
|
|
|
getNormalizedTxs(addresses, from, to, next); |
|
|
|
}, |
|
|
|
function(txs, next) { |
|
|
|
// Fetch all proposals in [t - 7 days, t + 1 day]
|
|
|
|
var minTs = _.min(txs.items, 'time').time - 7 * 24 * 3600; |
|
|
|
var maxTs = _.max(txs.items, 'time').time + 1 * 24 * 3600; |
|
|
|
|
|
|
|
async.parallel([ |
|
|
|
|
|
|
|
function(done) { |
|
|
|
self.storage.fetchTxs(self.walletId, { |
|
|
|
minTs: minTs, |
|
|
|
maxTs: maxTs |
|
|
|
}, done); |
|
|
|
}, |
|
|
|
function(done) { |
|
|
|
self.storage.fetchTxNotes(self.walletId, { |
|
|
|
minTs: minTs |
|
|
|
}, done); |
|
|
|
}, |
|
|
|
], function(err, res) { |
|
|
|
return next(err, { |
|
|
|
txs: txs, |
|
|
|
txps: res[0], |
|
|
|
notes: res[1] |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
], function(err, res) { |
|
|
|
if (err) return cb(err); |
|
|
|
}, |
|
|
|
], function(err, res) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
var finalTxs = decorate(res.txs.items, addresses, res.txps, res.notes); |
|
|
|
var finalTxs = decorate(wallet, res.txs.items, addresses, res.txps, res.notes); |
|
|
|
|
|
|
|
if (res.txs.fromCache) |
|
|
|
log.debug("History from cache for:", self.walletId, from, to); |
|
|
|
if (res.txs.fromCache) |
|
|
|
log.debug("History from cache for:", self.walletId, from, to); |
|
|
|
|
|
|
|
return cb(null, finalTxs, !!res.txs.fromCache); |
|
|
|
return cb(null, finalTxs, !!res.txs.fromCache); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|