add connect method.

This commit is contained in:
Christopher Jeffrey 2016-04-03 06:11:30 -07:00
parent ecaec7b5d9
commit 3f0ac32334
6 changed files with 26 additions and 8 deletions

View File

@ -20,8 +20,9 @@ node.open(function(err) {
if (err)
throw err;
node.startSync();
if (node.options.mine)
node.miner.start();
else
node.startSync();
});

View File

@ -127,7 +127,7 @@ Chain.prototype._init = function _init() {
this.on('invalid', function(block, data) {
utils.debug(
'Invalid block at height %d: hash=%s',
'Invalid block at height %d: hash=%s (%s)',
data.height,
utils.revHex(data.hash),
getHost()

View File

@ -194,6 +194,10 @@ Fullnode.prototype.sendBlock = function sendBlock(item, callback) {
return this.pool.sendBlock(item, callback);
};
Fullnode.prototype.connect = function connect() {
return this.pool.connect();
};
Fullnode.prototype.startSync = function startSync() {
return this.pool.startSync();
};

View File

@ -362,7 +362,7 @@ Miner.prototype.iterate = function iterate() {
if (err.type === 'VerifyError')
utils.debug('Miner: %s could not be added to chain.', self.block.rhash);
self.emit('error', err);
return self.iterate();
return self.start();
}
// Emit our newly found block

View File

@ -165,9 +165,11 @@ Pool.prototype.open = function open(callback) {
this.once('open', callback);
};
Pool.prototype._init = function _init() {
var self = this;
var i;
Pool.prototype.connect = function connect() {
assert(this.loaded, 'Pool is not loaded.');
if (this.connected)
return;
if (this.originalSeeds.length > 0) {
this._addLoader();
@ -178,6 +180,13 @@ Pool.prototype._init = function _init() {
this.connected = true;
}
this.startServer();
};
Pool.prototype._init = function _init() {
var self = this;
var i;
this.chain.on('block', function(block, entry, peer) {
// Emit merkle txs after the fact
if (block.type === 'merkleblock') {
@ -224,8 +233,6 @@ Pool.prototype._init = function _init() {
(this.options.wallets || []).forEach(function(wallet) {
self.addWallet(wallet);
});
this.startServer();
};
Pool.prototype.getBlocks = function getBlocks(peer, top, stop, callback) {
@ -510,6 +517,8 @@ Pool.prototype.startSync = function startSync() {
this._startInterval();
this._startTimer();
this.connect();
if (!this.peers.load) {
this._addLoader();
return;

View File

@ -150,6 +150,10 @@ SPVNode.prototype.sendBlock = function sendBlock(item, callback) {
return this.pool.sendBlock(item, callback);
};
SPVNode.prototype.connect = function connect() {
return this.pool.connect();
};
SPVNode.prototype.startSync = function startSync() {
return this.pool.startSync();
};