diff --git a/src/transaction.js b/src/transaction.js index c195da3..8132bd2 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -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 diff --git a/src/wallet.js b/src/wallet.js index 4410b36..4915d68 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -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() { diff --git a/test/transaction.js b/test/transaction.js index b2c8b92..8cf2366 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -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() {