From 02cc52e13bbdfc6dc64c9860ae82c733f0106ae5 Mon Sep 17 00:00:00 2001 From: c Date: Wed, 3 Jun 2015 18:47:01 -0700 Subject: [PATCH 1/2] Fixed setupRefund bug by going around Transaction.change. --- lib/consumer.js | 15 ++++++++++++--- lib/transactions/commitment.js | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/consumer.js b/lib/consumer.js index 2b7ae6f..5d2a1e4 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); + }; /** @@ -127,6 +131,7 @@ Consumer.prototype.processFunding = function(utxo) { * @return {bitcore.Transaction} */ Consumer.prototype.setupRefund = function() { +// this.commitmentTx.to(refundAddress, this.commitmentTx._getInputAmount() - ) this.commitmentTx.sign(this.fundingKey); $.checkState(this.commitmentTx.isFullySigned()); var amount = this.commitmentTx.amount; @@ -136,11 +141,15 @@ 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); + //.change(this.refundAddress); + 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._updateChangeOutput(); this.refundTx.nLockTime = this.expires; return this.refundTx; }; diff --git a/lib/transactions/commitment.js b/lib/transactions/commitment.js index 17cdb5c..48b2ece 100644 --- a/lib/transactions/commitment.js +++ b/lib/transactions/commitment.js @@ -27,7 +27,7 @@ function Commitment(opts) { this.publicKeys = opts.publicKeys; this.outscript = Script.buildMultisigOut(this.publicKeys, 2); this.address = this.outscript.toScriptHashOut().toAddress(); - this.change(this.address); + //this.change(this.address); Object.defineProperty(this, 'amount', { configurable: false, From 7297be29993c1cd946e90a9cf033e44d7c82e544 Mon Sep 17 00:00:00 2001 From: c Date: Wed, 3 Jun 2015 18:50:05 -0700 Subject: [PATCH 2/2] Removed comments --- lib/consumer.js | 3 --- lib/transactions/commitment.js | 1 - 2 files changed, 4 deletions(-) diff --git a/lib/consumer.js b/lib/consumer.js index 5d2a1e4..e94c59a 100644 --- a/lib/consumer.js +++ b/lib/consumer.js @@ -131,7 +131,6 @@ Consumer.prototype.processFunding = function(utxo) { * @return {bitcore.Transaction} */ Consumer.prototype.setupRefund = function() { -// this.commitmentTx.to(refundAddress, this.commitmentTx._getInputAmount() - ) this.commitmentTx.sign(this.fundingKey); $.checkState(this.commitmentTx.isFullySigned()); var amount = this.commitmentTx.amount; @@ -144,12 +143,10 @@ Consumer.prototype.setupRefund = function() { this.refundTx = new Refund() .from(multisigOut, this.commitmentTx.publicKeys, 2); - //.change(this.refundAddress); 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 48b2ece..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,