use correct constant & share between Transaction and ScriptInterpreter

Closes https://github.com/bitpay/bitcore/issues/424
This commit is contained in:
Ryan X. Charles 2014-07-15 11:59:56 -07:00
parent e75267bd01
commit 895bb6bab9
3 changed files with 19 additions and 14 deletions

View File

@ -8,11 +8,6 @@ var Util = require('../util');
var Script = require('./Script');
var Key = require('./Key');
var SIGHASH_ALL = 1;
var SIGHASH_NONE = 2;
var SIGHASH_SINGLE = 3;
var SIGHASH_ANYONECANPAY = 80;
var intToBufferSM = Util.intToBufferSM
var bufferSMToInt = Util.bufferSMToInt;
@ -22,6 +17,11 @@ function ScriptInterpreter(opts) {
this.disableUnsafeOpcodes = true;
};
var SIGHASH_ALL = ScriptInterpreter.SIGHASH_ALL = 1;
var SIGHASH_NONE = ScriptInterpreter.SIGHASH_NONE = 2;
var SIGHASH_SINGLE = ScriptInterpreter.SIGHASH_SINGLE = 3;
var SIGHASH_ANYONECANPAY = ScriptInterpreter.SIGHASH_ANYONECANPAY = 0x80;
ScriptInterpreter.prototype.eval = function eval(script, tx, inIndex, hashType, callback) {
if ("function" !== typeof callback) {
throw new Error("ScriptInterpreter.eval() requires a callback");

View File

@ -299,15 +299,10 @@ Transaction.prototype.getAffectedKeys = function getAffectedKeys(txCache) {
var OP_CODESEPARATOR = 171;
var SIGHASH_ALL = 1;
var SIGHASH_NONE = 2;
var SIGHASH_SINGLE = 3;
var SIGHASH_ANYONECANPAY = 0x80;
Transaction.SIGHASH_ALL = SIGHASH_ALL;
Transaction.SIGHASH_NONE = SIGHASH_NONE;
Transaction.SIGHASH_SINGLE = SIGHASH_SINGLE;
Transaction.SIGHASH_ANYONECANPAY = SIGHASH_ANYONECANPAY;
var SIGHASH_ALL = Transaction.SIGHASH_ALL = ScriptInterpreter.SIGHASH_ALL;
var SIGHASH_NONE = Transaction.SIGHASH_NONE = ScriptInterpreter.SIGHASH_NONE;
var SIGHASH_SINGLE = Transaction.SIGHASH_SINGLE = ScriptInterpreter.SIGHASH_SINGLE;
var SIGHASH_ANYONECANPAY = Transaction.SIGHASH_ANYONECANPAY = ScriptInterpreter.SIGHASH_ANYONECANPAY;
var TransactionSignatureSerializer = function(txTo, scriptCode, nIn, nHashType) {
this.txTo = txTo;

View File

@ -18,6 +18,16 @@ describe('ScriptInterpreter', function() {
var si = new ScriptInterpreter();
should.exist(si);
});
describe('SIGHASH constants', function() {
it('should equal the values from bitcoin core', function() {
ScriptInterpreter.SIGHASH_ALL.should.equal(1);
ScriptInterpreter.SIGHASH_NONE.should.equal(2);
ScriptInterpreter.SIGHASH_SINGLE.should.equal(3);
ScriptInterpreter.SIGHASH_ANYONECANPAY.should.equal(0x80);
});
});
var testScripts = function(data, valid) {
data.forEach(function(datum) {
if (datum.length < 2) throw new Error('Invalid test data');