Merge pull request #282 from matiu/feat/handle-invalid
Feat/handle invalid
This commit is contained in:
commit
43be63859a
|
@ -1420,13 +1420,18 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
|
||||||
var now = Math.floor(Date.now() / 1000);
|
var now = Math.floor(Date.now() / 1000);
|
||||||
|
|
||||||
return _.map(txs, function(tx) {
|
return _.map(txs, function(tx) {
|
||||||
|
|
||||||
|
var amountIn, amountOut, amountOutChange;
|
||||||
|
var amount, action, addressTo;
|
||||||
|
|
||||||
|
if (tx.outputs.length || tx.inputs.length) {
|
||||||
|
|
||||||
var inputs = classify(tx.inputs);
|
var inputs = classify(tx.inputs);
|
||||||
var outputs = classify(tx.outputs);
|
var outputs = classify(tx.outputs);
|
||||||
|
|
||||||
var amountIn = sum(inputs, true);
|
amountIn = sum(inputs, true);
|
||||||
var amountOut = sum(outputs, true, false);
|
amountOut = sum(outputs, true, false);
|
||||||
var amountOutChange = sum(outputs, true, true);
|
amountOutChange = sum(outputs, true, true);
|
||||||
var amount, action, addressTo;
|
|
||||||
if (amountIn == (amountOut + amountOutChange + (amountIn > 0 ? tx.fees : 0))) {
|
if (amountIn == (amountOut + amountOutChange + (amountIn > 0 ? tx.fees : 0))) {
|
||||||
amount = amountOut;
|
amount = amountOut;
|
||||||
action = 'moved';
|
action = 'moved';
|
||||||
|
@ -1442,6 +1447,10 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
|
||||||
});
|
});
|
||||||
addressTo = firstExternalOutput ? firstExternalOutput.address : 'N/A';
|
addressTo = firstExternalOutput ? firstExternalOutput.address : 'N/A';
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
action = 'invalid';
|
||||||
|
amount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
var newTx = {
|
var newTx = {
|
||||||
txid: tx.txid,
|
txid: tx.txid,
|
||||||
|
|
|
@ -3592,6 +3592,19 @@ describe('Wallet service', function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('should handle invalid tx in history ', function(done) {
|
||||||
|
var h = _.clone(TestData.history);
|
||||||
|
h.push({txid:'xx'})
|
||||||
|
helpers.stubHistory(h);
|
||||||
|
|
||||||
|
server.getTxHistory({}, function(err, txs) {
|
||||||
|
should.not.exist(err);
|
||||||
|
should.exist(txs);
|
||||||
|
txs.length.should.equal(3);
|
||||||
|
txs[2].action.should.equal('invalid');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#scan', function() {
|
describe('#scan', function() {
|
||||||
|
|
Loading…
Reference in New Issue