diff --git a/src/wallet.js b/src/wallet.js index b188808..b2d9a05 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -5,6 +5,7 @@ var networks = require('./networks') var Address = require('./address') var HDNode = require('./hdnode') var Transaction = require('./transaction') +var Script = require('./script') function Wallet(seed, network) { seed = seed || crypto.randomBytes(32) @@ -155,7 +156,7 @@ function Wallet(seed, network) { var outpoint = utxo.from.split(':') tx.addInput(outpoint[0], parseInt(outpoint[1])) - var fee = fixedFee == undefined ? estimateFeePadChangeOutput(tx) : fixedFee + var fee = fixedFee == undefined ? estimatePaddedFee(tx, network) : fixedFee accum += utxo.value subTotal = value + fee @@ -176,13 +177,6 @@ function Wallet(seed, network) { return tx } - function estimateFeePadChangeOutput(tx) { - var tmpTx = tx.clone() - tmpTx.addOutput(getChangeAddress(), network.dustSoftThreshold || 0) - - return network.estimateFee(tmpTx) - } - function getChangeAddress() { if(me.changeAddresses.length === 0) me.generateChangeAddress(); return me.changeAddresses[me.changeAddresses.length - 1] @@ -285,6 +279,13 @@ function validateUnspentOutput(uo) { } } +function estimatePaddedFee(tx, network) { + var tmpTx = tx.clone() + tmpTx.addOutput(Script.EMPTY, network.dustSoftThreshold || 0) + + return network.estimateFee(tmpTx) +} + function isNullOrUndefined(value) { return value == undefined }