Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions test/script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@ describe('Script', function() {
script.toASM().should.equal('OP_DUP OP_HASH160 f4c03610e60ad15100929cc23da2f3a799af1725 OP_EQUALVERIFY OP_CHECKSIG');
});

it('should output this known script with pushdata1 opcode as ASM', function() {
// network: livenet
// txid: dd6fabd2d879be7b8394ad170ff908e9a36b5d5d0b394508df0cca36d2931589
var script = Script.fromHex('00483045022100beb1d83771c04faaeb40bded4f031ed0e0730aaab77cf70102ecd05734a1762002206f168fb00f3b9d7c04b8c78e1fc11e81b9caa49885a904bf22780a7e14a8373101483045022100a319839e37828bf164ff45de34a3fe22d542ebc8297c5d87dbc56fc3068ff9d5022077081a877b6e7f104d8a2fe0985bf2eb7de2e08edbac9499fc3710a353f65461014c69522103a70ae7bde64333461fb88aaafe12ad6c67ca17c8213642469ae191e0aabc7251210344a62338c8ddf138771516d38187146242db50853aa588bcb10a5e49c86421a52102b52a1aed304c4d6cedcf82911f90ca6e1ffed0a5b8f7f19c68213d6fcbde677e53ae');
script.toASM().should.equal('0 3045022100beb1d83771c04faaeb40bded4f031ed0e0730aaab77cf70102ecd05734a1762002206f168fb00f3b9d7c04b8c78e1fc11e81b9caa49885a904bf22780a7e14a8373101 3045022100a319839e37828bf164ff45de34a3fe22d542ebc8297c5d87dbc56fc3068ff9d5022077081a877b6e7f104d8a2fe0985bf2eb7de2e08edbac9499fc3710a353f6546101 522103a70ae7bde64333461fb88aaafe12ad6c67ca17c8213642469ae191e0aabc7251210344a62338c8ddf138771516d38187146242db50853aa588bcb10a5e49c86421a52102b52a1aed304c4d6cedcf82911f90ca6e1ffed0a5b8f7f19c68213d6fcbde677e53ae');
});

it('should OP_1NEGATE opcode as -1 with ASM', function() {
var script = Script.fromString('OP_1NEGATE');
script.toASM().should.equal('-1');
});

});

describe('toHex', function() {
Expand Down