optimize memblock parsing.

This commit is contained in:
Christopher Jeffrey 2016-07-01 05:27:05 -07:00
parent f1bbd7736a
commit 3fb5a36f8d
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -113,7 +113,7 @@ MemBlock.prototype.getCoinbaseHeight = function getCoinbaseHeight() {
*/ */
MemBlock.prototype.fromRaw = function fromRaw(data) { MemBlock.prototype.fromRaw = function fromRaw(data) {
var p = bcoin.reader(data); var p = bcoin.reader(data, true);
var height = -1; var height = -1;
var inCount, input; var inCount, input;
@ -126,7 +126,7 @@ MemBlock.prototype.fromRaw = function fromRaw(data) {
this.totalTX = p.readVarint(); this.totalTX = p.readVarint();
if (this.version > 1 && this.totalTX > 0) { if (this.version > 1 && this.totalTX > 0) {
p.readU32(); // Technically signed p.seek(4);
inCount = p.readVarint(); inCount = p.readVarint();
if (inCount === 0) { if (inCount === 0) {
@ -134,13 +134,13 @@ MemBlock.prototype.fromRaw = function fromRaw(data) {
inCount = p.readVarint(); inCount = p.readVarint();
} }
if (inCount > 0) if (inCount > 0) {
input = bcoin.input.fromRaw(p); p.seek(36);
input = p.readVarBytes();
height = bcoin.script.getCoinbaseHeight(input);
}
} }
if (input)
height = bcoin.script.getCoinbaseHeight(input.script.raw);
this.coinbaseHeight = height; this.coinbaseHeight = height;
this.raw = p.data; this.raw = p.data;