diff --git a/lib/primitives/tx.js b/lib/primitives/tx.js index 1a4832c1..4706525a 100644 --- a/lib/primitives/tx.js +++ b/lib/primitives/tx.js @@ -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. diff --git a/lib/protocol/constants.js b/lib/protocol/constants.js index 910a2afb..c066fbcd 100644 --- a/lib/protocol/constants.js +++ b/lib/protocol/constants.js @@ -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 };