add includeExtendedInfo opts to getTxHistory

This commit is contained in:
Ivan Socolsky 2016-05-03 12:40:22 -03:00
parent 0bd06921dd
commit 42c2d9a95f
No known key found for this signature in database
GPG Key ID: FAECE6A05FAA4F56
1 changed files with 22 additions and 4 deletions

View File

@ -2490,6 +2490,7 @@ WalletService.prototype._normalizeTxHistory = function(txs) {
* @param {Object} opts
* @param {Number} opts.skip (defaults to 0)
* @param {Number} opts.limit
* @param {Number} opts.includeExtendedInfo[=false] - Include all inputs/outputs for every tx.
* @returns {TxProposal[]} Transaction proposals, first newer
*/
WalletService.prototype.getTxHistory = function(opts, cb) {
@ -2558,12 +2559,13 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
amount = 0;
}
function outputMap(o) {
function formatOutput(o) {
return {
amount: o.amount,
address: o.address
}
};
var newTx = {
txid: tx.txid,
action: action,
@ -2571,12 +2573,28 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
fees: tx.fees,
time: tx.time,
addressTo: addressTo,
outputs: _.map(_.filter(outputs, {
isChange: false
}), outputMap),
confirmations: tx.confirmations,
};
if (opts.includeExtendedInfo) {
newTx.inputs = _.map(inputs, function(input) {
return _.pick(input, 'address', 'amount', 'isMine');
});
newTx.outputs = _.map(outputs, function(output) {
return _.pick(output, 'address', 'amount', 'isMine');
});
} else {
outputs = _.filter(outputs, {
isChange: false
});
if (action == 'received') {
outputs = _.filter(outputs, {
isMine: true
});
}
newTx.outputs = _.map(outputs, formatOutput);
}
var proposal = indexedProposals[tx.txid];
if (proposal) {
newTx.proposalId = proposal.id;