framer: fix block framing.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
Christopher Jeffrey 2014-05-18 11:31:32 -05:00 committed by Fedor Indutny
parent 6d9c150134
commit f3c9ebd9a5

View File

@ -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) {