Browse Source

Merge pull request #19 from braydonf/pushdata1

Script: Account for reverseMap name inconsistencies
patch-2
Matias Alejo Garcia 7 years ago
committed by GitHub
parent
commit
ee61039f50
  1. 18
      lib/script/script.js
  2. 12
      test/script/script.js

18
lib/script/script.js

@ -230,7 +230,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) {
@ -244,7 +258,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();

12
test/script/script.js

@ -237,6 +237,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() {

Loading…
Cancel
Save