|
|
@ -115,6 +115,13 @@ Script.prototype.isMultiSig = function() { |
|
|
|
this.chunks[this.chunks.length - 1] == Opcode.map.OP_CHECKMULTISIG); |
|
|
|
}; |
|
|
|
|
|
|
|
Script.prototype.isPubkeyHashScript = function() { |
|
|
|
// TODO: add more restrictions to chunks
|
|
|
|
return (this.chunks.length == 2 && |
|
|
|
Buffer.isBuffer(this.chunks[0]) && |
|
|
|
Buffer.isBuffer(this.chunks[1])); |
|
|
|
}; |
|
|
|
|
|
|
|
Script.prototype.isP2shScriptSig = function() { |
|
|
|
if (!isSmallIntOp(this.chunks[0]) || this.chunks[0] !== 0) |
|
|
|
return false; |
|
|
@ -133,20 +140,65 @@ Script.prototype.isMultiSigScriptSig = function() { |
|
|
|
Script.prototype.countSignatures = function() { |
|
|
|
var ret = 0; |
|
|
|
var l = this.chunks.length; |
|
|
|
|
|
|
|
// Multisig?
|
|
|
|
if (this.isMultiSigScriptSig()) { |
|
|
|
ret = l - 1; |
|
|
|
} else if (this.isP2shScriptSig()) { |
|
|
|
} |
|
|
|
// p2sh
|
|
|
|
else if (this.isP2shScriptSig()) { |
|
|
|
ret = l - 2; |
|
|
|
} |
|
|
|
// p2pubkey or p2pubkeyhash
|
|
|
|
// p2pubkeyhash
|
|
|
|
else if (this.isPubkeyHashScript()) { |
|
|
|
ret = 1; |
|
|
|
} |
|
|
|
// p2pubkey
|
|
|
|
else { |
|
|
|
ret = buffertools.compare(this.getBuffer(), util.EMPTY_BUFFER) === 0 ? 0 : 1; |
|
|
|
ret = 0; |
|
|
|
} |
|
|
|
return ret; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Script.prototype.getSignatures = function() { |
|
|
|
ret = []; |
|
|
|
var l = this.chunks.length; |
|
|
|
// Multisig?
|
|
|
|
if (this.isMultiSigScriptSig()) { |
|
|
|
for(var i = 1; i<l; i++) { |
|
|
|
ret.push(this.chunks[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
// p2sh
|
|
|
|
else if (this.isP2shScriptSig()) { |
|
|
|
for (var i=1; i<l-1; i++) { |
|
|
|
ret.push(this.chunks[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
// p2pubkeyhash
|
|
|
|
else if (this.isPubkeyHashScript()) { |
|
|
|
ret.push(this.chunks[0]); |
|
|
|
} |
|
|
|
// p2pubkey
|
|
|
|
else { |
|
|
|
// no signatures
|
|
|
|
} |
|
|
|
return ret; |
|
|
|
}; |
|
|
|
|
|
|
|
Script.prototype.getHashType = function() { |
|
|
|
var sigs = this.getSignatures(); |
|
|
|
var hashType = null; |
|
|
|
for (var i=0; i<sigs.length; i++) { |
|
|
|
var sig = sigs[i]; |
|
|
|
var hashTypeI = sig[sig.length - 1]; |
|
|
|
if (hashType !== null && hashType !== hashTypeI) return null; |
|
|
|
hashType = hashTypeI; |
|
|
|
} |
|
|
|
return hashType; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Script.prototype.countMissingSignatures = function() { |
|
|
|
if (this.isMultiSig()) { |
|
|
|
log.debug("Can not count missing signatures on normal Multisig script"); |
|
|
|