chainentry.fromBlock.

This commit is contained in:
Christopher Jeffrey 2016-06-28 23:28:58 -07:00
parent 1aa70f8ff0
commit 4a8ef06154
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 6 additions and 23 deletions

View File

@ -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

View File

@ -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);
});
});