Browse Source

ScriptInterpreter: convert verifyFull() to use callbacks

patch-2
Jeff Garzik 12 years ago
parent
commit
3a29b6e0dd
  1. 102
      ScriptInterpreter.js

102
ScriptInterpreter.js

@ -917,60 +917,86 @@ function spec(b) {
return si; return si;
}; };
ScriptInterpreter.verifyFull = function verifyStep4(scriptSig, scriptPubKey, txTo, nIn,
function verifyFull(scriptSig, scriptPubKey, txTo, nIn, hashType, opts) hashType, opts, callback, si, siCopy)
{ {
var si = new ScriptInterpreter(); if (siCopy.stack.length == 0) {
var siCopy = new ScriptInterpreter(); callback(null, false);
return;
}
var ok = true; callback(null, castBool(siCopy.stackBack()));
si.eval(scriptSig, txTo, nIn, hashType, function (err) { }
function verifyStep3(scriptSig, scriptPubKey, txTo, nIn,
hashType, opts, callback, si, siCopy)
{
if (si.stack.length == 0) {
callback(null, false);
return;
}
if (castBool(si.stackBack()) == false) {
callback(null, false);
return;
}
// if not P2SH, we're done
if (!opts.verifyP2SH || !scriptPubKey.isP2SH()) {
callback(null, true);
return;
}
if (!scriptSig.isPushOnly()) {
callback(null, false);
return;
}
assert.notEqual(siCopy.length, 0);
var subscript = new Script(siCopy.stackPop());
ok = true;
siCopy.eval(subscript, txTo, nIn, hashType, function (err) {
if (err) if (err)
ok = false; callback(err);
else
verifyStep4(scriptSig, scriptPubKey, txTo, nIn,
hashType, opts, callback, si, siCopy);
}); });
if (!ok) }
return false;
function verifyStep2(scriptSig, scriptPubKey, txTo, nIn,
hashType, opts, callback, si, siCopy)
{
if (opts.verifyP2SH) { if (opts.verifyP2SH) {
si.stack.forEach(function(item) { si.stack.forEach(function(item) {
siCopy.stack.push(item); siCopy.stack.push(item);
}); });
} }
ok = true;
si.eval(scriptPubKey, txTo, nIn, hashType, function (err) { si.eval(scriptPubKey, txTo, nIn, hashType, function (err) {
if (err) if (err)
ok = false; callback(err);
else
verifyStep3(scriptSig, scriptPubKey, txTo, nIn,
hashType, opts, callback, si, siCopy);
}); });
if (!ok) }
return false;
if (si.stack.length == 0)
return false;
if (castBool(si.stackBack()) == false)
return false;
if (opts.verifyP2SH && scriptPubKey.isP2SH()) {
if (!scriptSig.isPushOnly())
return false;
assert.notEqual(siCopy.length, 0);
var subscript = new Script(siCopy.stackPop());
ok = true; ScriptInterpreter.verifyFull =
siCopy.eval(subscript, txTo, nIn, hashType, function (err) { function verifyFull(scriptSig, scriptPubKey, txTo, nIn, hashType,
if (err) opts, callback)
ok = false; {
}); var si = new ScriptInterpreter();
if (!ok) var siCopy = new ScriptInterpreter();
return false;
if (siCopy.stack.length == 0)
return false;
return castBool(siCopy.stackBack());
}
return true; si.eval(scriptSig, txTo, nIn, hashType, function (err) {
if (err)
callback(err);
else
verifyStep2(scriptSig, scriptPubKey, txTo, nIn,
hashType, opts, callback, si, siCopy);
});
}; };
var checkSig = ScriptInterpreter.checkSig = var checkSig = ScriptInterpreter.checkSig =

Loading…
Cancel
Save