Transaction: remove estimateFee
This is a wallet abstraction.
This commit is contained in:
parent
009fcb9b82
commit
d567463588
3 changed files with 5 additions and 36 deletions
|
@ -325,18 +325,6 @@ Transaction.prototype.validateInput = function(index, prevOutScript, pubKey, DER
|
|||
return pubKey.verify(hash, signature)
|
||||
}
|
||||
|
||||
Transaction.feePerKb = 20000
|
||||
Transaction.prototype.estimateFee = function(feePerKb){
|
||||
var uncompressedInSize = 180
|
||||
var outSize = 34
|
||||
var fixedPadding = 34
|
||||
|
||||
if(feePerKb == undefined) feePerKb = Transaction.feePerKb;
|
||||
var size = this.ins.length * uncompressedInSize + this.outs.length * outSize + fixedPadding
|
||||
|
||||
return feePerKb * Math.ceil(size / 1000)
|
||||
}
|
||||
|
||||
function TransactionIn(data) {
|
||||
assert(data.outpoint && data.script, 'Invalid TxIn parameters')
|
||||
this.outpoint = data.outpoint
|
||||
|
|
|
@ -237,10 +237,13 @@ function Wallet(seed, network) {
|
|||
return sortByValueDesc
|
||||
}
|
||||
|
||||
function estimateFeePadChangeOutput(tx){
|
||||
var feePerKb = 20000
|
||||
function estimateFeePadChangeOutput(tx) {
|
||||
var tmpTx = tx.clone()
|
||||
tmpTx.addOutput(getChangeAddress(), 0)
|
||||
return tmpTx.estimateFee()
|
||||
|
||||
var byteSize = tmpTx.toBuffer().length
|
||||
return feePerKb * Math.ceil(byteSize / 1000)
|
||||
}
|
||||
|
||||
function getChangeAddress() {
|
||||
|
|
|
@ -194,28 +194,6 @@ describe('Transaction', function() {
|
|||
assert.equal(validTx.validateInput(0, script, key.pub, sig), true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('estimateFee', function() {
|
||||
it('works for fixture tx 1', function() {
|
||||
var tx = Transaction.fromHex(fixtureTx1Hex)
|
||||
assert.equal(tx.estimateFee(), 20000)
|
||||
})
|
||||
|
||||
it('works for fixture big tx', function() {
|
||||
var tx = Transaction.fromHex(fixtureTxBigHex)
|
||||
assert.equal(tx.estimateFee(), 60000)
|
||||
})
|
||||
|
||||
it('allow feePerKb to be passed in as an argument', function() {
|
||||
var tx = Transaction.fromHex(fixtureTx2Hex)
|
||||
assert.equal(tx.estimateFee(10000), 10000)
|
||||
})
|
||||
|
||||
it('allow feePerKb to be set to 0', function() {
|
||||
var tx = Transaction.fromHex(fixtureTx2Hex)
|
||||
assert.equal(tx.estimateFee(0), 0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('signInput', function() {
|
||||
|
|
Loading…
Add table
Reference in a new issue