From 42c2d9a95f0029398807940046fb1c2baf2f8af1 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Tue, 3 May 2016 12:40:22 -0300 Subject: [PATCH 1/2] 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; From 64665d3efee761e7bb119914891817400622da1d Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Tue, 3 May 2016 12:42:04 -0300 Subject: [PATCH 2/2] REST endpoint --- lib/expressapp.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/expressapp.js b/lib/expressapp.js index b4f9a08..f64205a 100644 --- a/lib/expressapp.js +++ b/lib/expressapp.js @@ -459,6 +459,7 @@ ExpressApp.prototype.start = function(opts, cb) { var opts = {}; if (req.query.skip) opts.skip = +req.query.skip; if (req.query.limit) opts.limit = +req.query.limit; + if (req.query.includeExtendedInfo == '1') opts.includeExtendedInfo = true; server.getTxHistory(opts, function(err, txs) { if (err) return returnError(err, res, req);