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) {
|
||||
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;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user