Skip to content

Commit

Permalink
script: refactor opcode and optimize.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Aug 26, 2017
1 parent eabcf21 commit 49154be
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 231 deletions.
19 changes: 10 additions & 9 deletions lib/script/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ScriptNum = require('./scriptnum');
*/

exports.opcodes = {
OP_FALSE: 0x00,
// Push
OP_0: 0x00,

OP_PUSHDATA1: 0x4c,
Expand All @@ -34,7 +34,6 @@ exports.opcodes = {

OP_RESERVED: 0x50,

OP_TRUE: 0x51,
OP_1: 0x51,
OP_2: 0x52,
OP_3: 0x53,
Expand All @@ -52,6 +51,7 @@ exports.opcodes = {
OP_15: 0x5f,
OP_16: 0x60,

// Control
OP_NOP: 0x61,
OP_VER: 0x62,
OP_IF: 0x63,
Expand All @@ -63,6 +63,7 @@ exports.opcodes = {
OP_VERIFY: 0x69,
OP_RETURN: 0x6a,

// Stack
OP_TOALTSTACK: 0x6b,
OP_FROMALTSTACK: 0x6c,
OP_2DROP: 0x6d,
Expand All @@ -83,22 +84,24 @@ exports.opcodes = {
OP_SWAP: 0x7c,
OP_TUCK: 0x7d,

// Splice
OP_CAT: 0x7e,
OP_SUBSTR: 0x7f,
OP_LEFT: 0x80,
OP_RIGHT: 0x81,
OP_SIZE: 0x82,

// Bit
OP_INVERT: 0x83,
OP_AND: 0x84,
OP_OR: 0x85,
OP_XOR: 0x86,
OP_EQUAL: 0x87,
OP_EQUALVERIFY: 0x88,

OP_RESERVED1: 0x89,
OP_RESERVED2: 0x8a,

// Numeric
OP_1ADD: 0x8b,
OP_1SUB: 0x8c,
OP_2MUL: 0x8d,
Expand Down Expand Up @@ -127,6 +130,7 @@ exports.opcodes = {
OP_MAX: 0xa4,
OP_WITHIN: 0xa5,

// Crypto
OP_RIPEMD160: 0xa6,
OP_SHA1: 0xa7,
OP_SHA256: 0xa8,
Expand All @@ -138,11 +142,9 @@ exports.opcodes = {
OP_CHECKMULTISIG: 0xae,
OP_CHECKMULTISIGVERIFY: 0xaf,

OP_EVAL: 0xb0,
// Expansion
OP_NOP1: 0xb0,
OP_NOP2: 0xb1,
OP_CHECKLOCKTIMEVERIFY: 0xb1,
OP_NOP3: 0xb2,
OP_CHECKSEQUENCEVERIFY: 0xb2,
OP_NOP4: 0xb3,
OP_NOP5: 0xb4,
Expand All @@ -152,8 +154,7 @@ exports.opcodes = {
OP_NOP9: 0xb8,
OP_NOP10: 0xb9,

OP_PUBKEYHASH: 0xfd,
OP_PUBKEY: 0xfe,
// Custom
OP_INVALIDOPCODE: 0xff
};

Expand Down Expand Up @@ -496,7 +497,7 @@ exports.isSignatureEncoding = function isSignatureEncoding(sig) {

exports.toASM = function toASM(item, decode) {
if (item.length <= 4) {
const num = ScriptNum.decode(item, false, 4);
const num = ScriptNum.decode(item);
return num.toString(10);
}

Expand Down
Loading

0 comments on commit 49154be

Please sign in to comment.