improve block.getVirtualSize.

This commit is contained in:
Christopher Jeffrey 2016-04-09 00:55:22 -07:00
parent 044d54e12e
commit 646b3c3028
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 12 additions and 8 deletions

View File

@ -71,6 +71,12 @@ Block.prototype.getRaw = function getRaw() {
return raw;
};
Block.prototype._getSize = function _getSize() {
var sizes = bcoin.protocol.framer.block._sizes(this);
this._size = sizes.size;
this._witnessSize = sizes.witnessSize;
};
Block.prototype.getVirtualSize = function getVirtualSize(force) {
var size, witnessSize, base;
@ -83,13 +89,13 @@ Block.prototype.getVirtualSize = function getVirtualSize(force) {
Block.prototype.getSize = function getSize(force) {
if (force || this._size === 0)
this.getRaw();
this._getSize();
return this._size;
};
Block.prototype.getWitnessSize = function getWitnessSize(force) {
if (force || this._size === 0)
this.getRaw();
this._getSize();
return this._witnessSize;
};

View File

@ -366,7 +366,7 @@ MinerBlock.prototype.updateMerkle = function updateMerkle() {
};
MinerBlock.prototype.addTX = function addTX(tx) {
var size = this.block.getVirtualSize() + tx.getVirtualSize();
var size = this.block.getVirtualSize(true) + tx.getVirtualSize();
// Deliver me from the block size debate, please
if (size > constants.blocks.maxSize)

View File

@ -970,7 +970,7 @@ Script.prototype.interpret = function interpret(stack, flags, tx, index, version
n = Script.num(stack.pop(), flags).toNumber();
if (!(n >= 1 && n <= 15))
if (!(n >= 1 && n <= constants.script.maxPubkeysPerMultisig))
throw new ScriptError('`n` is out of bounds.', op, ip);
if (stack.length < n + 1)
@ -1731,9 +1731,7 @@ Script.prototype.getInputType = function getInputType() {
};
Script.getInputType = function getInputType(code, isWitness) {
var type;
type = (Script.isPubkeyInput(code) && 'pubkey')
var type = (Script.isPubkeyInput(code) && 'pubkey')
|| (Script.isPubkeyhashInput(code) && 'pubkeyhash')
|| (Script.isMultisigInput(code, isWitness) && 'multisig')
|| (Script.isScripthashInput(code, isWitness) && 'scripthash')
@ -1758,7 +1756,7 @@ Script.isUnknownInput = function isUnknownInput(code, isWitness) {
return Script.getInputType(code, isWitness) === 'unknown';
};
Script.createOutputScript = function(options) {
Script.createOutputScript = function createOutputScript(options) {
var script, m, n, hash, flags, address, redeem;
if (!options)