|
|
@ -231,7 +231,7 @@ TransactionBuilder.prototype._selectUnspent = function(neededAmountSat) { |
|
|
|
if (this.spendUnconfirmed) minConfirmationSteps.push(0); |
|
|
|
|
|
|
|
var sel = [], |
|
|
|
totalSat = new bignum(0), |
|
|
|
totalSat = bignum(0), |
|
|
|
fulfill = false, |
|
|
|
maxConfirmations = null, |
|
|
|
l = this.utxos.length; |
|
|
@ -246,9 +246,9 @@ TransactionBuilder.prototype._selectUnspent = function(neededAmountSat) { |
|
|
|
continue; |
|
|
|
|
|
|
|
var sat = u.amountSat || util.parseValue(u.amount); |
|
|
|
totalSat = totalSat.add(new bignum(sat)); |
|
|
|
totalSat = totalSat.add(sat); |
|
|
|
sel.push(u); |
|
|
|
if (totalSat.cmp(new bignum(neededAmountSat)) >= 0) { |
|
|
|
if (totalSat.cmp(neededAmountSat) >= 0) { |
|
|
|
fulfill = true; |
|
|
|
break; |
|
|
|
} |
|
|
@ -268,11 +268,11 @@ TransactionBuilder.prototype._selectUnspent = function(neededAmountSat) { |
|
|
|
TransactionBuilder.prototype._setInputs = function(txobj) { |
|
|
|
var ins = this.selectedUtxos; |
|
|
|
var l = ins.length; |
|
|
|
var valueInSat = new bignum(0); |
|
|
|
var valueInSat = bignum(0); |
|
|
|
|
|
|
|
txobj.ins = []; |
|
|
|
for (var i = 0; i < l; i++) { |
|
|
|
valueInSat = valueInSat.add(new bignum(util.parseValue(ins[i].amount))); |
|
|
|
valueInSat = valueInSat.add(util.parseValue(ins[i].amount)); |
|
|
|
|
|
|
|
var txin = {}; |
|
|
|
txin.s = util.EMPTY_BUFFER; |
|
|
@ -297,9 +297,9 @@ TransactionBuilder.prototype._setFee = function(feeSat) { |
|
|
|
throw new Error('valueOutSat undefined'); |
|
|
|
|
|
|
|
|
|
|
|
var valueOutSat = this.valueOutSat.add(new bignum(feeSat)); |
|
|
|
var valueOutSat = this.valueOutSat.add(feeSat); |
|
|
|
|
|
|
|
if (this.valueInSat.cmp(new bignum(valueOutSat)) < 0) { |
|
|
|
if (this.valueInSat.cmp(valueOutSat) < 0) { |
|
|
|
var inv = this.valueInSat.toString(); |
|
|
|
var ouv = valueOutSat.toString(); |
|
|
|
throw new Error('transaction input amount is less than outputs: ' + |
|
|
@ -316,16 +316,16 @@ TransactionBuilder.prototype._setRemainder = function(txobj, remainderIndex) { |
|
|
|
throw new Error('valueInSat / valueOutSat undefined'); |
|
|
|
|
|
|
|
/* add remainder (without modifying outs[]) */ |
|
|
|
var remainderSat = this.valueInSat.sub(new bignum(this.valueOutSat)).sub(new bignum(this.feeSat)); |
|
|
|
var remainderSat = this.valueInSat.sub(this.valueOutSat).sub(this.feeSat); |
|
|
|
var l = txobj.outs.length; |
|
|
|
this.remainderSat = new bignum(0); |
|
|
|
this.remainderSat = bignum(0); |
|
|
|
|
|
|
|
/*remove old remainder? */ |
|
|
|
if (l > remainderIndex) { |
|
|
|
txobj.outs.pop(); |
|
|
|
} |
|
|
|
|
|
|
|
if (remainderSat.cmp(new bignum(0)) > 0) { |
|
|
|
if (remainderSat.cmp(0) > 0) { |
|
|
|
var remainderOut = this.remainderOut || this.selectedUtxos[0]; |
|
|
|
var value = util.bigIntToValue(remainderSat); |
|
|
|
var script = TransactionBuilder._scriptForOut(remainderOut); |
|
|
@ -352,7 +352,7 @@ TransactionBuilder.prototype._setFeeAndRemainder = function(txobj) { |
|
|
|
var feeSat = this.givenFeeSat ? |
|
|
|
this.givenFeeSat : maxSizeK * FEE_PER_1000B_SAT; |
|
|
|
|
|
|
|
var neededAmountSat = this.valueOutSat.add(new bignum(feeSat)); |
|
|
|
var neededAmountSat = this.valueOutSat.add(feeSat); |
|
|
|
|
|
|
|
this._selectUnspent(neededAmountSat) |
|
|
|
._setInputs(txobj) |
|
|
@ -381,7 +381,7 @@ TransactionBuilder.prototype._setFeeAndRemainder = function(txobj) { |
|
|
|
//
|
|
|
|
|
|
|
|
TransactionBuilder.prototype.setOutputs = function(outs) { |
|
|
|
var valueOutSat = new bignum(0); |
|
|
|
var valueOutSat = bignum(0); |
|
|
|
|
|
|
|
var txobj = {}; |
|
|
|
txobj.version = 1; |
|
|
@ -401,7 +401,7 @@ TransactionBuilder.prototype.setOutputs = function(outs) { |
|
|
|
txobj.outs.push(txout); |
|
|
|
|
|
|
|
var sat = outs[i].amountSat || util.parseValue(outs[i].amount); |
|
|
|
valueOutSat = valueOutSat.add(new bignum(sat)); |
|
|
|
valueOutSat = valueOutSat.add(sat); |
|
|
|
} |
|
|
|
|
|
|
|
this.valueOutSat = valueOutSat; |
|
|
|