remove console.logs and std::couts
This commit is contained in:
parent
406600720e
commit
0b2dae43c5
|
@ -33,7 +33,6 @@ ScriptInterpreter.prototype.eval = function eval(script, tx, inIndex, hashType,
|
||||||
throw new Error("ScriptInterpreter.eval() requires a callback");
|
throw new Error("ScriptInterpreter.eval() requires a callback");
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('eval script '+script.toHumanReadable());
|
|
||||||
var pc = 0;
|
var pc = 0;
|
||||||
var execStack = [];
|
var execStack = [];
|
||||||
var altStack = [];
|
var altStack = [];
|
||||||
|
@ -49,6 +48,7 @@ ScriptInterpreter.prototype.eval = function eval(script, tx, inIndex, hashType,
|
||||||
executeStep.call(this, callback);
|
executeStep.call(this, callback);
|
||||||
|
|
||||||
function executeStep(cb) {
|
function executeStep(cb) {
|
||||||
|
try {
|
||||||
// Once all chunks have been processed, execution ends
|
// Once all chunks have been processed, execution ends
|
||||||
if (pc >= script.chunks.length) {
|
if (pc >= script.chunks.length) {
|
||||||
// Execution stack must be empty at the end of the script
|
// Execution stack must be empty at the end of the script
|
||||||
|
@ -713,18 +713,15 @@ ScriptInterpreter.prototype.eval = function eval(script, tx, inIndex, hashType,
|
||||||
|
|
||||||
checkSig(sig, pubkey, scriptCode, tx, inIndex, hashType, function(e, result) {
|
checkSig(sig, pubkey, scriptCode, tx, inIndex, hashType, function(e, result) {
|
||||||
if (!e && result) {
|
if (!e && result) {
|
||||||
console.log('sig '+isig+' succeeded with key '+ikey);
|
|
||||||
isig++;
|
isig++;
|
||||||
sigsCount--;
|
sigsCount--;
|
||||||
} else {
|
} else {
|
||||||
console.log('key '+ikey+' failed to verify sig '+isig+': '+e +' '+result);
|
|
||||||
ikey++;
|
ikey++;
|
||||||
keysCount--;
|
keysCount--;
|
||||||
|
|
||||||
// If there are more signatures than keys left, then too many
|
// If there are more signatures than keys left, then too many
|
||||||
// signatures have failed
|
// signatures have failed
|
||||||
if (sigsCount > keysCount) {
|
if (sigsCount > keysCount) {
|
||||||
console.log('CHECKMULTISIG sigsCount > keysCount');
|
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -767,6 +764,9 @@ ScriptInterpreter.prototype.eval = function eval(script, tx, inIndex, hashType,
|
||||||
} else {
|
} else {
|
||||||
executeStep.call(this, cb);
|
executeStep.call(this, cb);
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
cb(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -916,29 +916,24 @@ ScriptInterpreter.prototype.verifyStep3 = function(scriptSig,
|
||||||
|
|
||||||
// if stack is empty, script considered invalid
|
// if stack is empty, script considered invalid
|
||||||
if (this.stack.length === 0) {
|
if (this.stack.length === 0) {
|
||||||
console.log('3rd step: no stack');
|
|
||||||
callback(null, false);
|
callback(null, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if top of stack contains false, script evaluated to false
|
// if top of stack contains false, script evaluated to false
|
||||||
if (castBool(this.stackBack()) == false) {
|
if (castBool(this.stackBack()) == false) {
|
||||||
console.log('3rd step: stack contains false');
|
|
||||||
callback(null, false);
|
callback(null, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if not P2SH, script evaluated to true
|
// if not P2SH, script evaluated to true
|
||||||
if (!this.opts.verifyP2SH || !scriptPubKey.isP2SH()) {
|
if (!this.opts.verifyP2SH || !scriptPubKey.isP2SH()) {
|
||||||
console.log('3rd step: done, true');
|
|
||||||
callback(null, true);
|
callback(null, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if P2SH, scriptSig should be push-only
|
// if P2SH, scriptSig should be push-only
|
||||||
if (!scriptSig.isPushOnly()) {
|
if (!scriptSig.isPushOnly()) {
|
||||||
console.log('3rd step: scriptSig should be push only');
|
|
||||||
console.log();
|
|
||||||
callback(null, false);
|
callback(null, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -952,7 +947,6 @@ ScriptInterpreter.prototype.verifyStep3 = function(scriptSig,
|
||||||
var that = this;
|
var that = this;
|
||||||
// evaluate the P2SH subscript
|
// evaluate the P2SH subscript
|
||||||
siCopy.eval(subscript, tx, nIn, hashType, function(err) {
|
siCopy.eval(subscript, tx, nIn, hashType, function(err) {
|
||||||
console.log('Err 3nd step: '+err);
|
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
that.verifyStep4(callback, siCopy);
|
that.verifyStep4(callback, siCopy);
|
||||||
});
|
});
|
||||||
|
@ -971,7 +965,6 @@ ScriptInterpreter.prototype.verifyStep2 = function(scriptSig, scriptPubKey,
|
||||||
var that = this;
|
var that = this;
|
||||||
// 2nd step, evaluate scriptPubKey
|
// 2nd step, evaluate scriptPubKey
|
||||||
this.eval(scriptPubKey, tx, nIn, hashType, function(err) {
|
this.eval(scriptPubKey, tx, nIn, hashType, function(err) {
|
||||||
console.log('Err 2nd step: '+err);
|
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
that.verifyStep3(scriptSig, scriptPubKey, tx, nIn,
|
that.verifyStep3(scriptSig, scriptPubKey, tx, nIn,
|
||||||
hashType, callback, siCopy);
|
hashType, callback, siCopy);
|
||||||
|
@ -984,7 +977,6 @@ ScriptInterpreter.prototype.verifyFull = function(scriptSig, scriptPubKey,
|
||||||
|
|
||||||
// 1st step, evaluate scriptSig
|
// 1st step, evaluate scriptSig
|
||||||
this.eval(scriptSig, tx, nIn, hashType, function(err) {
|
this.eval(scriptSig, tx, nIn, hashType, function(err) {
|
||||||
console.log('Err 1st step: '+err);
|
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
that.verifyStep2(scriptSig, scriptPubKey, tx, nIn,
|
that.verifyStep2(scriptSig, scriptPubKey, tx, nIn,
|
||||||
hashType, callback);
|
hashType, callback);
|
||||||
|
@ -1004,7 +996,6 @@ var checkSig = ScriptInterpreter.checkSig =
|
||||||
function(sig, pubkey, scriptCode, tx, n, hashType, callback) {
|
function(sig, pubkey, scriptCode, tx, n, hashType, callback) {
|
||||||
// https://en.bitcoin.it/wiki/OP_CHECKSIG#How_it_works
|
// https://en.bitcoin.it/wiki/OP_CHECKSIG#How_it_works
|
||||||
if (!sig.length) {
|
if (!sig.length) {
|
||||||
console.log('sig length 0');
|
|
||||||
callback(null, false);
|
callback(null, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1013,7 +1004,6 @@ var checkSig = ScriptInterpreter.checkSig =
|
||||||
if (hashType === 0) {
|
if (hashType === 0) {
|
||||||
hashType = sig[sig.length - 1];
|
hashType = sig[sig.length - 1];
|
||||||
} else if (hashType != sig[sig.length - 1]) {
|
} else if (hashType != sig[sig.length - 1]) {
|
||||||
console.log('wrong hashtype');
|
|
||||||
callback(null, false);
|
callback(null, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1022,20 +1012,13 @@ var checkSig = ScriptInterpreter.checkSig =
|
||||||
sig = sig.slice(0, sig.length - 1);
|
sig = sig.slice(0, sig.length - 1);
|
||||||
|
|
||||||
// Signature verification requires a special hash procedure
|
// Signature verification requires a special hash procedure
|
||||||
console.log('rawtx '+buffertools.toHex(tx.serialize()));
|
|
||||||
var hash = tx.hashForSignature(scriptCode, n, hashType);
|
var hash = tx.hashForSignature(scriptCode, n, hashType);
|
||||||
console.log('n ='+n+'; hashType='+hashType);
|
|
||||||
console.log('hash ='+ buffertools.toHex(hash));
|
|
||||||
|
|
||||||
// Verify signature
|
// Verify signature
|
||||||
var key = new Key();
|
var key = new Key();
|
||||||
if (pubkey.length === 0) pubkey = new Buffer('00', 'hex');
|
if (pubkey.length === 0) pubkey = new Buffer('00', 'hex');
|
||||||
key.public = pubkey;
|
key.public = pubkey;
|
||||||
|
|
||||||
console.log('pubkey before verification: '+buffertools.toHex(key.public));
|
|
||||||
console.log('sig before verification: '+buffertools.toHex(sig));
|
|
||||||
console.log('hash before verification: '+buffertools.toHex(hash));
|
|
||||||
|
|
||||||
key.verifySignature(hash, sig, callback);
|
key.verifySignature(hash, sig, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -313,7 +313,6 @@ Key::SetPublic(Local<String> property, Local<Value> value, const AccessorInfo& i
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
// TODO: Error
|
// TODO: Error
|
||||||
std::cout << ret << "C++++++++++++++++++++++++++++++++++++++\n";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ function parse_test_transaction(entry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Transaction', function() {
|
describe('Transaction', function() {
|
||||||
it.skip('should initialze the main object', function() {
|
it('should initialze the main object', function() {
|
||||||
should.exist(Transaction);
|
should.exist(Transaction);
|
||||||
In = Transaction.In;
|
In = Transaction.In;
|
||||||
Out = Transaction.Out;
|
Out = Transaction.Out;
|
||||||
|
@ -57,7 +57,7 @@ describe('Transaction', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it.skip('should be able to create instance', function() {
|
it('should be able to create instance', function() {
|
||||||
var t = new Transaction();
|
var t = new Transaction();
|
||||||
should.exist(t);
|
should.exist(t);
|
||||||
});
|
});
|
||||||
|
@ -76,8 +76,8 @@ describe('Transaction', function() {
|
||||||
var tx = testTx.transaction;
|
var tx = testTx.transaction;
|
||||||
|
|
||||||
describe((valid ? '' : 'in') + 'valid tx=' + raw, function() {
|
describe((valid ? '' : 'in') + 'valid tx=' + raw, function() {
|
||||||
it.skip('should parse correctly', function() {
|
it('should parse correctly', function() {
|
||||||
buffertools.toHex(tx.serialize()).should.equal(raw);
|
buffertools.toHex(tx.serialize()).toLowerCase().should.equal(raw.toLowerCase());
|
||||||
});
|
});
|
||||||
|
|
||||||
var inputs = tx.inputs();
|
var inputs = tx.inputs();
|
||||||
|
@ -91,7 +91,6 @@ describe('Transaction', function() {
|
||||||
input[0].copy(outpointHash);
|
input[0].copy(outpointHash);
|
||||||
input[0] = buffertools.reverse(outpointHash);
|
input[0] = buffertools.reverse(outpointHash);
|
||||||
input[0] = buffertools.toHex(input[0]);
|
input[0] = buffertools.toHex(input[0]);
|
||||||
buffertools.toHex(tx.serialize()).toLowerCase().should.equal(raw.toLowerCase());
|
|
||||||
var mapKey = [input];
|
var mapKey = [input];
|
||||||
var scriptPubKey = testTx.inputs[mapKey];
|
var scriptPubKey = testTx.inputs[mapKey];
|
||||||
if (!scriptPubKey) throw new Error('Bad test: ' + datum);
|
if (!scriptPubKey) throw new Error('Bad test: ' + datum);
|
||||||
|
@ -102,9 +101,14 @@ describe('Transaction', function() {
|
||||||
dontVerifyStrictEnc: true
|
dontVerifyStrictEnc: true
|
||||||
},
|
},
|
||||||
function(err, results) {
|
function(err, results) {
|
||||||
|
if (valid) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
should.exist(results);
|
should.exist(results);
|
||||||
results.should.equal(valid);
|
results.should.equal(valid);
|
||||||
|
} else {
|
||||||
|
var invalid = (typeof err !== 'undefined') || results === false;
|
||||||
|
invalid.should.equal(true);
|
||||||
|
}
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue