From 3fb5a36f8dde3a447826aa6d7a9a05a4c04d5850 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 1 Jul 2016 05:27:05 -0700 Subject: [PATCH] optimize memblock parsing. --- lib/bcoin/memblock.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/bcoin/memblock.js b/lib/bcoin/memblock.js index 70e3873b..0b17f1ef 100644 --- a/lib/bcoin/memblock.js +++ b/lib/bcoin/memblock.js @@ -113,7 +113,7 @@ MemBlock.prototype.getCoinbaseHeight = function getCoinbaseHeight() { */ MemBlock.prototype.fromRaw = function fromRaw(data) { - var p = bcoin.reader(data); + var p = bcoin.reader(data, true); var height = -1; var inCount, input; @@ -126,7 +126,7 @@ MemBlock.prototype.fromRaw = function fromRaw(data) { this.totalTX = p.readVarint(); if (this.version > 1 && this.totalTX > 0) { - p.readU32(); // Technically signed + p.seek(4); inCount = p.readVarint(); if (inCount === 0) { @@ -134,13 +134,13 @@ MemBlock.prototype.fromRaw = function fromRaw(data) { inCount = p.readVarint(); } - if (inCount > 0) - input = bcoin.input.fromRaw(p); + if (inCount > 0) { + p.seek(36); + input = p.readVarBytes(); + height = bcoin.script.getCoinbaseHeight(input); + } } - if (input) - height = bcoin.script.getCoinbaseHeight(input.script.raw); - this.coinbaseHeight = height; this.raw = p.data;