framer: fix block framing.
Signed-off-by: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
parent
6d9c150134
commit
f3c9ebd9a5
@ -257,32 +257,41 @@ Framer.block = function _block(block, type) {
|
|||||||
var p = [];
|
var p = [];
|
||||||
var off = 0;
|
var off = 0;
|
||||||
|
|
||||||
|
// version
|
||||||
|
assert.equal(off, 0);
|
||||||
off += writeU32(p, constants.version, off);
|
off += writeU32(p, constants.version, off);
|
||||||
|
|
||||||
// prev_block
|
// prev_block
|
||||||
|
assert.equal(off, 4);
|
||||||
utils.toArray(block.prevBlock, 'hex').forEach(function(ch) {
|
utils.toArray(block.prevBlock, 'hex').forEach(function(ch) {
|
||||||
p[off++] = ch;
|
p[off++] = ch;
|
||||||
});
|
});
|
||||||
|
|
||||||
// merkle_root
|
// merkle_root
|
||||||
|
assert.equal(off, 36);
|
||||||
utils.toArray(block.merkleRoot, 'hex').forEach(function(ch) {
|
utils.toArray(block.merkleRoot, 'hex').forEach(function(ch) {
|
||||||
p[off++] = ch;
|
p[off++] = ch;
|
||||||
});
|
});
|
||||||
|
|
||||||
// timestamp
|
// timestamp
|
||||||
|
assert.equal(off, 68);
|
||||||
off += writeU32(p, block.ts, off);
|
off += writeU32(p, block.ts, off);
|
||||||
|
|
||||||
// bits
|
// bits
|
||||||
|
assert.equal(off, 72);
|
||||||
off += writeU32(p, block.bits, off);
|
off += writeU32(p, block.bits, off);
|
||||||
|
|
||||||
// nonce
|
// nonce
|
||||||
|
assert.equal(off, 76);
|
||||||
off += writeU32(p, block.nonce, off);
|
off += writeU32(p, block.nonce, off);
|
||||||
|
|
||||||
// txn_count
|
// txn_count (spec says this is a varint for some reason)
|
||||||
off += varint(p, block.totalTX, off);
|
assert.equal(off, 80);
|
||||||
|
off += writeU32(p, block.totalTX, off);
|
||||||
|
|
||||||
if (type === 'merkleblock') {
|
if (type === 'merkleblock') {
|
||||||
// hash count
|
// hash count
|
||||||
|
assert.equal(off, 84);
|
||||||
off += varint(p, block.hashes.length, off);
|
off += varint(p, block.hashes.length, off);
|
||||||
// hashes
|
// hashes
|
||||||
block.hashes.forEach(function(hash) {
|
block.hashes.forEach(function(hash) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user