From c33a88fb9ece995c1d298044d4f025c1a22b3bb4 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 9 Apr 2016 03:23:55 -0700 Subject: [PATCH] more accurate sigop counting. --- lib/bcoin/script.js | 15 --------------- lib/bcoin/tx.js | 18 ++++++------------ scripts/gen.js | 11 +++++------ 3 files changed, 11 insertions(+), 33 deletions(-) diff --git a/lib/bcoin/script.js b/lib/bcoin/script.js index 659960a6..3d60891e 100644 --- a/lib/bcoin/script.js +++ b/lib/bcoin/script.js @@ -1397,9 +1397,6 @@ Script.getRedeem = function getRedeem(code) { }; Script.prototype.getType = function getType() { - if (this.isCommitment()) - return 'commitment'; - if (this.isWitnessProgram()) { if (this.isWitnessPubkeyhash()) return 'witnesspubkeyhash'; @@ -2741,18 +2738,6 @@ Script.encode = function encode(code) { if (op.length === 0) { p.writeU8(opcodes.OP_0); } else if (op.length <= 0x4b) { - if (op.length === 1) { - if (op[0] === 0) { - p.writeU8(opcodes.OP_0); - continue; - } else if (op[0] >= 1 && op[0] <= 16) { - p.writeU8(op[0] + 0x50); - continue; - } else if (op[0] === 0xff) { - p.writeU8(opcodes.OP_1NEGATE); - continue; - } - } p.writeU8(op.length); p.writeBytes(op); } else if (op.length <= 0xff) { diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 7f02d06b..95469a07 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -659,13 +659,13 @@ TX.prototype._getSigops = function _getSigops(scriptHash, accurate) { for (i = 0; i < this.inputs.length; i++) { input = this.inputs[i]; + total += input.script.getSigops(accurate); + if (!input.coin) continue; prev = input.coin.script; - total += input.script.getSigops(accurate); - if (scriptHash && !this.isCoinbase()) { if (!prev.isScripthash()) continue; @@ -807,12 +807,11 @@ TX.prototype.isSane = function isSane(ret) { // IsStandardTx TX.prototype.isStandard = function isStandard(flags, ret) { - var i, input, output, type; + var i, input, output; var nulldata = 0; - var maxVersion = constants.tx.version; if (!ret) - ret = { reason: null }; + ret = {}; if (flags == null) flags = constants.flags.STANDARD_VERIFY_FLAGS; @@ -835,10 +834,6 @@ TX.prototype.isStandard = function isStandard(flags, ret) { return false; } - // Not accurate - if (this.isCoinbase()) - continue; - if (flags & constants.flags.VERIFY_SIGPUSHONLY) { if (!input.script.isPushOnly()) { ret.reason = 'scriptsig-not-pushonly'; @@ -849,19 +844,18 @@ TX.prototype.isStandard = function isStandard(flags, ret) { for (i = 0; i < this.outputs.length; i++) { output = this.outputs[i]; - type = output.script.getType(); if (!output.script.isStandard()) { ret.reason = 'scriptpubkey'; return false; } - if (type === 'nulldata') { + if (output.script.isNulldata()) { nulldata++; continue; } - if (type === 'multisig' && !constants.tx.bareMultisig) { + if (output.script.isMultisig() && !constants.tx.bareMultisig) { ret.reason = 'bare-multisig'; return false; } diff --git a/scripts/gen.js b/scripts/gen.js index ebbe6037..cd65a08b 100644 --- a/scripts/gen.js +++ b/scripts/gen.js @@ -1,4 +1,4 @@ -var bcoin = require('bcoin'); +var bcoin = require('bcoin')(); var constants = bcoin.protocol.constants; var network = bcoin.protocol.network; var utils = bcoin.utils; @@ -32,13 +32,13 @@ function createGenesisBlock(options) { version: 1, inputs: [{ prevout: { - hash: utils.toHex(constants.zeroHash), + hash: constants.nullHash, index: 0xffffffff }, script: { code: [ - new bn(486604799, 'le').toBuffer(), - new bn(4, 'le').toBuffer(), + new bn(486604799).toBuffer('le'), + new bn(4).toBuffer('le'), options.flags ] }, @@ -58,7 +58,7 @@ function createGenesisBlock(options) { block = { version: options.version, - prevBlock: utils.toHex(constants.zeroHash), + prevBlock: constants.nullHash, merkleRoot: utils.toHex(utils.dsha256(txRaw)), ts: options.ts, bits: options.bits, @@ -109,7 +109,6 @@ var regtest = createGenesisBlock({ var segnet3 = createGenesisBlock({ version: 1, - // ts: 1452368293, ts: 1452831101, bits: 0x1d00ffff, nonce: 0