From 697718c940cfc723ab78a182351b16aafac64178 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 12 Feb 2016 04:04:18 -0800 Subject: [PATCH] drop fee recalculation. --- lib/bcoin/tx.js | 59 +-------------------------------------------- lib/bcoin/wallet.js | 11 +++++---- 2 files changed, 7 insertions(+), 63 deletions(-) diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 59791cde..ae09b575 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -311,12 +311,8 @@ TX.prototype.scriptInput = function scriptInput(index, publicKey, redeem) { } // P2SH requires the redeem script after signatures - if (redeem) { + if (redeem) input.script.push(redeem); - // The fee can be calculated more accurately - // now that the redeem script is available. - this._recalculateFee(); - } return true; }; @@ -1149,9 +1145,6 @@ TX.prototype.fill = function fill(unspent, options) { if (!result.inputs) return result; - this._changeAddress = options.changeAddress; - this._fee = options.fee; - result.inputs.forEach(function(input) { this.addInput(input); }, this); @@ -1218,54 +1211,6 @@ TX.prototype.sortMembers = function sortMembers() { TX.prototype.fillUnspent = TX.prototype.fill; TX.prototype.fillInputs = TX.prototype.fill; -TX.prototype._recalculateFee = function recalculateFee() { - var output = this.outputs[this.changeIndex]; - var size, real, fee; - - if (!this._changeAddress) - return; - - if (this._fee) - return; - - if (!output) { - this.addOutput({ - address: this._changeAddress, - value: new bn(0) - }); - output = this.outputs[this.outputs.length - 1]; - } - - size = this.maxSize(); - real = Math.ceil(size / 1024) * constants.tx.minFee; - fee = this.getFee().toNumber(); - - if (real === fee) { - if (this.changeIndex === -1) - this.outputs.pop(); - return; - } - - if (real > fee) { - if (output.value.cmpn(real - fee) < 0) { - this.outputs.pop(); - this.changeIndex = -1; - return; - } - output.value.isubn(real - fee); - } else { - output.value.iaddn(fee - real); - } - - if (output.value.cmpn(constants.tx.dustThreshold) < 0) { - this.outputs.pop(); - this.changeIndex = -1; - return; - } - - this.changeIndex = this.outputs.indexOf(output); -}; - TX.prototype.getFee = function getFee() { if (!this.hasPrevout()) return new bn(0); @@ -1790,8 +1735,6 @@ TX.prototype.inspect = function inspect() { copy.block = this.block; delete copy._raw; delete copy._chain; - delete copy._changeAddress; - delete copy._fee; delete copy.total; copy.hash = this.hash('hex'); copy.rhash = this.rhash; diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index e03a5085..cac3c3b2 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -501,20 +501,21 @@ Wallet.prototype.ownOutput = function ownOutput(tx, index) { }; Wallet.prototype.fill = function fill(tx, options) { - var unspent, result; + var result; if (!options) options = {}; assert(this._initialized); - unspent = this.getUnspent(); - - result = tx.fill(unspent, utils.merge(options || {}, { + result = tx.fill(this.getUnspent(), { + // wallet: this, + fee: options.fee, + subtractFee: options.subtractFee, changeAddress: this.changeAddress.getAddress(), m: this.m, n: this.n - })); + }); if (!result.inputs) return false;