Skip to content

Commit

Permalink
Bugfix - reversing value bytes when calculating totaloutvalue
Browse files Browse the repository at this point in the history
  • Loading branch information
sidazhang committed Feb 11, 2014
1 parent 5daede0 commit 461e178
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Transaction.prototype.addOutput = function(address, value) {
if ("number" == typeof value) {
value = BigInteger(value.toString(), 10);
}

if ("string" == typeof value) {
value = BigInteger(value, 10);
}
Expand Down Expand Up @@ -386,7 +386,7 @@ Transaction.prototype.getTotalOutValue = function() {
var totalValue = BigInteger.ZERO;
for (var j = 0; j < this.outs.length; j++) {
var txout = this.outs[j];
totalValue = totalValue.add(BigInteger.fromByteArrayUnsigned(txout.value));
totalValue = totalValue.add(BigInteger.fromByteArrayUnsigned(txout.value.reverse()));
}
return totalValue;
};
Expand Down
10 changes: 10 additions & 0 deletions test/transaction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ describe('Transaction ', function() {
})
})

describe(' - Transaction.getTotalOutValue()', function() {
it(' > should return the correct value (from LE byte array)', function() {
var test = new Transaction()
test.addOutput('mvaRDyLUeF4CP7Lu9umbU3FxehyC5nUz3L', '10000000000')
test.addOutput('mvaRDyLUeF4CP7Lu9umbU3FxehyC5nUz3L', '20000000000')

T(test.getTotalOutValue().compareTo(BigInteger('30000000000', 10)) === 0)
})
})

})

describe('TransactionOut', function() {
Expand Down

0 comments on commit 461e178

Please sign in to comment.