From 2fd1d171f2cdaaea353d60a0a6ddb088d1d0fcf2 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 9 Dec 2015 12:11:32 -0800 Subject: [PATCH] handle op_1negate. --- lib/bcoin/protocol/constants.js | 9 ++------- lib/bcoin/script.js | 6 +++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/bcoin/protocol/constants.js b/lib/bcoin/protocol/constants.js index ba25f547..25075f09 100644 --- a/lib/bcoin/protocol/constants.js +++ b/lib/bcoin/protocol/constants.js @@ -57,7 +57,7 @@ exports.opcodes = { pushdata1: 0x4c, pushdata2: 0x4d, pushdata4: 0x4e, - negate1: 0x4f, + // negate1: 0x4f, nop1: 0x61, if_: 0x63, @@ -141,18 +141,13 @@ exports.opcodes = { checklocktimeverify: 0xb1 }; +exports.opcodes['-1'] = 0x50 + -1; for (var i = 1; i <= 16; i++) exports.opcodes[i] = 0x50 + i; for (var i = 0; i <= 7; i++) exports.opcodes['nop' + (i + 3)] = 0xb2 + i; -// exports.opcodes['false'] = exports.opcodes['0']; -// exports.opcodes['true'] = exports.opcodes['1']; - -// exports.opcodes['if'] = exports.opcodes.if_; -// exports.opcodes['else'] = exports.opcodes.else_; - exports.opcodesByVal = new Array(256); Object.keys(exports.opcodes).forEach(function(name) { exports.opcodesByVal[exports.opcodes[name]] = name; diff --git a/lib/bcoin/script.js b/lib/bcoin/script.js index 961e14a7..7e6dfd6d 100644 --- a/lib/bcoin/script.js +++ b/lib/bcoin/script.js @@ -25,8 +25,8 @@ script.decode = function decode(s) { continue; } - // Raw number - if (b >= 0x51 && b <= 0x60) { + // Raw number (-1 and 1-16) + if (b === 0x4f || (b >= 0x51 && b <= 0x60)) { opcodes.push(b - 0x50); continue; } @@ -170,7 +170,7 @@ script.execute = function execute(s, stack, tx, index) { continue; } - if (typeof o === 'number' && o >= 1 && o <= 16) { + if (o === -1 || (o >= 1 && o <= 16)) { stack.push([o]); continue; }