|
@ -2,6 +2,7 @@ |
|
|
|
|
|
|
|
|
var _ = require('lodash'); |
|
|
var _ = require('lodash'); |
|
|
var $ = require('./util/preconditions'); |
|
|
var $ = require('./util/preconditions'); |
|
|
|
|
|
var BufferUtil = require('./util/buffer'); |
|
|
|
|
|
|
|
|
function Opcode(num) { |
|
|
function Opcode(num) { |
|
|
if (!(this instanceof Opcode)) { |
|
|
if (!(this instanceof Opcode)) { |
|
@ -26,6 +27,11 @@ function Opcode(num) { |
|
|
return this; |
|
|
return this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Opcode.fromBuffer = function(buf) { |
|
|
|
|
|
$.checkArgument(BufferUtil.isBuffer(buf)); |
|
|
|
|
|
return new Opcode(Number('0x' + buf.toString('hex'))); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
Opcode.fromNumber = function(num) { |
|
|
Opcode.fromNumber = function(num) { |
|
|
$.checkArgument(_.isNumber(num)); |
|
|
$.checkArgument(_.isNumber(num)); |
|
|
return new Opcode(num); |
|
|
return new Opcode(num); |
|
@ -40,6 +46,14 @@ Opcode.fromString = function(str) { |
|
|
return new Opcode(value); |
|
|
return new Opcode(value); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Opcode.prototype.toHex = function() { |
|
|
|
|
|
return this.num.toString(16); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Opcode.prototype.toBuffer = function() { |
|
|
|
|
|
return new Buffer(this.toHex(), 'hex'); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
Opcode.prototype.toNumber = function() { |
|
|
Opcode.prototype.toNumber = function() { |
|
|
return this.num; |
|
|
return this.num; |
|
|
}; |
|
|
}; |
|
|