Merge pull request #454 from matiu/feature/builder02

accept amount a strings in setOutput
This commit is contained in:
Ryan X. Charles 2014-07-24 19:17:06 -04:00
commit b4a56eb454
1 changed files with 6 additions and 6 deletions

View File

@ -386,7 +386,8 @@ TransactionBuilder.prototype._setFeeAndRemainder = function(txobj) {
// //
// Note that only some of this outputs will be selected // Note that only some of this outputs will be selected
// to create the transaction. The selected ones can be checked // 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) { TransactionBuilder.prototype.setOutputs = function(outs) {
@ -401,7 +402,7 @@ TransactionBuilder.prototype.setOutputs = function(outs) {
var l = outs.length; var l = outs.length;
for (var i = 0; i < l; i++) { 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 value = util.bigIntToValue(amountSat);
var script = TransactionBuilder._scriptForOut(outs[i]); var script = TransactionBuilder._scriptForOut(outs[i]);
var txout = { var txout = {
@ -410,8 +411,7 @@ TransactionBuilder.prototype.setOutputs = function(outs) {
}; };
txobj.outs.push(txout); txobj.outs.push(txout);
var sat = outs[i].amountSat || util.parseValue(outs[i].amount); valueOutSat = valueOutSat.add(amountSat);
valueOutSat = valueOutSat.add(sat);
} }
this.valueOutSat = valueOutSat; this.valueOutSat = valueOutSat;