Merge pull request #734 from matiu/feat/foreign-sent
fix: handle outgoing TXs foreign crafted
This commit is contained in:
commit
80d609c014
|
@ -1106,7 +1106,7 @@ WalletService.prototype._getUtxos = function(coin, addresses, cb) {
|
|||
var bc = self._getBlockchainExplorer(coin, networkName);
|
||||
if (!bc) return cb(new Error('Could not get blockchain explorer instance'));
|
||||
|
||||
self.logi('','Querying utxos: %s addrs', addresses.length);
|
||||
self.logi('Querying utxos: %s addrs', addresses.length);
|
||||
|
||||
bc.getUtxos(addresses, function(err, utxos) {
|
||||
if (err) return cb(err);
|
||||
|
@ -3010,7 +3010,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
|
|||
|
||||
var amountIn, amountOut, amountOutChange;
|
||||
var amount, action, addressTo;
|
||||
var inputs, outputs;
|
||||
var inputs, outputs, foreignCrafted;
|
||||
|
||||
if (tx.outputs.length || tx.inputs.length) {
|
||||
|
||||
|
@ -3024,7 +3024,9 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
|
|||
amount = amountOut;
|
||||
action = 'moved';
|
||||
} else {
|
||||
amount = amountIn - amountOut - amountOutChange - (amountIn > 0 ? tx.fees : 0);
|
||||
// BWS standard sent
|
||||
//(amountIn > 0 && amountOutChange >0 && outputs.length <= 2)
|
||||
amount = amountIn - amountOut - amountOutChange - ((amountIn > 0 && amountOutChange >0 ) ? tx.fees : 0);
|
||||
action = amount > 0 ? 'sent' : 'received';
|
||||
}
|
||||
|
||||
|
@ -3035,6 +3037,11 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
|
|||
});
|
||||
addressTo = firstExternalOutput ? firstExternalOutput.address : 'N/A';
|
||||
};
|
||||
|
||||
if (action == 'sent' && inputs.length != (_.filter(inputs,'isMine')).length ) {
|
||||
foreignCrafted = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
action = 'invalid';
|
||||
amount = 0;
|
||||
|
@ -3055,6 +3062,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
|
|||
time: tx.time,
|
||||
addressTo: addressTo,
|
||||
confirmations: tx.confirmations,
|
||||
foreignCrafted: foreignCrafted,
|
||||
};
|
||||
|
||||
if (_.isNumber(tx.size) && tx.size > 0) {
|
||||
|
@ -3139,7 +3147,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
|
|||
var bc = self._getBlockchainExplorer(wallet.coin, wallet.network);
|
||||
if (!bc) return next(new Error('Could not get blockchain explorer instance'));
|
||||
|
||||
self.logi('','Querying tx for: %s addrs', addresses.length);
|
||||
self.logi('Querying tx for: %s addrs', addresses.length);
|
||||
|
||||
bc.getTransactions(addressStrs, from, to, function(err, rawTxs, total) {
|
||||
if (err) return next(err);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -27,6 +27,7 @@ var Model = require('../../lib/model');
|
|||
|
||||
var WalletService = require('../../lib/server');
|
||||
|
||||
var HugeTxs = require('./hugetx');
|
||||
var TestData = require('../testdata');
|
||||
var helpers = require('./helpers');
|
||||
var storage, blockchainExplorer, request;
|
||||
|
@ -6809,7 +6810,7 @@ describe('Wallet service', function() {
|
|||
txs.length.should.equal(1);
|
||||
var tx = txs[0];
|
||||
tx.action.should.equal('sent');
|
||||
tx.amount.should.equal(400);
|
||||
tx.amount.should.equal(500); // it is 500 because there is no change Address
|
||||
tx.fees.should.equal(100);
|
||||
tx.time.should.equal(12345);
|
||||
done();
|
||||
|
@ -6914,6 +6915,8 @@ describe('Wallet service', function() {
|
|||
tx.createdOn.should.equal(txp.createdOn);
|
||||
tx.action.should.equal('sent');
|
||||
tx.amount.should.equal(0.8e8);
|
||||
|
||||
|
||||
tx.message.should.equal('some message');
|
||||
tx.addressTo.should.equal(external);
|
||||
tx.actions.length.should.equal(1);
|
||||
|
@ -7136,10 +7139,55 @@ describe('Wallet service', function() {
|
|||
should.not.exist(err);
|
||||
var tx = txs[0];
|
||||
tx.feePerKb.should.equal(200);
|
||||
should.not.exist(tx.foreignCrafted);
|
||||
should.not.exist(tx.lowFees);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle outgoing txs where fee > amount', function(done) {
|
||||
var x = _.cloneDeep([HugeTxs[0]]);
|
||||
x[0].vin[118].addr = mainAddresses[0].address;
|
||||
helpers.stubHistory(x);
|
||||
|
||||
|
||||
//console.log('[server.js.7149]',HugeTxs[1].vin); //TODO
|
||||
|
||||
|
||||
|
||||
server.getTxHistory({}, function(err, txs) {
|
||||
should.not.exist(err);
|
||||
should.exist(txs);
|
||||
txs.length.should.equal(1);
|
||||
var tx = txs[0];
|
||||
tx.action.should.equal('sent');
|
||||
tx.amount.should.equal(3002982);
|
||||
tx.fees.should.equal(10000000);
|
||||
tx.outputs[0].address.should.equal('1DVhaBdbp5mx5Y8zR1qR9NBiQtrgL9ZNQs');
|
||||
tx.outputs[0].amount.should.equal(500000000);
|
||||
tx.foreignCrafted.should.equal(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should handle incoming txs with fee > incoming', function(done) {
|
||||
var x = _.cloneDeep([HugeTxs[1]]);
|
||||
|
||||
x[0].vout[43].scriptPubKey.addresses = [mainAddresses[0].address];
|
||||
helpers.stubHistory(x);
|
||||
|
||||
server.getTxHistory({}, function(err, txs) {
|
||||
should.not.exist(err);
|
||||
should.exist(txs);
|
||||
txs.length.should.equal(1);
|
||||
var tx = txs[0];
|
||||
tx.action.should.equal('received');
|
||||
tx.amount.should.equal(3002982);
|
||||
tx.fees.should.equal(130700);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getTxHistory cache', function() {
|
||||
|
|
Loading…
Reference in New Issue