Merge pull request #504 from isocolsky/ref/tx-history
Add extended info to tx history
This commit is contained in:
commit
8caaf5ea20
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue