|
|
@ -1420,29 +1420,38 @@ WalletService.prototype.getTxHistory = function(opts, cb) { |
|
|
|
var now = Math.floor(Date.now() / 1000); |
|
|
|
|
|
|
|
return _.map(txs, function(tx) { |
|
|
|
var inputs = classify(tx.inputs); |
|
|
|
var outputs = classify(tx.outputs); |
|
|
|
|
|
|
|
var amountIn = sum(inputs, true); |
|
|
|
var amountOut = sum(outputs, true, false); |
|
|
|
var amountOutChange = sum(outputs, true, true); |
|
|
|
var amountIn, amountOut, amountOutChange, amount |
|
|
|
var amount, action, addressTo; |
|
|
|
if (amountIn == (amountOut + amountOutChange + (amountIn > 0 ? tx.fees : 0))) { |
|
|
|
amount = amountOut; |
|
|
|
action = 'moved'; |
|
|
|
|
|
|
|
if (tx.outputs.length || tx.inputs.length) { |
|
|
|
|
|
|
|
var inputs = classify(tx.inputs); |
|
|
|
var outputs = classify(tx.outputs); |
|
|
|
|
|
|
|
amountIn = sum(inputs, true); |
|
|
|
amountOut = sum(outputs, true, false); |
|
|
|
amountOutChange = sum(outputs, true, true); |
|
|
|
if (amountIn == (amountOut + amountOutChange + (amountIn > 0 ? tx.fees : 0))) { |
|
|
|
amount = amountOut; |
|
|
|
action = 'moved'; |
|
|
|
} else { |
|
|
|
amount = amountIn - amountOut - amountOutChange - (amountIn > 0 ? tx.fees : 0); |
|
|
|
action = amount > 0 ? 'sent' : 'received'; |
|
|
|
} |
|
|
|
|
|
|
|
amount = Math.abs(amount); |
|
|
|
if (action == 'sent' || action == 'moved') { |
|
|
|
var firstExternalOutput = _.find(outputs, { |
|
|
|
isMine: false |
|
|
|
}); |
|
|
|
addressTo = firstExternalOutput ? firstExternalOutput.address : 'N/A'; |
|
|
|
}; |
|
|
|
} else { |
|
|
|
amount = amountIn - amountOut - amountOutChange - (amountIn > 0 ? tx.fees : 0); |
|
|
|
action = amount > 0 ? 'sent' : 'received'; |
|
|
|
action = 'invalid'; |
|
|
|
amount = 0; |
|
|
|
} |
|
|
|
|
|
|
|
amount = Math.abs(amount); |
|
|
|
if (action == 'sent' || action == 'moved') { |
|
|
|
var firstExternalOutput = _.find(outputs, { |
|
|
|
isMine: false |
|
|
|
}); |
|
|
|
addressTo = firstExternalOutput ? firstExternalOutput.address : 'N/A'; |
|
|
|
}; |
|
|
|
|
|
|
|
var newTx = { |
|
|
|
txid: tx.txid, |
|
|
|
action: action, |
|
|
|