From 1b37d88e9a1d651c2b1d0552c5e8698a0eeefb9c Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 24 Jul 2014 20:02:41 -0300 Subject: [PATCH] accept amount a strings in setOutput --- lib/TransactionBuilder.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/TransactionBuilder.js b/lib/TransactionBuilder.js index 9b84216..7fdfbd1 100644 --- a/lib/TransactionBuilder.js +++ b/lib/TransactionBuilder.js @@ -386,7 +386,8 @@ TransactionBuilder.prototype._setFeeAndRemainder = function(txobj) { // // Note that only some of this outputs will be selected // to create the transaction. The selected ones can be checked -// after calling `setOutputs`, with `.getSelectedUnspent` +// after calling `setOutputs`, with `.getSelectedUnspent`. +// amountSatStr could be used to pass in the amount in satoshis, as a string. // TransactionBuilder.prototype.setOutputs = function(outs) { @@ -401,7 +402,7 @@ TransactionBuilder.prototype.setOutputs = function(outs) { var l = outs.length; for (var i = 0; i < l; i++) { - var amountSat = outs[i].amountSat || util.parseValue(outs[i].amount); + var amountSat = outs[i].amountSat || outs[i].amountSatStr ? bignum(outs[i].amountSatStr) : util.parseValue(outs[i].amount); var value = util.bigIntToValue(amountSat); var script = TransactionBuilder._scriptForOut(outs[i]); var txout = { @@ -410,8 +411,7 @@ TransactionBuilder.prototype.setOutputs = function(outs) { }; txobj.outs.push(txout); - var sat = outs[i].amountSat || util.parseValue(outs[i].amount); - valueOutSat = valueOutSat.add(sat); + valueOutSat = valueOutSat.add(amountSat); } this.valueOutSat = valueOutSat; @@ -445,7 +445,7 @@ TransactionBuilder._mapKeys = function(keys) { } var addr = wk.storeObj().addr; walletKeyMap[addr] = wk; - + } return walletKeyMap; }; @@ -766,7 +766,7 @@ TransactionBuilder.prototype.sign = function(keys) { ins = tx.ins, l = ins.length, walletKeyMap = TransactionBuilder._mapKeys(keys); - + for (var i = 0; i < l; i++) { var input = this.inputMap[i];