|
|
@ -3,9 +3,9 @@ |
|
|
|
var BufferReader = require('./encoding/bufferreader'); |
|
|
|
var BufferWriter = require('./encoding/bufferwriter'); |
|
|
|
var Opcode = require('./opcode'); |
|
|
|
var Address = require('./address'); |
|
|
|
var PublicKey = require('./publickey'); |
|
|
|
var Hash = require('./crypto/hash'); |
|
|
|
var bu = require('./util/buffer'); |
|
|
|
|
|
|
|
var Script = function Script(from) { |
|
|
|
if (!(this instanceof Script)) { |
|
|
@ -14,7 +14,7 @@ var Script = function Script(from) { |
|
|
|
|
|
|
|
this.chunks = []; |
|
|
|
|
|
|
|
if (Buffer.isBuffer(from)) { |
|
|
|
if (bu.isBuffer(from)) { |
|
|
|
return Script.fromBuffer(from); |
|
|
|
} else if (typeof from === 'string') { |
|
|
|
return Script.fromString(from); |
|
|
@ -205,7 +205,7 @@ Script.prototype.isPublicKeyHashIn = function() { |
|
|
|
*/ |
|
|
|
Script.prototype.isPublicKeyOut = function() { |
|
|
|
return this.chunks.length === 2 && |
|
|
|
Buffer.isBuffer(this.chunks[0].buf) && |
|
|
|
bu.isBuffer(this.chunks[0].buf) && |
|
|
|
PublicKey.isValid(this.chunks[0].buf) && |
|
|
|
this.chunks[1] === Opcode('OP_CHECKSIG').toNumber(); |
|
|
|
}; |
|
|
@ -215,7 +215,7 @@ Script.prototype.isPublicKeyOut = function() { |
|
|
|
*/ |
|
|
|
Script.prototype.isPublicKeyIn = function() { |
|
|
|
return this.chunks.length === 1 && |
|
|
|
Buffer.isBuffer(this.chunks[0].buf) && |
|
|
|
bu.isBuffer(this.chunks[0].buf) && |
|
|
|
this.chunks[0].buf.length === 0x47; |
|
|
|
}; |
|
|
|
|
|
|
@ -259,7 +259,7 @@ 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); |
|
|
|
return obj.buf && bu.isBuffer(obj.buf); |
|
|
|
}) && |
|
|
|
Opcode.isSmallIntOp(this.chunks[this.chunks.length - 2]) && |
|
|
|
this.chunks[this.chunks.length - 1] === Opcode.map.OP_CHECKMULTISIG); |
|
|
@ -273,7 +273,7 @@ Script.prototype.isMultisigIn = function() { |
|
|
|
return this.chunks[0] === 0 && |
|
|
|
this.chunks.slice(1, this.chunks.length).every(function(obj) { |
|
|
|
return obj.buf && |
|
|
|
Buffer.isBuffer(obj.buf) && |
|
|
|
bu.isBuffer(obj.buf) && |
|
|
|
obj.buf.length === 0x47; |
|
|
|
}); |
|
|
|
}; |
|
|
@ -367,7 +367,7 @@ Script.prototype._addByType = function(obj, prepend) { |
|
|
|
this._addOpcode(obj, prepend); |
|
|
|
} else if (obj.constructor && obj.constructor.name && obj.constructor.name === 'Opcode') { |
|
|
|
this._addOpcode(obj, prepend); |
|
|
|
} else if (Buffer.isBuffer(obj)) { |
|
|
|
} else if (bu.isBuffer(obj)) { |
|
|
|
this._addBuffer(obj, prepend); |
|
|
|
} else if (typeof obj === 'object') { |
|
|
|
this._insertAtPosition(obj, prepend); |
|
|
|