diff --git a/lib/script/common.js b/lib/script/common.js index 5c9b8f62..c43ecc29 100644 --- a/lib/script/common.js +++ b/lib/script/common.js @@ -769,15 +769,18 @@ exports.array = function(value) { * @constructor * @extends Error * @param {String} code - Error code. - * @param {(Number|String)?} op - Opcode. + * @param {Number} op - Opcode. * @param {Number?} ip - Instruction pointer. * @property {String} message - Error message. * @property {String} code - Original code passed in. - * @property {String?} op - Symbolic opcode. - * @property {Number?} ip - Instruction pointer. + * @property {Number} op - Opcode. + * @property {Number} ip - Instruction pointer. */ exports.ScriptError = function ScriptError(code, op, ip) { + if (!(this instanceof ScriptError)) + return new ScriptError(code, op, ip); + Error.call(this); if (Error.captureStackTrace) @@ -785,27 +788,21 @@ exports.ScriptError = function ScriptError(code, op, ip) { this.type = 'ScriptError'; this.code = code; + this.message = code; + this.op = op != null ? op : -1; + this.ip = ip != null ? ip : -1; - if (typeof op !== 'string') { - if (op || ip != null) { - code += ' ('; - if (op) { - op = exports.opcodesByVal[op] || op; - code += 'op=' + op; - if (ip != null) - code += ', '; - } - if (ip != null) - code += 'ip=' + ip; - code += ')'; - } + if (typeof op === 'number') { + if (exports.opcodesByVal[op]) + op = exports.opcodesByVal[op]; + else if (op !== -1) + op = util.hex8(op); - this.message = code; - this.op = op || ''; - this.ip = ip != null ? ip : -1; - } else { + this.message += ' (op=' + op + ','; + this.message += ' ip=' + this.ip + ')'; + } else if (typeof op === 'string') { this.message = op; - this.op = ''; + this.op = -1; this.ip = -1; } }; diff --git a/lib/script/script.js b/lib/script/script.js index 25e78dc3..b812323c 100644 --- a/lib/script/script.js +++ b/lib/script/script.js @@ -2524,41 +2524,6 @@ Script.getCoinbaseHeight = function getCoinbaseHeight(raw) { return height.toNumber(); }; -/** - * Get info about a coinbase script. - * @returns {Object} Object containing `height`, - * `nonce`, `flags`, and `text`. - */ - -Script.prototype.getCoinbaseFlags = function getCoinbaseFlags() { - var height = this.getCoinbaseHeight(); - var index = 0; - var nonce, flags, text; - - if (height !== -1) - index++; - - nonce = this.getNumber(1); - - if (nonce) - nonce = nonce.toNumber(); - else - nonce = -1; - - flags = Script.fromArray(this.code.slice(index)); - flags = flags.toRaw(); - - text = flags.toString('utf8'); - text = text.replace(/[\u0000-\u0019\u007f-\u00ff]/g, ''); - - return { - height: height, - nonce: nonce, - flags: flags, - text: text - }; -}; - /** * Test the script against a bloom filter. * @param {Bloom} filter