Merge pull request #431 from ryanxcharles/bug/SIGHASH_ANYONECANPAY
use correct constant & share between Transaction and ScriptInterpreter
This commit is contained in:
commit
c4e22bf5fd
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue