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