This commit is contained in:
Christopher Jeffrey 2016-02-16 21:04:10 -08:00
parent d0d0378f3e
commit 2dc3786eb0

View File

@ -49,17 +49,6 @@ function Chain(options) {
size: 0
};
this._saveEntry(bcoin.chainblock.fromJSON(this, {
hash: network.genesis.hash,
version: network.genesis.version,
prevBlock: network.genesis.prevBlock,
merkleRoot: network.genesis.merkleRoot,
ts: network.genesis.ts,
bits: network.genesis.bits,
nonce: network.genesis.nonce,
height: 0
}), true);
Chain.global = this;
this._init();
@ -91,37 +80,6 @@ Chain.msg = function msg(code) {
return Chain.messages[code] || 'Unknown';
};
Chain.prototype._ensureGenesis = function _ensureGenesis(callback) {
var self = this;
callback = utils.asyncify(callback);
if (!this.blockdb)
return callback();
self.blockdb.hasBlock(network.genesis.hash, function(err, result) {
var genesis;
if (err)
return callback(err);
if (result)
return callback();
utils.debug('BlockDB does not have genesis block. Adding.');
genesis = bcoin.block.fromRaw(network.genesisBlock, 'hex');
genesis.height = 0;
self.blockdb.saveBlock(genesis, function(err) {
if (err)
return callback(err);
return callback();
});
});
};
Chain.prototype._init = function _init() {
var self = this;
@ -210,6 +168,48 @@ Chain.prototype._init = function _init() {
});
};
Chain.prototype._ensureGenesis = function _ensureGenesis(callback) {
var self = this;
callback = utils.asyncify(callback);
this._saveEntry(bcoin.chainblock.fromJSON(this, {
hash: network.genesis.hash,
version: network.genesis.version,
prevBlock: network.genesis.prevBlock,
merkleRoot: network.genesis.merkleRoot,
ts: network.genesis.ts,
bits: network.genesis.bits,
nonce: network.genesis.nonce,
height: 0
}), true);
if (!this.blockdb)
return callback();
self.blockdb.hasBlock(network.genesis.hash, function(err, result) {
var genesis;
if (err)
return callback(err);
if (result)
return callback();
utils.debug('BlockDB does not have genesis block. Adding.');
genesis = bcoin.block.fromRaw(network.genesisBlock, 'hex');
genesis.height = 0;
self.blockdb.saveBlock(genesis, function(err) {
if (err)
return callback(err);
return callback();
});
});
};
// Stream headers from electrum.org for quickly
// preloading the chain. Electrum.org stores
// headers in the standard block header format,