Skip to content

Commit

Permalink
fix: handle outgoing TXs foreign crafted
Browse files Browse the repository at this point in the history
  • Loading branch information
matiu committed Nov 16, 2017
1 parent acb14a1 commit 869840e
Show file tree
Hide file tree
Showing 3 changed files with 6,812 additions and 5 deletions.
16 changes: 12 additions & 4 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {

Expand All @@ -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';
}

Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 869840e

Please sign in to comment.