diff --git a/lib/bcoin/script.js b/lib/bcoin/script.js index 0949670d..af76103f 100644 --- a/lib/bcoin/script.js +++ b/lib/bcoin/script.js @@ -35,12 +35,12 @@ script.decode = function decode(s) { opcodes.push(s.slice(i, i + len)); i += 2 + len; } else if (opcode === 'pushdata2') { - var len = readU16(s, i); + var len = utils.readU16(s, i); i += 2; opcodes.push(s.slice(i, i + len)); i += len; } else if (opcode === 'pushdata4') { - var len = readU32(s, i); + var len = utils.readU32(s, i); i += 4; opcodes.push(s.slice(i, i + len)); i += len; diff --git a/lib/bcoin/utils.js b/lib/bcoin/utils.js index f2afa256..1adf947e 100644 --- a/lib/bcoin/utils.js +++ b/lib/bcoin/utils.js @@ -134,6 +134,12 @@ utils.dsha256 = function dsha256(data, enc) { return utils.sha256(utils.sha256(data, enc)); }; +utils.readU16 = function readU16(arr, off) { + if (!off) + off = 0; + return arr[off] | (arr[off + 1] << 8); +}; + utils.readU32 = function readU32(arr, off) { if (!off) off = 0;