script: fromOptions.
This commit is contained in:
parent
3a652727c9
commit
9fe97dc855
@ -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;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user