chain: refactor open.
This commit is contained in:
parent
6589cdc95b
commit
b7f82990c3
@ -218,23 +218,26 @@ ChainDB.layout = layout;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ChainDB.prototype._open = co(function* open() {
|
ChainDB.prototype._open = co(function* open() {
|
||||||
var result, genesis, block;
|
var state, block, entry;
|
||||||
|
|
||||||
this.logger.info('Starting chain load.');
|
this.logger.info('Starting chain load.');
|
||||||
|
|
||||||
yield this.db.open();
|
yield this.db.open();
|
||||||
|
|
||||||
result = yield this.db.has(layout.e(this.network.genesis.hash));
|
yield this.db.checkVersion('V', 1);
|
||||||
|
|
||||||
if (result) {
|
state = yield this.db.get(layout.R);
|
||||||
yield this.initState();
|
|
||||||
|
if (state) {
|
||||||
|
// Grab the chainstate if we have one.
|
||||||
|
this.state = ChainState.fromRaw(state);
|
||||||
} else {
|
} else {
|
||||||
|
// Otherwise write the genesis block.
|
||||||
|
// (We assume this database is fresh).
|
||||||
block = bcoin.block.fromRaw(this.network.genesisBlock, 'hex');
|
block = bcoin.block.fromRaw(this.network.genesisBlock, 'hex');
|
||||||
block.setHeight(0);
|
block.setHeight(0);
|
||||||
|
entry = bcoin.chainentry.fromBlock(this.chain, block);
|
||||||
genesis = bcoin.chainentry.fromBlock(this.chain, block);
|
yield this.save(entry, block, new CoinView());
|
||||||
|
|
||||||
yield this.save(genesis, block, new CoinView());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.info('Chain successfully loaded.');
|
this.logger.info('Chain successfully loaded.');
|
||||||
@ -245,8 +248,6 @@ ChainDB.prototype._open = co(function* open() {
|
|||||||
this.state.tx,
|
this.state.tx,
|
||||||
this.state.coin,
|
this.state.coin,
|
||||||
utils.btc(this.state.value));
|
utils.btc(this.state.value));
|
||||||
|
|
||||||
yield this.db.checkVersion('V', 1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user