From 7bd312de71a010a7d4474591cefbfbd41e850554 Mon Sep 17 00:00:00 2001 From: Wei Lu Date: Tue, 25 Mar 2014 11:21:23 +0800 Subject: [PATCH] get rid of magic numbers in fee estimation --- src/transaction.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/transaction.js b/src/transaction.js index 7401c54..6059fc5 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -379,8 +379,12 @@ Transaction.prototype.validateSig = function(index, script, sig, pub) { Transaction.feePerKb = 20000 Transaction.prototype.estimateFee = function(feePerKb){ + var uncompressedInSize = 180 + var outSize = 34 + var fixedPadding = 34 var feePerKb = feePerKb || Transaction.feePerKb - var size = this.ins.length * 180 + this.outs.length * 34 + 10 + + var size = this.ins.length * uncompressedInSize + this.outs.length * outSize + fixedPadding var sizeInKb = BigInteger.valueOf(Math.ceil(size / 1000)) return BigInteger.valueOf(feePerKb).multiply(sizeInKb).intValue()