get rid of magic numbers in fee estimation

This commit is contained in:
Wei Lu 2014-03-25 11:21:23 +08:00
parent 58ab0b631e
commit 7bd312de71

View file

@ -379,8 +379,12 @@ Transaction.prototype.validateSig = function(index, script, sig, pub) {
Transaction.feePerKb = 20000 Transaction.feePerKb = 20000
Transaction.prototype.estimateFee = function(feePerKb){ Transaction.prototype.estimateFee = function(feePerKb){
var uncompressedInSize = 180
var outSize = 34
var fixedPadding = 34
var feePerKb = feePerKb || Transaction.feePerKb 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)) var sizeInKb = BigInteger.valueOf(Math.ceil(size / 1000))
return BigInteger.valueOf(feePerKb).multiply(sizeInKb).intValue() return BigInteger.valueOf(feePerKb).multiply(sizeInKb).intValue()