Browse Source

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:
- e54ebbf600/src/script/script.cpp (L13)
- e54ebbf600/src/core_write.cpp (L75)
patch-2
Braydon Fuller 9 years ago
parent
commit
0a052355bb
  1. 16
      lib/script/script.js

16
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') {
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();

Loading…
Cancel
Save