tx: add sigops vsize calculation.

This commit is contained in:
Christopher Jeffrey 2016-12-11 10:33:00 -08:00
parent 72d5eec710
commit 808d8678a6
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 15 additions and 0 deletions

View File

@ -324,6 +324,20 @@ TX.prototype.getVirtualSize = function getVirtualSize() {
return (this.getWeight() + scale - 1) / scale | 0;
};
/**
* Calculate the virtual size of the transaction
* (weighted against bytes per sigop cost).
* @param {Number} sigops - Sigops cost.
* @returns {Number} vsize
*/
TX.prototype.getSigopsSize = function getSigopsSize(sigops) {
var scale = constants.WITNESS_SCALE_FACTOR;
var bytes = constants.tx.BYTES_PER_SIGOP;
var weight = Math.max(this.getWeight(), sigops * bytes);
return (weight + scale - 1) / scale | 0;
};
/**
* Calculate the weight of the transaction.
* Note that this is cached.

View File

@ -422,6 +422,7 @@ exports.tx = {
FREE_THRESHOLD: exports.COIN * 144 / 250,
MAX_SIGOPS: exports.block.MAX_SIGOPS / 5,
MAX_SIGOPS_WEIGHT: exports.block.MAX_SIGOPS_WEIGHT / 5,
BYTES_PER_SIGOP: 20,
COINBASE_MATURITY: 100
};