script: some refactoring.
This commit is contained in:
parent
f58e748263
commit
29e03892e7
@ -769,15 +769,18 @@ exports.array = function(value) {
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @extends Error
|
* @extends Error
|
||||||
* @param {String} code - Error code.
|
* @param {String} code - Error code.
|
||||||
* @param {(Number|String)?} op - Opcode.
|
* @param {Number} op - Opcode.
|
||||||
* @param {Number?} ip - Instruction pointer.
|
* @param {Number?} ip - Instruction pointer.
|
||||||
* @property {String} message - Error message.
|
* @property {String} message - Error message.
|
||||||
* @property {String} code - Original code passed in.
|
* @property {String} code - Original code passed in.
|
||||||
* @property {String?} op - Symbolic opcode.
|
* @property {Number} op - Opcode.
|
||||||
* @property {Number?} ip - Instruction pointer.
|
* @property {Number} ip - Instruction pointer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.ScriptError = function ScriptError(code, op, ip) {
|
exports.ScriptError = function ScriptError(code, op, ip) {
|
||||||
|
if (!(this instanceof ScriptError))
|
||||||
|
return new ScriptError(code, op, ip);
|
||||||
|
|
||||||
Error.call(this);
|
Error.call(this);
|
||||||
|
|
||||||
if (Error.captureStackTrace)
|
if (Error.captureStackTrace)
|
||||||
@ -785,27 +788,21 @@ exports.ScriptError = function ScriptError(code, op, ip) {
|
|||||||
|
|
||||||
this.type = 'ScriptError';
|
this.type = 'ScriptError';
|
||||||
this.code = code;
|
this.code = code;
|
||||||
|
this.message = code;
|
||||||
|
this.op = op != null ? op : -1;
|
||||||
|
this.ip = ip != null ? ip : -1;
|
||||||
|
|
||||||
if (typeof op !== 'string') {
|
if (typeof op === 'number') {
|
||||||
if (op || ip != null) {
|
if (exports.opcodesByVal[op])
|
||||||
code += ' (';
|
op = exports.opcodesByVal[op];
|
||||||
if (op) {
|
else if (op !== -1)
|
||||||
op = exports.opcodesByVal[op] || op;
|
op = util.hex8(op);
|
||||||
code += 'op=' + op;
|
|
||||||
if (ip != null)
|
|
||||||
code += ', ';
|
|
||||||
}
|
|
||||||
if (ip != null)
|
|
||||||
code += 'ip=' + ip;
|
|
||||||
code += ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
this.message = code;
|
this.message += ' (op=' + op + ',';
|
||||||
this.op = op || '';
|
this.message += ' ip=' + this.ip + ')';
|
||||||
this.ip = ip != null ? ip : -1;
|
} else if (typeof op === 'string') {
|
||||||
} else {
|
|
||||||
this.message = op;
|
this.message = op;
|
||||||
this.op = '';
|
this.op = -1;
|
||||||
this.ip = -1;
|
this.ip = -1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2524,41 +2524,6 @@ Script.getCoinbaseHeight = function getCoinbaseHeight(raw) {
|
|||||||
return height.toNumber();
|
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.
|
* Test the script against a bloom filter.
|
||||||
* @param {Bloom} filter
|
* @param {Bloom} filter
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user