fix: minor fixes to block framer and block.
This commit is contained in:
parent
73ea21a903
commit
4e7dbae829
@ -32,11 +32,11 @@ function Block(data, subtype) {
|
|||||||
tx.ts = tx.ts || self.ts;
|
tx.ts = tx.ts || self.ts;
|
||||||
return tx;
|
return tx;
|
||||||
});
|
});
|
||||||
this.hashes = this.txs.map(function(tx) {
|
this.tx = this.txs.map(function(tx) {
|
||||||
return tx.hash('hex');
|
return tx.hash('hex');
|
||||||
});
|
});
|
||||||
this.tx = this.hashes.slice();
|
|
||||||
this.invalid = !this._checkBlock();
|
this.invalid = !this._checkBlock();
|
||||||
|
this.hashes = this.merkleTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._hash = null;
|
this._hash = null;
|
||||||
@ -193,7 +193,7 @@ Block.prototype.toJSON = function toJSON() {
|
|||||||
v: '1',
|
v: '1',
|
||||||
type: 'block',
|
type: 'block',
|
||||||
subtype: this.subtype,
|
subtype: this.subtype,
|
||||||
hash: this._hash || this.hash('hex'),
|
hash: this.hash('hex'),
|
||||||
prevBlock: this.prevBlock,
|
prevBlock: this.prevBlock,
|
||||||
ts: this.ts,
|
ts: this.ts,
|
||||||
block: utils.toHex(bcoin.protocol.framer.block(this, this.subtype))
|
block: utils.toHex(bcoin.protocol.framer.block(this, this.subtype))
|
||||||
|
|||||||
@ -276,32 +276,29 @@ Framer.block = function _block(block, type) {
|
|||||||
var p = [];
|
var p = [];
|
||||||
var off = 0;
|
var off = 0;
|
||||||
|
|
||||||
|
if (!type)
|
||||||
|
type = block.subtype;
|
||||||
|
|
||||||
// version
|
// version
|
||||||
assert.equal(off, 0);
|
|
||||||
off += writeU32(p, block.version, off);
|
off += writeU32(p, block.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);
|
||||||
|
|
||||||
assert.equal(off, 80);
|
assert.equal(off, 80);
|
||||||
@ -310,7 +307,6 @@ Framer.block = function _block(block, type) {
|
|||||||
// txn_count
|
// txn_count
|
||||||
off += writeU32(p, block.totalTX, off);
|
off += writeU32(p, block.totalTX, off);
|
||||||
// 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) {
|
||||||
@ -329,7 +325,8 @@ Framer.block = function _block(block, type) {
|
|||||||
off += varint(p, block.totalTX, off);
|
off += varint(p, block.totalTX, off);
|
||||||
// txs
|
// txs
|
||||||
block.txs.forEach(function(tx) {
|
block.txs.forEach(function(tx) {
|
||||||
tx._raw.forEach(function(ch) {
|
var raw = tx._raw || tx.render();
|
||||||
|
raw.forEach(function(ch) {
|
||||||
p[off++] = ch;
|
p[off++] = ch;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user