From 4a8ef06154d81107f5ae7e296fd43e0ab91cc2b1 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 28 Jun 2016 23:28:58 -0700 Subject: [PATCH] chainentry.fromBlock. --- lib/bcoin/chain.js | 15 ++++----------- lib/bcoin/chaindb.js | 14 ++------------ 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index f95d8a2d..7bb562b0 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -421,8 +421,10 @@ Chain.prototype._preload = function _preload(callback) { return callback(new Error('Bad headers.')); } + block.setHeight(height); + // Create a chain entry. - entry = new bcoin.chainentry(self, data, lastEntry); + entry = bcoin.chainentry.fromBlock(self, block, lastEntry); if (entry.height > chainHeight) save(entry, block); @@ -1563,16 +1565,7 @@ Chain.prototype.add = function add(block, callback, force) { block.setHeight(height); // Create a new chain entry. - entry = new bcoin.chainentry(self, { - hash: hash, - version: block.version, - prevBlock: block.prevBlock, - merkleRoot: block.merkleRoot, - ts: block.ts, - bits: block.bits, - nonce: block.nonce, - height: height - }, prev); + entry = bcoin.chainentry.fromBlock(self, block, prev); // The block is on a alternate chain if the // chainwork is less than or equal to diff --git a/lib/bcoin/chaindb.js b/lib/bcoin/chaindb.js index 29835c00..e89b9b21 100644 --- a/lib/bcoin/chaindb.js +++ b/lib/bcoin/chaindb.js @@ -253,21 +253,11 @@ ChainDB.prototype._init = function _init() { if (exists) return finish(); - genesis = new bcoin.chainentry(self.chain, { - hash: self.network.genesis.hash, - version: self.network.genesis.version, - prevBlock: self.network.genesis.prevBlock, - merkleRoot: self.network.genesis.merkleRoot, - ts: self.network.genesis.ts, - bits: self.network.genesis.bits, - nonce: self.network.genesis.nonce, - height: 0, - chainwork: null - }, null); - block = bcoin.block.fromRaw(self.network.genesisBlock, 'hex'); block.setHeight(0); + genesis = bcoin.chainentry.fromBlock(self.chain, block); + self.save(genesis, block, null, true, finish); }); });