From d5f29c37b4d17b5b9e5ab8194ff2cdb37e71b3cb Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 14 May 2014 15:08:53 -0500 Subject: [PATCH] script: fix undefined error. Signed-off-by: Fedor Indutny --- lib/bcoin/script.js | 4 ++-- lib/bcoin/utils.js | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) 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;