Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

};

/**
Expand All @@ -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;
};
Expand Down
1 change: 0 additions & 1 deletion lib/transactions/commitment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down