From 2e1cc88c56b46443ea0fdd16ee8f36e1573180ac Mon Sep 17 00:00:00 2001 From: Kosta Korenkov <7r0ggy@gmail.com> Date: Mon, 11 Apr 2016 13:10:40 +0300 Subject: [PATCH 1/2] fix: wrong output value calculation in _buildTx --- lib/model/txproposal.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/model/txproposal.js b/lib/model/txproposal.js index 7b9d546..31f51f2 100644 --- a/lib/model/txproposal.js +++ b/lib/model/txproposal.js @@ -162,7 +162,7 @@ TxProposal.prototype._buildTx = function() { t.fee(self.fee); var totalInputs = _.sum(self.inputs, 'satoshis'); - var totalOutputs = _.sum(self.outputs, 'satoshis'); + var totalOutputs = _.sum(self.outputs, 'amount'); if (totalInputs - totalOutputs - self.fee > 0 && self.changeAddress) { t.change(self.changeAddress.address); @@ -182,7 +182,7 @@ TxProposal.prototype._buildTx = function() { } // Validate actual inputs vs outputs independently of Bitcore - var totalInputs = _.sum(t.inputs, 'satoshis'); + var totalInputs = _.sum(t.inputs, 'output.satoshis'); var totalOutputs = _.sum(t.outputs, 'satoshis'); $.checkState(totalInputs - totalOutputs <= Defaults.MAX_TX_FEE); From 4d2516109830e60a042b00a8bbb0387905026b82 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 11 Apr 2016 10:04:37 -0300 Subject: [PATCH 2/2] assert inputs & outputs are consistent --- lib/model/txproposal.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/model/txproposal.js b/lib/model/txproposal.js index 31f51f2..b7c5ca1 100644 --- a/lib/model/txproposal.js +++ b/lib/model/txproposal.js @@ -185,6 +185,7 @@ TxProposal.prototype._buildTx = function() { var totalInputs = _.sum(t.inputs, 'output.satoshis'); var totalOutputs = _.sum(t.outputs, 'satoshis'); + $.checkState(totalInputs > 0 && totalOutputs > 0 && totalInputs >= totalOutputs); $.checkState(totalInputs - totalOutputs <= Defaults.MAX_TX_FEE); return t;