more accurate sigop counting.

This commit is contained in:
Christopher Jeffrey 2016-04-09 03:23:55 -07:00
parent 9e0aa7acbb
commit c33a88fb9e
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 11 additions and 33 deletions

View File

@ -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) {

View File

@ -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;
}

View File

@ -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