|
|
@ -87,7 +87,9 @@ Script.fromBuffer = function(buffer) { |
|
|
|
opcodenum: opcodenum |
|
|
|
}); |
|
|
|
} else { |
|
|
|
script.chunks.push(opcodenum); |
|
|
|
script.chunks.push({ |
|
|
|
opcodenum: opcodenum |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -99,13 +101,9 @@ Script.prototype.toBuffer = function() { |
|
|
|
|
|
|
|
for (var i = 0; i < this.chunks.length; i++) { |
|
|
|
var chunk = this.chunks[i]; |
|
|
|
var opcodenum; |
|
|
|
if (typeof chunk === 'number') { |
|
|
|
opcodenum = chunk; |
|
|
|
bw.writeUInt8(opcodenum); |
|
|
|
} else { |
|
|
|
opcodenum = chunk.opcodenum; |
|
|
|
bw.writeUInt8(chunk.opcodenum); |
|
|
|
var opcodenum = chunk.opcodenum; |
|
|
|
bw.writeUInt8(chunk.opcodenum); |
|
|
|
if (chunk.buf) { |
|
|
|
if (opcodenum < Opcode.map.OP_PUSHDATA1) { |
|
|
|
bw.write(chunk.buf); |
|
|
|
} else if (opcodenum === Opcode.map.OP_PUSHDATA1) { |
|
|
@ -163,7 +161,9 @@ Script.fromString = function(str) { |
|
|
|
}); |
|
|
|
i = i + 3; |
|
|
|
} else { |
|
|
|
script.chunks.push(opcodenum); |
|
|
|
script.chunks.push({ |
|
|
|
opcodenum: opcodenum |
|
|
|
}); |
|
|
|
i = i + 1; |
|
|
|
} |
|
|
|
} |
|
|
@ -175,23 +175,25 @@ Script.prototype.toString = function() { |
|
|
|
|
|
|
|
for (var i = 0; i < this.chunks.length; i++) { |
|
|
|
var chunk = this.chunks[i]; |
|
|
|
var opcodenum; |
|
|
|
if (typeof chunk === 'number') { |
|
|
|
opcodenum = chunk; |
|
|
|
str = str + Opcode(opcodenum).toString() + ' '; |
|
|
|
var opcodenum = chunk.opcodenum; |
|
|
|
if (!chunk.buf) { |
|
|
|
if (typeof Opcode.reverseMap[opcodenum] !== 'undefined') { |
|
|
|
str = str + ' ' + Opcode(opcodenum).toString(); |
|
|
|
} else { |
|
|
|
str = str + ' ' + '0x' + opcodenum.toString(16); |
|
|
|
} |
|
|
|
} else { |
|
|
|
opcodenum = chunk.opcodenum; |
|
|
|
if (opcodenum === Opcode.map.OP_PUSHDATA1 || |
|
|
|
opcodenum === Opcode.map.OP_PUSHDATA2 || |
|
|
|
opcodenum === Opcode.map.OP_PUSHDATA4) { |
|
|
|
str = str + Opcode(opcodenum).toString() + ' '; |
|
|
|
if (opcodenum === Opcode.OP_PUSHDATA1 || |
|
|
|
opcodenum === Opcode.OP_PUSHDATA2 || |
|
|
|
opcodenum === Opcode.OP_PUSHDATA4) { |
|
|
|
str = str + ' ' + Opcode(opcodenum).toString(); |
|
|
|
} |
|
|
|
str = str + chunk.len + ' '; |
|
|
|
str = str + '0x' + chunk.buf.toString('hex') + ' '; |
|
|
|
str = str + ' ' + chunk.len; |
|
|
|
str = str + ' ' + '0x' + chunk.buf.toString('hex'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return str.substr(0, str.length - 1); |
|
|
|
return str.substr(1); |
|
|
|
}; |
|
|
|
|
|
|
|
// script classification methods
|
|
|
@ -200,11 +202,14 @@ Script.prototype.toString = function() { |
|
|
|
* @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() && |
|
|
|
return this.chunks[0] && this.chunks[0].opcodenum === Opcode.OP_DUP && |
|
|
|
this.chunks[1] && |
|
|
|
this.chunks[1].opcodenum === Opcode.OP_HASH160 && |
|
|
|
this.chunks[2].buf && |
|
|
|
this.chunks[3] === Opcode('OP_EQUALVERIFY').toNumber() && |
|
|
|
this.chunks[4] === Opcode('OP_CHECKSIG').toNumber(); |
|
|
|
this.chunks[3] && |
|
|
|
this.chunks[3].opcodenum === Opcode.OP_EQUALVERIFY && |
|
|
|
this.chunks[4] && |
|
|
|
this.chunks[4].opcodenum === Opcode.OP_CHECKSIG; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
@ -301,7 +306,7 @@ Script.prototype.isMultisigIn = function() { |
|
|
|
* @returns true if this is an OP_RETURN data script |
|
|
|
*/ |
|
|
|
Script.prototype.isDataOut = function() { |
|
|
|
return (this.chunks[0] === Opcode('OP_RETURN').toNumber() && |
|
|
|
return (this.chunks[0].opcodenum === Opcode('OP_RETURN').toNumber() && |
|
|
|
(this.chunks.length === 1 || |
|
|
|
(this.chunks.length === 2 && |
|
|
|
this.chunks[1].buf && |
|
|
@ -470,7 +475,7 @@ Script.prototype.removeCodeseparators = function() { |
|
|
|
* requiring m of those public keys to spend |
|
|
|
* @param {PublicKey[]} pubkeys - list of all public keys controlling the output |
|
|
|
* @param {number} m - amount of required signatures to spend the output |
|
|
|
* @param {Object} [opts] - Several options: |
|
|
|
* @param {Object} [opts] - Several options: |
|
|
|
* - noSorting: defaults to false, if true, don't sort the given |
|
|
|
* public keys before creating the script |
|
|
|
*/ |
|
|
|