script: fromOptions.

This commit is contained in:
Christopher Jeffrey 2016-07-01 06:03:48 -07:00
parent 3a652727c9
commit 9fe97dc855
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -56,17 +56,17 @@ Witness.prototype.__defineSetter__('length', function(length) {
*/ */
Witness.prototype.fromOptions = function fromOptions(options) { Witness.prototype.fromOptions = function fromOptions(options) {
var items = options.items; var items;
assert(options, 'Witness data is required.');
items = options.items;
if (!items) if (!items)
items = options; items = options;
assert(Array.isArray(items)); if (items)
this.fromArray(items);
// Duplicate:
// items = items.slice();
this.items = items;
return this; return this;
}; };
@ -1150,34 +1150,28 @@ Script.prototype.__defineSetter__('length', function(length) {
*/ */
Script.prototype.fromOptions = function fromOptions(options) { Script.prototype.fromOptions = function fromOptions(options) {
var code, raw; assert(options, 'Script data is required.');
if (Buffer.isBuffer(options)) { if (Buffer.isBuffer(options))
raw = options; return this.fromRaw(options);
} else if (Array.isArray(options)) {
code = options; if (Array.isArray(options))
} else { return this.fromArray(options);
code = options.code;
raw = options.raw; if (options.raw) {
if (!options.code)
return this.fromRaw(options.raw);
assert(Buffer.isBuffer(options.raw));
this.raw = options.raw;
} }
if (code) { if (options.code) {
code = Script.parseArray(code); if (!options.raw)
// Duplicate: return this.fromArray(options.code);
// code = code.slice(); assert(Array.isArray(options.code));
this.code = options.code;
} }
if (!raw)
raw = Script.encode(code);
else if (!code)
code = Script.decode(raw);
assert(Array.isArray(code));
assert(Buffer.isBuffer(raw));
this.raw = raw;
this.code = code;
return this; return this;
}; };
@ -4553,6 +4547,9 @@ Script.parseArray = function parseArray(code) {
assert(Array.isArray(code)); assert(Array.isArray(code));
if (code.length === 0)
return code;
if (code[0] instanceof Opcode) if (code[0] instanceof Opcode)
return code; return code;