|
|
@ -170,15 +170,13 @@ Script.prototype.toString = function() { |
|
|
|
return str.substr(0, str.length - 1); |
|
|
|
}; |
|
|
|
|
|
|
|
Script.prototype.isOpReturn = function() { |
|
|
|
return (this.chunks[0] === Opcode('OP_RETURN').toNumber() && |
|
|
|
(this.chunks.length === 1 || |
|
|
|
(this.chunks.length === 2 && |
|
|
|
this.chunks[1].buf && |
|
|
|
this.chunks[1].buf.length <= 40 && |
|
|
|
this.chunks[1].length === this.chunks.len))); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// script classification methods
|
|
|
|
|
|
|
|
/** |
|
|
|
* @returns true if this is a pay to pubkey hash output script |
|
|
|
*/ |
|
|
|
Script.prototype.isPublicKeyHashOut = function() { |
|
|
|
return this.chunks[0] === Opcode('OP_DUP').toNumber() && |
|
|
|
this.chunks[1] === Opcode('OP_HASH160').toNumber() && |
|
|
@ -187,12 +185,18 @@ Script.prototype.isPublicKeyHashOut = function() { |
|
|
|
this.chunks[4] === Opcode('OP_CHECKSIG').toNumber(); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* @returns true if this is a pay to public key hash input script |
|
|
|
*/ |
|
|
|
Script.prototype.isPublicKeyHashIn = function() { |
|
|
|
return !!(this.chunks.length === 2 && |
|
|
|
this.chunks[0].buf && |
|
|
|
this.chunks[1].buf); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* @returns true if this is a p2sh output script |
|
|
|
*/ |
|
|
|
Script.prototype.isScriptHashOut = function() { |
|
|
|
return this.chunks.length === 3 && |
|
|
|
this.chunks[0] === Opcode('OP_HASH160').toNumber() && |
|
|
@ -201,13 +205,44 @@ Script.prototype.isScriptHashOut = function() { |
|
|
|
this.chunks[2] === Opcode('OP_EQUAL').toNumber(); |
|
|
|
}; |
|
|
|
|
|
|
|
//note that these are frequently indistinguishable from pubkeyhashin
|
|
|
|
/** |
|
|
|
* @returns true if this is a p2sh input script |
|
|
|
* Note that these are frequently indistinguishable from pubkeyhashin |
|
|
|
*/ |
|
|
|
Script.prototype.isScriptHashIn = function() { |
|
|
|
return this.chunks.every(function(chunk) { |
|
|
|
return Buffer.isBuffer(chunk.buf); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* @returns true if this is a mutlsig output script |
|
|
|
*/ |
|
|
|
Script.prototype.isMultisigOut = function() { |
|
|
|
return (this.chunks.length > 3 && |
|
|
|
Opcode.isSmallIntOp(this.chunks[0]) && |
|
|
|
this.chunks.slice(1, this.chunks.length - 2).every(function(obj) { |
|
|
|
return obj.buf && Buffer.isBuffer(obj.buf); |
|
|
|
}) && |
|
|
|
Opcode.isSmallIntOp(this.chunks[this.chunks.length - 2]) && |
|
|
|
this.chunks[this.chunks.length - 1] === Opcode.map.OP_CHECKMULTISIG); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* @returns true if this is an OP_RETURN data script |
|
|
|
*/ |
|
|
|
Script.prototype.isOpReturn = function() { |
|
|
|
return (this.chunks[0] === Opcode('OP_RETURN').toNumber() && |
|
|
|
(this.chunks.length === 1 || |
|
|
|
(this.chunks.length === 2 && |
|
|
|
this.chunks[1].buf && |
|
|
|
this.chunks[1].buf.length <= 40 && |
|
|
|
this.chunks[1].length === this.chunks.len))); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Script construction methods
|
|
|
|
|
|
|
|
/** |
|
|
|
* Adds a script element at the start of the script. |
|
|
|
* @param {*} obj a string, number, Opcode, Bufer, or object to add |
|
|
|