Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Commit ee61039

Browse files
authored
Merge pull request #19 from braydonf/pushdata1
Script: Account for reverseMap name inconsistencies
2 parents 75c056f + 36b781d commit ee61039

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

lib/script/script.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,21 @@ Script.prototype._chunkToString = function(chunk, type) {
230230
if (!chunk.buf) {
231231
// no data chunk
232232
if (typeof Opcode.reverseMap[opcodenum] !== 'undefined') {
233-
str = str + ' ' + Opcode(opcodenum).toString();
233+
if (asm) {
234+
// A few cases where the opcode name differs from reverseMap
235+
// aside from 1 to 16 data pushes.
236+
if (opcodenum === 0) {
237+
// OP_0 -> 0
238+
str = str + ' 0';
239+
} else if(opcodenum === 79) {
240+
// OP_1NEGATE -> 1
241+
str = str + ' -1';
242+
} else {
243+
str = str + ' ' + Opcode(opcodenum).toString();
244+
}
245+
} else {
246+
str = str + ' ' + Opcode(opcodenum).toString();
247+
}
234248
} else {
235249
var numstr = opcodenum.toString(16);
236250
if (numstr.length % 2 !== 0) {
@@ -244,7 +258,7 @@ Script.prototype._chunkToString = function(chunk, type) {
244258
}
245259
} else {
246260
// data chunk
247-
if (opcodenum === Opcode.OP_PUSHDATA1 ||
261+
if (!asm && opcodenum === Opcode.OP_PUSHDATA1 ||
248262
opcodenum === Opcode.OP_PUSHDATA2 ||
249263
opcodenum === Opcode.OP_PUSHDATA4) {
250264
str = str + ' ' + Opcode(opcodenum).toString();

test/script/script.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,18 @@ describe('Script', function() {
237237
script.toASM().should.equal('OP_DUP OP_HASH160 f4c03610e60ad15100929cc23da2f3a799af1725 OP_EQUALVERIFY OP_CHECKSIG');
238238
});
239239

240+
it('should output this known script with pushdata1 opcode as ASM', function() {
241+
// network: livenet
242+
// txid: dd6fabd2d879be7b8394ad170ff908e9a36b5d5d0b394508df0cca36d2931589
243+
var script = Script.fromHex('00483045022100beb1d83771c04faaeb40bded4f031ed0e0730aaab77cf70102ecd05734a1762002206f168fb00f3b9d7c04b8c78e1fc11e81b9caa49885a904bf22780a7e14a8373101483045022100a319839e37828bf164ff45de34a3fe22d542ebc8297c5d87dbc56fc3068ff9d5022077081a877b6e7f104d8a2fe0985bf2eb7de2e08edbac9499fc3710a353f65461014c69522103a70ae7bde64333461fb88aaafe12ad6c67ca17c8213642469ae191e0aabc7251210344a62338c8ddf138771516d38187146242db50853aa588bcb10a5e49c86421a52102b52a1aed304c4d6cedcf82911f90ca6e1ffed0a5b8f7f19c68213d6fcbde677e53ae');
244+
script.toASM().should.equal('0 3045022100beb1d83771c04faaeb40bded4f031ed0e0730aaab77cf70102ecd05734a1762002206f168fb00f3b9d7c04b8c78e1fc11e81b9caa49885a904bf22780a7e14a8373101 3045022100a319839e37828bf164ff45de34a3fe22d542ebc8297c5d87dbc56fc3068ff9d5022077081a877b6e7f104d8a2fe0985bf2eb7de2e08edbac9499fc3710a353f6546101 522103a70ae7bde64333461fb88aaafe12ad6c67ca17c8213642469ae191e0aabc7251210344a62338c8ddf138771516d38187146242db50853aa588bcb10a5e49c86421a52102b52a1aed304c4d6cedcf82911f90ca6e1ffed0a5b8f7f19c68213d6fcbde677e53ae');
245+
});
246+
247+
it('should OP_1NEGATE opcode as -1 with ASM', function() {
248+
var script = Script.fromString('OP_1NEGATE');
249+
script.toASM().should.equal('-1');
250+
});
251+
240252
});
241253

242254
describe('toHex', function() {

0 commit comments

Comments
 (0)