From 42c2d9a95f0029398807940046fb1c2baf2f8af1 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Tue, 3 May 2016 12:40:22 -0300 Subject: [PATCH] add includeExtendedInfo opts to getTxHistory --- lib/server.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/server.js b/lib/server.js index c26411d..7c64ad3 100644 --- a/lib/server.js +++ b/lib/server.js @@ -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;