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