wip
This commit is contained in:
parent
c4e90875a9
commit
7ca831657b
22
bitcore-node.json.connect
Normal file
22
bitcore-node.json.connect
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"network": "regtest",
|
||||||
|
"port": 3001,
|
||||||
|
"datadir": "/Users/chrisk",
|
||||||
|
"services": [
|
||||||
|
"p2p",
|
||||||
|
"db",
|
||||||
|
"transaction",
|
||||||
|
"timestamp",
|
||||||
|
"address",
|
||||||
|
"mempool",
|
||||||
|
"wallet-api",
|
||||||
|
"web"
|
||||||
|
],
|
||||||
|
"servicesConfig": {
|
||||||
|
"p2p": {
|
||||||
|
"connect": [
|
||||||
|
{ "rpchost": "127.0.0.1", "rpcport": 58332, "rpcuser": "bitcoin", "rpcpassword": "local321", "zmqpubrawtx": "tcp://127.0.0.1:28332" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
40
lib/node.js
40
lib/node.js
@ -19,6 +19,15 @@ function Node(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._init(config);
|
this._init(config);
|
||||||
|
|
||||||
|
if (!_.isUndefined(config.formatLogs)) {
|
||||||
|
this.log.formatting = config.formatLogs ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.services) {
|
||||||
|
$.checkArgument(Array.isArray(config.services));
|
||||||
|
this._unloadedServices = config.services;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
util.inherits(Node, EventEmitter);
|
util.inherits(Node, EventEmitter);
|
||||||
@ -28,19 +37,11 @@ Node.prototype._init = function(config) {
|
|||||||
this.errors = errors;
|
this.errors = errors;
|
||||||
this.log = log;
|
this.log = log;
|
||||||
|
|
||||||
if (!_.isUndefined(config.formatLogs)) {
|
|
||||||
this.log.formatting = config.formatLogs ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.datadir = config.datadir;
|
this.datadir = config.datadir;
|
||||||
this.network = null;
|
this.network = null;
|
||||||
this.services = {};
|
this.services = {};
|
||||||
this._unloadedServices = [];
|
this._unloadedServices = [];
|
||||||
|
|
||||||
if (config.services) {
|
|
||||||
$.checkArgument(Array.isArray(config.services));
|
|
||||||
this._unloadedServices = config.services;
|
|
||||||
}
|
|
||||||
this.port = config.port;
|
this.port = config.port;
|
||||||
this.https = config.https;
|
this.https = config.https;
|
||||||
this.httpsOptions = config.httpsOptions;
|
this.httpsOptions = config.httpsOptions;
|
||||||
@ -88,9 +89,7 @@ Node.prototype.getAllPublishEvents = function() {
|
|||||||
return events;
|
return events;
|
||||||
};
|
};
|
||||||
|
|
||||||
Node.prototype.getServiceOrder = function() {
|
Node.prototype._getServiceOrder = function(services) {
|
||||||
|
|
||||||
var services = this._unloadedServices;
|
|
||||||
|
|
||||||
var names = [];
|
var names = [];
|
||||||
var servicesByName = {};
|
var servicesByName = {};
|
||||||
@ -187,9 +186,24 @@ Node.prototype._logTitle = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Node.prototype._startBcoinNode = function() {
|
||||||
|
bcoin.set(this.getNetworkName())
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Node.prototype._detectRemoteNode = function(services) {
|
||||||
|
if (!_.isArray(services) || services.indexOf('p2p') === -1) {
|
||||||
|
this._startBcoinNode();
|
||||||
|
}
|
||||||
|
return services;
|
||||||
|
};
|
||||||
|
|
||||||
Node.prototype.start = function(callback) {
|
Node.prototype.start = function(callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var servicesOrder = this.getServiceOrder();
|
|
||||||
|
var services = this._detectRemoteNode(this._unloadedServices);
|
||||||
|
|
||||||
|
var servicesOrder = this._getServiceOrder(services);
|
||||||
|
|
||||||
self._logTitle();
|
self._logTitle();
|
||||||
|
|
||||||
@ -221,7 +235,7 @@ Node.prototype.stop = function(callback) {
|
|||||||
|
|
||||||
log.info('Beginning shutdown');
|
log.info('Beginning shutdown');
|
||||||
var self = this;
|
var self = this;
|
||||||
var services = this.getServiceOrder().reverse();
|
var services = this._getServiceOrder(this._unloadedServices).reverse();
|
||||||
|
|
||||||
this.stopping = true;
|
this.stopping = true;
|
||||||
this.emit('stopping');
|
this.emit('stopping');
|
||||||
|
|||||||
@ -7,6 +7,9 @@ var index = require('../../');
|
|||||||
var log = index.log;
|
var log = index.log;
|
||||||
var BaseService = require('../../service');
|
var BaseService = require('../../service');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
var utils = require('../utils');
|
||||||
|
var async = require('async');
|
||||||
|
var bcoin = require('bcoin');
|
||||||
|
|
||||||
var P2P = function(options) {
|
var P2P = function(options) {
|
||||||
|
|
||||||
@ -16,13 +19,34 @@ var P2P = function(options) {
|
|||||||
|
|
||||||
BaseService.call(this, options);
|
BaseService.call(this, options);
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
|
||||||
|
this._initPubSub();
|
||||||
|
this._initP2P();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
util.inherits(P2P, BaseService);
|
||||||
|
|
||||||
|
P2P.dependencies = [];
|
||||||
|
|
||||||
|
P2P.prototype._initRemoteNode = function(callback) {
|
||||||
|
// if no connect params exist for p2p, then spawn bcoin as a fallback
|
||||||
|
if (!this.options.connect) {
|
||||||
|
return this._spawnBcoin(callback);
|
||||||
|
}
|
||||||
|
// remote p2p nodes may not be ready just yet.
|
||||||
|
async.retry({ times: 10, interval: 1000 }, utils.tryTcpConnection, callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
P2P.prototype._spawnBcoin = function(callback) {
|
||||||
|
bcoin.set(this.node.getNetworkName());
|
||||||
|
l
|
||||||
|
};
|
||||||
|
|
||||||
|
P2P.prototype._initP2P = function() {
|
||||||
this._maxPeers = this.options.maxPeers || 60;
|
this._maxPeers = this.options.maxPeers || 60;
|
||||||
this._minPeers = this.options.minPeers || 1;
|
this._minPeers = this.options.minPeers || 1;
|
||||||
this._configPeers = this.options.peers;
|
this._configPeers = this.options.peers;
|
||||||
this.subscriptions = {};
|
|
||||||
this.subscriptions.block = [];
|
|
||||||
this.subscriptions.headers = [];
|
|
||||||
this.subscriptions.transaction = [];
|
|
||||||
this.messages = new p2p.Messages({ network: this.node.network });
|
this.messages = new p2p.Messages({ network: this.node.network });
|
||||||
this._peerHeights = [];
|
this._peerHeights = [];
|
||||||
this._peers = [];
|
this._peers = [];
|
||||||
@ -30,17 +54,28 @@ var P2P = function(options) {
|
|||||||
this._mempoolFilter = [];
|
this._mempoolFilter = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(P2P, BaseService);
|
P2P.prototype._initPubSub = function() {
|
||||||
|
this.subscriptions = {};
|
||||||
P2P.dependencies = [];
|
this.subscriptions.block = [];
|
||||||
|
this.subscriptions.headers = [];
|
||||||
|
this.subscriptions.transaction = [];
|
||||||
|
};
|
||||||
|
|
||||||
P2P.prototype.start = function(callback) {
|
P2P.prototype.start = function(callback) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
self._initCache();
|
self._initRemoteNode(function(err) {
|
||||||
self._initPool();
|
|
||||||
this._setupListeners();
|
if (err) {
|
||||||
callback();
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
self._initCache();
|
||||||
|
self._initPool();
|
||||||
|
this._setupListeners();
|
||||||
|
callback();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -49,6 +49,7 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^1.3.0",
|
"async": "^1.3.0",
|
||||||
|
"bcoin", "^1.0.0-beta.12",
|
||||||
"bitcoind-rpc": "^0.6.0",
|
"bitcoind-rpc": "^0.6.0",
|
||||||
"bitcore-lib": "^0.14",
|
"bitcore-lib": "^0.14",
|
||||||
"body-parser": "^1.13.3",
|
"body-parser": "^1.13.3",
|
||||||
|
|||||||
@ -10,10 +10,8 @@ var crypto = require('crypto');
|
|||||||
var zmq = require('zmq');
|
var zmq = require('zmq');
|
||||||
var bitcore = require('bitcore-lib');
|
var bitcore = require('bitcore-lib');
|
||||||
var Transaction = bitcore.Transaction;
|
var Transaction = bitcore.Transaction;
|
||||||
var PrivateKey = bitcore.PrivateKey;
|
|
||||||
var Block = bitcore.Block;
|
var Block = bitcore.Block;
|
||||||
var BlockHeader = bitcore.BlockHeader;
|
var BlockHeader = bitcore.BlockHeader;
|
||||||
var Unit = bitcore.Unit;
|
|
||||||
var constants = require('../lib/constants');
|
var constants = require('../lib/constants');
|
||||||
var debug = true;
|
var debug = true;
|
||||||
var extraDebug = true;
|
var extraDebug = true;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user