always assume change output exists when estimating fee
This commit is contained in:
parent
2dc0f69d00
commit
8f0413da98
1 changed files with 8 additions and 4 deletions
|
@ -191,14 +191,12 @@ var Wallet = function (seed, options) {
|
||||||
totalInValue += output.value
|
totalInValue += output.value
|
||||||
if(totalInValue < value) continue;
|
if(totalInValue < value) continue;
|
||||||
|
|
||||||
var fee = fixedFee || tx.estimateFee()
|
var fee = fixedFee || estimateFeePadChangeOutput(tx)
|
||||||
if(totalInValue < value + fee) continue;
|
if(totalInValue < value + fee) continue;
|
||||||
|
|
||||||
var change = totalInValue - value - fee
|
var change = totalInValue - value - fee
|
||||||
var changeAddress = getChangeAddress()
|
|
||||||
if(change > 0) {
|
if(change > 0) {
|
||||||
tx.addOutput(changeAddress, change)
|
tx.addOutput(getChangeAddress(), change)
|
||||||
// TODO: recalculate fee
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -207,6 +205,12 @@ var Wallet = function (seed, options) {
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function estimateFeePadChangeOutput(tx){
|
||||||
|
var tmpTx = tx.clone()
|
||||||
|
tmpTx.addOutput(getChangeAddress(), 0)
|
||||||
|
return tmpTx.estimateFee()
|
||||||
|
}
|
||||||
|
|
||||||
function getChangeAddress() {
|
function getChangeAddress() {
|
||||||
if(me.changeAddresses.length === 0) me.generateChangeAddress()
|
if(me.changeAddresses.length === 0) me.generateChangeAddress()
|
||||||
return me.changeAddresses[me.changeAddresses.length - 1]
|
return me.changeAddresses[me.changeAddresses.length - 1]
|
||||||
|
|
Loading…
Reference in a new issue