From 0a052355bbb6ab99e4267d28ad2a968a9a908a99 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Mon, 16 Nov 2015 12:49:31 -0500 Subject: [PATCH] Script: Account for reverseMap name inconsistencies There are a few cases where the opcode name doesn't match the name exactly. These are mostly related with data pushes, and the cases for `OP_0` and `OP_1NEGATE` were not handled as data pushes as the buf.length was 0. This adds these exceptions to the `_chunkToString` method on Script. References: - https://github.com/bitcoin/bitcoin/blob/e54ebbf6009716a7abcd4d8d3f7bd910e88decdc/src/script/script.cpp#L13 - https://github.com/bitcoin/bitcoin/blob/e54ebbf6009716a7abcd4d8d3f7bd910e88decdc/src/core_write.cpp#L75 --- lib/script/script.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/script/script.js b/lib/script/script.js index 176efdb..24c31c9 100644 --- a/lib/script/script.js +++ b/lib/script/script.js @@ -228,7 +228,21 @@ Script.prototype._chunkToString = function(chunk, type) { if (!chunk.buf) { // no data chunk if (typeof Opcode.reverseMap[opcodenum] !== 'undefined') { - str = str + ' ' + Opcode(opcodenum).toString(); + if (asm) { + // A few cases where the opcode name differs from reverseMap + // aside from 1 to 16 data pushes. + if (opcodenum === 0) { + // OP_0 -> 0 + str = str + ' 0'; + } else if(opcodenum === 79) { + // OP_1NEGATE -> 1 + str = str + ' -1'; + } else { + str = str + ' ' + Opcode(opcodenum).toString(); + } + } else { + str = str + ' ' + Opcode(opcodenum).toString(); + } } else { var numstr = opcodenum.toString(16); if (numstr.length % 2 !== 0) { @@ -242,7 +256,7 @@ Script.prototype._chunkToString = function(chunk, type) { } } else { // data chunk - if (opcodenum === Opcode.OP_PUSHDATA1 || + if (!asm && opcodenum === Opcode.OP_PUSHDATA1 || opcodenum === Opcode.OP_PUSHDATA2 || opcodenum === Opcode.OP_PUSHDATA4) { str = str + ' ' + Opcode(opcodenum).toString();