more accurate sigop counting.
This commit is contained in:
parent
9e0aa7acbb
commit
c33a88fb9e
@ -1397,9 +1397,6 @@ Script.getRedeem = function getRedeem(code) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Script.prototype.getType = function getType() {
|
Script.prototype.getType = function getType() {
|
||||||
if (this.isCommitment())
|
|
||||||
return 'commitment';
|
|
||||||
|
|
||||||
if (this.isWitnessProgram()) {
|
if (this.isWitnessProgram()) {
|
||||||
if (this.isWitnessPubkeyhash())
|
if (this.isWitnessPubkeyhash())
|
||||||
return 'witnesspubkeyhash';
|
return 'witnesspubkeyhash';
|
||||||
@ -2741,18 +2738,6 @@ Script.encode = function encode(code) {
|
|||||||
if (op.length === 0) {
|
if (op.length === 0) {
|
||||||
p.writeU8(opcodes.OP_0);
|
p.writeU8(opcodes.OP_0);
|
||||||
} else if (op.length <= 0x4b) {
|
} 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.writeU8(op.length);
|
||||||
p.writeBytes(op);
|
p.writeBytes(op);
|
||||||
} else if (op.length <= 0xff) {
|
} else if (op.length <= 0xff) {
|
||||||
|
|||||||
@ -659,13 +659,13 @@ TX.prototype._getSigops = function _getSigops(scriptHash, accurate) {
|
|||||||
for (i = 0; i < this.inputs.length; i++) {
|
for (i = 0; i < this.inputs.length; i++) {
|
||||||
input = this.inputs[i];
|
input = this.inputs[i];
|
||||||
|
|
||||||
|
total += input.script.getSigops(accurate);
|
||||||
|
|
||||||
if (!input.coin)
|
if (!input.coin)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
prev = input.coin.script;
|
prev = input.coin.script;
|
||||||
|
|
||||||
total += input.script.getSigops(accurate);
|
|
||||||
|
|
||||||
if (scriptHash && !this.isCoinbase()) {
|
if (scriptHash && !this.isCoinbase()) {
|
||||||
if (!prev.isScripthash())
|
if (!prev.isScripthash())
|
||||||
continue;
|
continue;
|
||||||
@ -807,12 +807,11 @@ TX.prototype.isSane = function isSane(ret) {
|
|||||||
|
|
||||||
// IsStandardTx
|
// IsStandardTx
|
||||||
TX.prototype.isStandard = function isStandard(flags, ret) {
|
TX.prototype.isStandard = function isStandard(flags, ret) {
|
||||||
var i, input, output, type;
|
var i, input, output;
|
||||||
var nulldata = 0;
|
var nulldata = 0;
|
||||||
var maxVersion = constants.tx.version;
|
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = { reason: null };
|
ret = {};
|
||||||
|
|
||||||
if (flags == null)
|
if (flags == null)
|
||||||
flags = constants.flags.STANDARD_VERIFY_FLAGS;
|
flags = constants.flags.STANDARD_VERIFY_FLAGS;
|
||||||
@ -835,10 +834,6 @@ TX.prototype.isStandard = function isStandard(flags, ret) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not accurate
|
|
||||||
if (this.isCoinbase())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (flags & constants.flags.VERIFY_SIGPUSHONLY) {
|
if (flags & constants.flags.VERIFY_SIGPUSHONLY) {
|
||||||
if (!input.script.isPushOnly()) {
|
if (!input.script.isPushOnly()) {
|
||||||
ret.reason = 'scriptsig-not-pushonly';
|
ret.reason = 'scriptsig-not-pushonly';
|
||||||
@ -849,19 +844,18 @@ TX.prototype.isStandard = function isStandard(flags, ret) {
|
|||||||
|
|
||||||
for (i = 0; i < this.outputs.length; i++) {
|
for (i = 0; i < this.outputs.length; i++) {
|
||||||
output = this.outputs[i];
|
output = this.outputs[i];
|
||||||
type = output.script.getType();
|
|
||||||
|
|
||||||
if (!output.script.isStandard()) {
|
if (!output.script.isStandard()) {
|
||||||
ret.reason = 'scriptpubkey';
|
ret.reason = 'scriptpubkey';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'nulldata') {
|
if (output.script.isNulldata()) {
|
||||||
nulldata++;
|
nulldata++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'multisig' && !constants.tx.bareMultisig) {
|
if (output.script.isMultisig() && !constants.tx.bareMultisig) {
|
||||||
ret.reason = 'bare-multisig';
|
ret.reason = 'bare-multisig';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
var bcoin = require('bcoin');
|
var bcoin = require('bcoin')();
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
var network = bcoin.protocol.network;
|
var network = bcoin.protocol.network;
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
@ -32,13 +32,13 @@ function createGenesisBlock(options) {
|
|||||||
version: 1,
|
version: 1,
|
||||||
inputs: [{
|
inputs: [{
|
||||||
prevout: {
|
prevout: {
|
||||||
hash: utils.toHex(constants.zeroHash),
|
hash: constants.nullHash,
|
||||||
index: 0xffffffff
|
index: 0xffffffff
|
||||||
},
|
},
|
||||||
script: {
|
script: {
|
||||||
code: [
|
code: [
|
||||||
new bn(486604799, 'le').toBuffer(),
|
new bn(486604799).toBuffer('le'),
|
||||||
new bn(4, 'le').toBuffer(),
|
new bn(4).toBuffer('le'),
|
||||||
options.flags
|
options.flags
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -58,7 +58,7 @@ function createGenesisBlock(options) {
|
|||||||
|
|
||||||
block = {
|
block = {
|
||||||
version: options.version,
|
version: options.version,
|
||||||
prevBlock: utils.toHex(constants.zeroHash),
|
prevBlock: constants.nullHash,
|
||||||
merkleRoot: utils.toHex(utils.dsha256(txRaw)),
|
merkleRoot: utils.toHex(utils.dsha256(txRaw)),
|
||||||
ts: options.ts,
|
ts: options.ts,
|
||||||
bits: options.bits,
|
bits: options.bits,
|
||||||
@ -109,7 +109,6 @@ var regtest = createGenesisBlock({
|
|||||||
|
|
||||||
var segnet3 = createGenesisBlock({
|
var segnet3 = createGenesisBlock({
|
||||||
version: 1,
|
version: 1,
|
||||||
// ts: 1452368293,
|
|
||||||
ts: 1452831101,
|
ts: 1452831101,
|
||||||
bits: 0x1d00ffff,
|
bits: 0x1d00ffff,
|
||||||
nonce: 0
|
nonce: 0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user