Browse Source

treat single address in output as change

feat/estimateFee-limit
Ivan Socolsky 8 years ago
parent
commit
75c8e28e73
No known key found for this signature in database GPG Key ID: FAECE6A05FAA4F56
  1. 11
      lib/server.js
  2. 9
      test/integration/server.js

11
lib/server.js

@ -2660,8 +2660,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
if (opts.limit > Defaults.HISTORY_LIMIT)
return cb(Errors.HISTORY_LIMIT_EXCEEDED);
function decorate(txs, addresses, proposals, notes) {
function decorate(wallet, txs, addresses, proposals, notes) {
var indexedAddresses = _.indexBy(addresses, 'address');
var indexedProposals = _.indexBy(proposals, 'txid');
var indexedNotes = _.indexBy(notes, 'txid');
@ -2680,7 +2679,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
address: item.address,
amount: item.amount,
isMine: !!address,
isChange: address ? address.isChange : false,
isChange: address ? (address.isChange || wallet.singleAddress) : false,
}
});
};
@ -2858,6 +2857,9 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
});
};
self.getWallet({}, function(err, wallet) {
if (err) return cb(err);
// Get addresses for this wallet
self.storage.fetchAddresses(self.walletId, function(err, addresses) {
if (err) return cb(err);
@ -2901,7 +2903,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
], function(err, res) {
if (err) return cb(err);
var finalTxs = decorate(res.txs.items, addresses, res.txps, res.notes);
var finalTxs = decorate(wallet, res.txs.items, addresses, res.txps, res.notes);
if (res.txs.fromCache)
log.debug("History from cache for:", self.walletId, from, to);
@ -2909,6 +2911,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
return cb(null, finalTxs, !!res.txs.fromCache);
});
});
});
};

9
test/integration/server.js

@ -4245,19 +4245,20 @@ describe('Wallet service', function() {
});
});
});
it.only('should correctly handle change in tx history', function(done) {
it('should correctly handle change in tx history', function(done) {
server._normalizeTxHistory = sinon.stub().returnsArg(0);
helpers.stubUtxos(server, wallet, 2, function() {
var txs = [{
txid: '1',
confirmations: 1,
fees: 150,
time: Date.now() / 1000,
inputs: [{
address: firstAddress,
address: firstAddress.address,
amount: 550,
}],
outputs: [{
address: firstAddress,
address: firstAddress.address,
amount: 100,
}, {
address: 'external',
@ -4279,7 +4280,7 @@ describe('Wallet service', function() {
done();
});
});
});
});

Loading…
Cancel
Save