Merge pull request #23 from chjj/block-size

parser: fix minimum block size.
This commit is contained in:
Christopher Jeffrey 2014-06-03 09:56:56 -05:00
commit 5a67c56b00
3 changed files with 11 additions and 8 deletions

View File

@ -195,7 +195,9 @@ Block.prototype._checkBlock = function checkBlock() {
} }
// First TX must be a coinbase // First TX must be a coinbase
if (this.txs[0].inputs.length !== 1 || +this.txs[0].inputs[0].out.hash !== 0) { if (!this.txs.length ||
this.txs[0].inputs.length !== 1 ||
+this.txs[0].inputs[0].out.hash !== 0) {
return false; return false;
} }

View File

@ -91,10 +91,9 @@ Framer.prototype.version = function version(packet) {
p[off++] = 0; p[off++] = 0;
} else { } else {
off += varint(p, this.agent.length, off); off += varint(p, this.agent.length, off);
for (var i = 0; i < this.agent.length; i++) { for (var i = 0; i < this.agent.length; i++)
p[off++] = this.agent[i]; p[off++] = this.agent[i];
} }
}
// Start height // Start height
off += writeU32(p, packet.height || 0, off); off += writeU32(p, packet.height || 0, off);

View File

@ -215,7 +215,7 @@ Parser.prototype.parseMerkleBlock = function parseMerkleBlock(p) {
}; };
Parser.prototype.parseBlock = function parseBlock(p) { Parser.prototype.parseBlock = function parseBlock(p) {
if (p.length < 84) if (p.length < 81)
return this._error('Invalid block size'); return this._error('Invalid block size');
var result = readIntv(p, 80); var result = readIntv(p, 80);
@ -223,11 +223,13 @@ Parser.prototype.parseBlock = function parseBlock(p) {
var totalTX = result.r; var totalTX = result.r;
var txs = []; var txs = [];
if (p.length >= off + 10) {
for (var i = 0; i < totalTX; i++) { for (var i = 0; i < totalTX; i++) {
var tx = this.parseTX(p.slice(off)); var tx = this.parseTX(p.slice(off));
off += tx._off; off += tx._off;
txs.push(tx); txs.push(tx);
} }
}
return { return {
version: readU32(p, 0), version: readU32(p, 0),