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
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;
}

View File

@ -91,9 +91,8 @@ Framer.prototype.version = function version(packet) {
p[off++] = 0;
} else {
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];
}
}
// Start height

View File

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