script refactor.
This commit is contained in:
parent
f5ea3b1870
commit
616d9bd7f3
@ -200,6 +200,7 @@ MTX.prototype.addOutput = function addOutput(options, value) {
|
||||
output.value = value;
|
||||
} else {
|
||||
output.fromOptions(options);
|
||||
assert(output.value >= 0);
|
||||
}
|
||||
|
||||
this.outputs.push(output);
|
||||
|
||||
@ -48,7 +48,6 @@ Output.prototype.fromOptions = function fromOptions(options) {
|
||||
|
||||
if (options.value) {
|
||||
assert(utils.isNumber(options.value));
|
||||
assert(options.value >= 0);
|
||||
this.value = options.value;
|
||||
}
|
||||
|
||||
|
||||
@ -56,8 +56,18 @@ Witness.prototype.__defineSetter__('length', function(length) {
|
||||
*/
|
||||
|
||||
Witness.prototype.fromOptions = function fromOptions(options) {
|
||||
this.items = options.items || options;
|
||||
assert(Array.isArray(this.items));
|
||||
var items = options.items;
|
||||
|
||||
if (!items)
|
||||
items = options;
|
||||
|
||||
assert(Array.isArray(items));
|
||||
|
||||
// Duplicate:
|
||||
// items = items.slice();
|
||||
|
||||
this.items = items;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
@ -1123,23 +1133,23 @@ Script.prototype.fromOptions = function fromOptions(options) {
|
||||
raw = options.raw;
|
||||
}
|
||||
|
||||
if (code)
|
||||
if (code) {
|
||||
code = Script.parseArray(code);
|
||||
// Duplicate:
|
||||
// code = code.slice();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (!this.raw) {
|
||||
assert(this.code);
|
||||
this.raw = Script.encode(this.code);
|
||||
} else if (!this.code) {
|
||||
assert(this.raw);
|
||||
this.code = Script.decode(this.raw);
|
||||
}
|
||||
|
||||
assert(Buffer.isBuffer(this.raw));
|
||||
assert(Array.isArray(this.code));
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
@ -4358,6 +4368,8 @@ Script.encode = function encode(code, writer) {
|
||||
var p = new BufferWriter(writer);
|
||||
var i, op;
|
||||
|
||||
assert(Array.isArray(code));
|
||||
|
||||
for (i = 0; i < code.length; i++) {
|
||||
op = code[i];
|
||||
|
||||
@ -4406,6 +4418,8 @@ Script.parseArray = function parseArray(code) {
|
||||
var out = [];
|
||||
var i, op;
|
||||
|
||||
assert(Array.isArray(code));
|
||||
|
||||
if (code[0] instanceof Opcode)
|
||||
return code;
|
||||
|
||||
|
||||
@ -365,7 +365,6 @@ describe('Script', function() {
|
||||
coin._hashSequence = null;
|
||||
coin._hashOutputs = null;
|
||||
|
||||
delete input.redeem;
|
||||
delete input._address;
|
||||
delete output._address;
|
||||
}
|
||||
|
||||
@ -38,7 +38,6 @@ function clearCache(tx, nocache) {
|
||||
if (tx instanceof bcoin.script) {
|
||||
if (!nocache)
|
||||
return;
|
||||
tx.redeem = null;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -61,8 +60,6 @@ function clearCache(tx, nocache) {
|
||||
for (i = 0; i < tx.inputs.length; i++) {
|
||||
input = tx.inputs[i];
|
||||
input._address = null;
|
||||
input.script.redeem = null;
|
||||
input.witness.redeem = null;
|
||||
}
|
||||
|
||||
for (i = 0; i < tx.outputs.length; i++) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user