From f3c9ebd9a535e7b76df72b873d69d342cbecb33d Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 18 May 2014 11:31:32 -0500 Subject: [PATCH] framer: fix block framing. Signed-off-by: Fedor Indutny --- lib/bcoin/protocol/framer.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/bcoin/protocol/framer.js b/lib/bcoin/protocol/framer.js index c183f2f1..55ae74de 100644 --- a/lib/bcoin/protocol/framer.js +++ b/lib/bcoin/protocol/framer.js @@ -257,32 +257,41 @@ Framer.block = function _block(block, type) { var p = []; var off = 0; + // version + assert.equal(off, 0); off += writeU32(p, constants.version, off); // prev_block + assert.equal(off, 4); utils.toArray(block.prevBlock, 'hex').forEach(function(ch) { p[off++] = ch; }); // merkle_root + assert.equal(off, 36); utils.toArray(block.merkleRoot, 'hex').forEach(function(ch) { p[off++] = ch; }); // timestamp + assert.equal(off, 68); off += writeU32(p, block.ts, off); // bits + assert.equal(off, 72); off += writeU32(p, block.bits, off); // nonce + assert.equal(off, 76); off += writeU32(p, block.nonce, off); - // txn_count - off += varint(p, block.totalTX, off); + // txn_count (spec says this is a varint for some reason) + assert.equal(off, 80); + off += writeU32(p, block.totalTX, off); if (type === 'merkleblock') { // hash count + assert.equal(off, 84); off += varint(p, block.hashes.length, off); // hashes block.hashes.forEach(function(hash) {