Browse Source

add script.isStandard()

patch-2
Manuel Araoz 10 years ago
parent
commit
ef8f1eabd2
  1. 9
      lib/script.js
  2. 14
      test/script.js

9
lib/script.js

@ -329,6 +329,15 @@ Script.prototype.classify = function() {
return Script.types.UNKNOWN;
};
/**
* @returns true if script is one of the known types
*/
Script.prototype.isStandard = function() {
return this.classify() !== Script.types.UNKNOWN;
};
// Script construction methods
/**

14
test/script.js

@ -166,6 +166,11 @@ describe('Script', function() {
describe('#toString', function() {
it('should work with an empty script', function() {
var script = new Script();
script.toString().should.equal('');
});
it('should output this buffer an OP code, data, and another OP code', function() {
var buf = new Buffer([0, 0, 0, 0, 0, 0, 1, 2, 3, 0]);
buf[0] = Opcode('OP_0').toNumber();
@ -361,4 +366,13 @@ describe('Script', function() {
});
});
describe('#isStandard', function() {
it('should classify correctly standard script', function() {
Script('OP_RETURN 1 0x00').isStandard().should.equal(true);
});
it('should classify correctly non standard script', function() {
Script('OP_TRUE OP_FALSE').isStandard().should.equal(false);
});
});
});

Loading…
Cancel
Save