Skip to content

Commit

Permalink
fix format in ScriptInterpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
maraoz committed Mar 7, 2014
1 parent 512d9d3 commit 9a64cb0
Showing 1 changed file with 63 additions and 63 deletions.
126 changes: 63 additions & 63 deletions ScriptInterpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function spec(b) {
function ScriptInterpreter() {
this.stack = [];
this.disableUnsafeOpcodes = true;
};
}

ScriptInterpreter.prototype.eval = function eval(script, tx, inIndex, hashType, callback) {
if ("function" !== typeof callback) {
Expand Down Expand Up @@ -76,22 +76,22 @@ function spec(b) {
}

if (this.disableUnsafeOpcodes &&
"number" === typeof opcode &&
(opcode === OP_CAT ||
opcode === OP_SUBSTR ||
opcode === OP_LEFT ||
opcode === OP_RIGHT ||
opcode === OP_INVERT ||
opcode === OP_AND ||
opcode === OP_OR ||
opcode === OP_XOR ||
opcode === OP_2MUL ||
opcode === OP_2DIV ||
opcode === OP_MUL ||
opcode === OP_DIV ||
opcode === OP_MOD ||
opcode === OP_LSHIFT ||
opcode === OP_RSHIFT)) {
"number" === typeof opcode &&
(opcode === OP_CAT ||
opcode === OP_SUBSTR ||
opcode === OP_LEFT ||
opcode === OP_RIGHT ||
opcode === OP_INVERT ||
opcode === OP_AND ||
opcode === OP_OR ||
opcode === OP_XOR ||
opcode === OP_2MUL ||
opcode === OP_2DIV ||
opcode === OP_MUL ||
opcode === OP_DIV ||
opcode === OP_MOD ||
opcode === OP_LSHIFT ||
opcode === OP_RSHIFT)) {
throw new Error("Encountered a disabled opcode");
}

Expand Down Expand Up @@ -619,34 +619,34 @@ function spec(b) {

// Verify signature
checkSig(sig, pubkey, scriptCode, tx, inIndex, hashType, function(e, result) {
try {
try {
var success;

if (e) {
// We intentionally ignore errors during signature verification and
// treat these cases as an invalid signature.
success = false;
// We intentionally ignore errors during signature verification and
// treat these cases as an invalid signature.
success = false;
} else {
success = result;
success = result;
}

// Update stack
this.stackPop();
this.stackPop();
this.stack.push(new Buffer([success ? 1 : 0]));
if (opcode === OP_CHECKSIGVERIFY) {
if (success) {
this.stackPop();
} else {
throw new Error("OP_CHECKSIGVERIFY negative");
}
if (success) {
this.stackPop();
} else {
throw new Error("OP_CHECKSIGVERIFY negative");
}
}

// Run next step
executeStep.call(this, cb);
} catch (e) {
cb(e);
}
} catch (e) {
cb(e);
}
}.bind(this));

// Note that for asynchronous opcodes we have to return here to prevent
Expand Down Expand Up @@ -690,12 +690,12 @@ function spec(b) {

// Drop the signatures, since a signature can't sign itself
sigs.forEach(function(sig) {
scriptCode.findAndDelete(sig);
});
scriptCode.findAndDelete(sig);
});

var success = true,
isig = 0,
ikey = 0;
isig = 0,
ikey = 0;
checkMultiSigStep.call(this);

function checkMultiSigStep() {
Expand All @@ -705,26 +705,26 @@ function spec(b) {
var key = keys[ikey];

checkSig(sig, key, scriptCode, tx, inIndex, hashType, function(e, result) {
try {
try {
if (!e && result) {
isig++;
sigsCount--;
isig++;
sigsCount--;
} else {
ikey++;
keysCount--;

// If there are more signatures than keys left, then too many
// signatures have failed
if (sigsCount > keysCount) {
success = false;
}
ikey++;
keysCount--;

// If there are more signatures than keys left, then too many
// signatures have failed
if (sigsCount > keysCount) {
success = false;
}
}

checkMultiSigStep.call(this);
} catch (e) {
} catch (e) {
cb(e);
}
}.bind(this));
}
}.bind(this));
} else {
this.stack.push(new Buffer([success ? 1 : 0]));
if (opcode === OP_CHECKMULTISIGVERIFY) {
Expand All @@ -748,7 +748,7 @@ function spec(b) {
return;

default:
console.log('opcode '+opcode);
console.log('opcode ' + opcode);
throw new Error("Unknown opcode encountered");
}

Expand All @@ -767,7 +767,7 @@ function spec(b) {
}
} catch (e) {
log.debug("Script aborted: " +
(e.message ? e.message : e));
(e.message ? e.message : e));
cb(e);
}
}
Expand All @@ -778,14 +778,14 @@ function spec(b) {
var self = this;

self.eval(scriptSig, tx, n, hashType, function(e) {
if (e) {
if (e) {
callback(e)
return;
}
}

self.eval(scriptPubkey, tx, n, hashType, callback);
});
};
self.eval(scriptPubkey, tx, n, hashType, callback);
});
};

/**
* Get the top element of the stack.
Expand Down Expand Up @@ -825,7 +825,7 @@ function spec(b) {
}

var s = this.stack,
l = s.length;
l = s.length;

var tmp = s[l - a];
s[l - a] = s[l - b];
Expand All @@ -840,16 +840,16 @@ function spec(b) {
*/
ScriptInterpreter.prototype.getPrimitiveStack = function getPrimitiveStack() {
return this.stack.map(function(entry) {
if (entry.length > 2) {
if (entry.length > 2) {
return buffertools.toHex(entry.slice(0));
}
var num = castBigint(entry);
if (num.cmp(-128) >= 0 && num.cmp(127) <= 0) {
}
var num = castBigint(entry);
if (num.cmp(-128) >= 0 && num.cmp(127) <= 0) {
return num.toNumber();
} else {
} else {
return buffertools.toHex(entry.slice(0));
}
});
}
});
};

var castBool = ScriptInterpreter.castBool = function castBool(v) {
Expand Down

0 comments on commit 9a64cb0

Please sign in to comment.