framer: frame regular blocks with transactions correctly.

This commit is contained in:
Christopher Jeffrey 2014-05-23 23:26:47 -05:00
parent e3e324441b
commit 60a9e556f8

View File

@ -303,11 +303,11 @@ Framer.block = function _block(block, type) {
assert.equal(off, 76);
off += writeU32(p, block.nonce, 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') {
// txn_count
off += writeU32(p, block.totalTX, off);
// hash count
assert.equal(off, 84);
off += varint(p, block.hashes.length, off);
@ -323,6 +323,15 @@ Framer.block = function _block(block, type) {
block.flags.forEach(function(flag) {
p[off++] = flag;
});
} else if (type === 'block') {
// txn_count
off += varint(p, block.totalTX, off);
// txs
block.txs.forEach(function(tx) {
tx._raw.forEach(function(ch) {
p[off++] = ch;
});
});
}
return p;