diff --git a/lib/consumer.js b/lib/consumer.js index 2b7ae6f..e94c59a 100644 --- a/lib/consumer.js +++ b/lib/consumer.js @@ -119,6 +119,10 @@ function Consumer(opts) { Consumer.prototype.processFunding = function(utxo) { $.checkArgument(_.isObject(utxo), 'Can only process an array of objects or an object'); this.commitmentTx.from(utxo); + var size = this.commitmentTx._estimateSize(); + var fee = this.commitmentTx._estimateFee(size, 0); + this.commitmentTx.to(this.commitmentTx.address, this.commitmentTx.amount - fee); + }; /** @@ -136,11 +140,13 @@ Consumer.prototype.setupRefund = function() { satoshis: amount, script: this.commitmentTx.outputs[0].script }; + this.refundTx = new Refund() - .from(multisigOut, this.commitmentTx.publicKeys, 2) - .change(this.refundAddress); + .from(multisigOut, this.commitmentTx.publicKeys, 2); + var size = this.refundTx._estimateSize(); + var fee = this.refundTx._estimateFee(size, 0); + this.refundTx.to(this.refundAddress, amount - fee); this.refundTx.inputs[0].sequenceNumber = 0; - this.refundTx._updateChangeOutput(); this.refundTx.nLockTime = this.expires; return this.refundTx; }; diff --git a/lib/transactions/commitment.js b/lib/transactions/commitment.js index 17cdb5c..006d260 100644 --- a/lib/transactions/commitment.js +++ b/lib/transactions/commitment.js @@ -27,7 +27,6 @@ function Commitment(opts) { this.publicKeys = opts.publicKeys; this.outscript = Script.buildMultisigOut(this.publicKeys, 2); this.address = this.outscript.toScriptHashOut().toAddress(); - this.change(this.address); Object.defineProperty(this, 'amount', { configurable: false,