Speed up isPublicKeyOut
This commit is contained in:
parent
1a809cbeec
commit
9f4b1a2c26
|
@ -32,6 +32,14 @@ async.series([
|
|||
}
|
||||
}
|
||||
|
||||
function isPublicKeyOut() {
|
||||
if (c >= scripts.length) {
|
||||
c = 0;
|
||||
}
|
||||
scripts[c].isPublicKeyOut();
|
||||
c++;
|
||||
}
|
||||
|
||||
function isPublicKeyHashIn() {
|
||||
if (c >= scripts.length) {
|
||||
c = 0;
|
||||
|
@ -58,6 +66,7 @@ async.series([
|
|||
|
||||
var suite = new benchmark.Suite();
|
||||
suite.add('isPublicKeyHashIn', isPublicKeyHashIn, {maxTime: maxTime});
|
||||
suite.add('isPublicKeyOut', isPublicKeyOut, {maxTime: maxTime});
|
||||
suite.add('toAddress', toAddress, {maxTime: maxTime});
|
||||
suite.add('getAddressInfo', getAddressInfo, {maxTime: maxTime});
|
||||
suite
|
||||
|
|
|
@ -276,10 +276,21 @@ Script.prototype.getPublicKeyHash = function() {
|
|||
* @returns {boolean} if this is a public key output script
|
||||
*/
|
||||
Script.prototype.isPublicKeyOut = function() {
|
||||
return this.chunks.length === 2 &&
|
||||
BufferUtil.isBuffer(this.chunks[0].buf) &&
|
||||
PublicKey.isValid(this.chunks[0].buf) &&
|
||||
this.chunks[1].opcodenum === Opcode.OP_CHECKSIG;
|
||||
if (this.chunks.length === 2 &&
|
||||
this.chunks[0].buf &&
|
||||
this.chunks[0].buf.length &&
|
||||
this.chunks[1].opcodenum === Opcode.OP_CHECKSIG) {
|
||||
var pubkeyBuf = this.chunks[0].buf;
|
||||
var version = pubkeyBuf[0];
|
||||
if ((version === 0x04 ||
|
||||
version === 0x06 ||
|
||||
version === 0x07) && pubkeyBuf.length === 65) {
|
||||
return true;
|
||||
} else if ((version === 0x03 || version === 0x02) && pubkeyBuf.length === 33) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue