Wallet: move estimatePaddedTxFee out of Wallet scope
This commit is contained in:
parent
8b3470e8ca
commit
abc3e6c715
1 changed files with 9 additions and 8 deletions
|
@ -5,6 +5,7 @@ var networks = require('./networks')
|
||||||
var Address = require('./address')
|
var Address = require('./address')
|
||||||
var HDNode = require('./hdnode')
|
var HDNode = require('./hdnode')
|
||||||
var Transaction = require('./transaction')
|
var Transaction = require('./transaction')
|
||||||
|
var Script = require('./script')
|
||||||
|
|
||||||
function Wallet(seed, network) {
|
function Wallet(seed, network) {
|
||||||
seed = seed || crypto.randomBytes(32)
|
seed = seed || crypto.randomBytes(32)
|
||||||
|
@ -155,7 +156,7 @@ function Wallet(seed, network) {
|
||||||
var outpoint = utxo.from.split(':')
|
var outpoint = utxo.from.split(':')
|
||||||
tx.addInput(outpoint[0], parseInt(outpoint[1]))
|
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
|
accum += utxo.value
|
||||||
subTotal = value + fee
|
subTotal = value + fee
|
||||||
|
@ -176,13 +177,6 @@ function Wallet(seed, network) {
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
|
||||||
function estimateFeePadChangeOutput(tx) {
|
|
||||||
var tmpTx = tx.clone()
|
|
||||||
tmpTx.addOutput(getChangeAddress(), network.dustSoftThreshold || 0)
|
|
||||||
|
|
||||||
return network.estimateFee(tmpTx)
|
|
||||||
}
|
|
||||||
|
|
||||||
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]
|
||||||
|
@ -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) {
|
function isNullOrUndefined(value) {
|
||||||
return value == undefined
|
return value == undefined
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue