Browse Source

refactor fee correction on change below dust

activeAddress
Ivan Socolsky 9 years ago
parent
commit
a4ced0320f
  1. 8
      lib/server.js
  2. 2
      test/integration/server.js

8
lib/server.js

@ -1389,13 +1389,11 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
if (netTotal >= txpAmount) {
var changeAmount = Math.round(total - txpAmount - fee);
log.debug('Tx change: ', Utils.formatAmountInBtc(changeAmount));
if (changeAmount != 0 && Math.abs(changeAmount) <= Bitcore.Transaction.DUST_AMOUNT) {
log.debug('ABS(Change) (' + Utils.formatAmountInBtc(changeAmount) + ') below dust amount (' + Utils.formatAmountInBtc(Bitcore.Transaction.DUST_AMOUNT) + ')');
if (changeAmount > 0 && fee < changeAmount) return;
// Either increment or decrement fee to remove change
if (changeAmount > 0 && changeAmount <= Bitcore.Transaction.DUST_AMOUNT) {
log.debug('Change below dust amount (' + Utils.formatAmountInBtc(Bitcore.Transaction.DUST_AMOUNT) + ')');
// Remove dust change by incrementing fee
fee += changeAmount;
}

2
test/integration/server.js

@ -3540,6 +3540,8 @@ describe('Wallet service', function() {
server.createTx(txOpts, function(err, txp) {
should.not.exist(err);
(_.sum(txp.inputs, 'satoshis') - txp.outputs[0].amount - txp.fee).should.equal(0);
var changeOutput = txp.getBitcoreTx().getChangeOutput();
should.not.exist(changeOutput);
done();
});
});

Loading…
Cancel
Save