add Script#isPushOnly()
This commit is contained in:
parent
5bdda7c95b
commit
b61bd6f76a
|
@ -1,16 +1,15 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('lodash');
|
|
||||||
var bu = require('./util/buffer');
|
|
||||||
|
|
||||||
var Address = require('./address');
|
var Address = require('./address');
|
||||||
var BufferReader = require('./encoding/bufferreader');
|
var BufferReader = require('./encoding/bufferreader');
|
||||||
var BufferWriter = require('./encoding/bufferwriter');
|
var BufferWriter = require('./encoding/bufferwriter');
|
||||||
var Errors = require('./errors');
|
|
||||||
var Hash = require('./crypto/hash');
|
var Hash = require('./crypto/hash');
|
||||||
var Opcode = require('./opcode');
|
var Opcode = require('./opcode');
|
||||||
var PublicKey = require('./publickey');
|
var PublicKey = require('./publickey');
|
||||||
var PublicKey = require('./publickey');
|
var PublicKey = require('./publickey');
|
||||||
|
var Hash = require('./crypto/hash');
|
||||||
|
var bu = require('./util/buffer');
|
||||||
|
var _ = require('lodash');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A bitcoin transaction script. Each transaction's inputs and outputs
|
* A bitcoin transaction script. Each transaction's inputs and outputs
|
||||||
|
@ -304,6 +303,17 @@ Script.prototype.isDataOut = function() {
|
||||||
this.chunks[1].length === this.chunks.len)));
|
this.chunks[1].length === this.chunks.len)));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns true if the script is only composed of data pushing
|
||||||
|
* opcodes or small int opcodes (OP_0, OP_1, ..., OP_16)
|
||||||
|
*/
|
||||||
|
Script.prototype.isPushOnly = function() {
|
||||||
|
return _.every(this.chunks, function(chunk) {
|
||||||
|
var opcodenum = chunk.opcodenum;
|
||||||
|
return !_.isUndefined(opcodenum) || chunk <= Opcode.map.OP_16;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
Script.types = {};
|
Script.types = {};
|
||||||
Script.types.UNKNOWN = 'Unknown';
|
Script.types.UNKNOWN = 'Unknown';
|
||||||
|
|
|
@ -301,6 +301,17 @@ describe('Script', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#isPushOnly', function() {
|
||||||
|
it('should know these scripts are or aren\'t push only', function() {
|
||||||
|
Script('OP_NOP 1 0x01').isPushOnly().should.equal(false);
|
||||||
|
Script('OP_0').isPushOnly().should.equal(true);
|
||||||
|
Script('OP_0 OP_RETURN').isPushOnly().should.equal(false);
|
||||||
|
Script('OP_PUSHDATA1 5 0x1010101010').isPushOnly().should.equal(true);
|
||||||
|
// like bitcoind, we regard OP_RESERVED as being "push only"
|
||||||
|
Script('OP_RESERVED').isPushOnly().should.equal(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('#classify', function() {
|
describe('#classify', function() {
|
||||||
it('should classify public key hash out', function() {
|
it('should classify public key hash out', function() {
|
||||||
Script('OP_DUP OP_HASH160 20 0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG').classify().should.equal(Script.types.PUBKEYHASH_OUT);
|
Script('OP_DUP OP_HASH160 20 0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG').classify().should.equal(Script.types.PUBKEYHASH_OUT);
|
||||||
|
|
Loading…
Reference in New Issue