wip
This commit is contained in:
parent
7ca831657b
commit
facea3bd13
@ -5,7 +5,7 @@ module.exports = {
|
||||
BITCOIN_GENESIS_HASH: {
|
||||
livenet: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
|
||||
regtest: '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206',
|
||||
testnet: '000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943' //this is testnet3
|
||||
testnet: '000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943', //this is testnet3
|
||||
testnet5: '000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943' //this is testnet5
|
||||
}
|
||||
};
|
||||
|
||||
15
lib/node.js
15
lib/node.js
@ -185,23 +185,10 @@ 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) {
|
||||
var self = this;
|
||||
|
||||
var services = this._detectRemoteNode(this._unloadedServices);
|
||||
var services = this._unloadedServices;
|
||||
|
||||
var servicesOrder = this._getServiceOrder(services);
|
||||
|
||||
|
||||
71
lib/services/bcoin/index.js
Normal file
71
lib/services/bcoin/index.js
Normal file
@ -0,0 +1,71 @@
|
||||
'use strict';
|
||||
|
||||
var BaseService = require('../../service');
|
||||
var inherits = require('util').inherits;
|
||||
var index = require('../../');
|
||||
var log = index.log;
|
||||
var bcoin = require('bcoin');
|
||||
|
||||
var BcoinService = function(options) {
|
||||
BaseService.call(this, options);
|
||||
this._config = options.config || this._getDefaultConfig();
|
||||
};
|
||||
|
||||
inherits(BcoinService, BaseService);
|
||||
|
||||
BcoinService.dependencies = [];
|
||||
|
||||
BcoinService.prototype._getDefaultConfig = function() {
|
||||
return {
|
||||
checkpoints: true,
|
||||
logLevel: 'info',
|
||||
network: this.node.getNetworkName()
|
||||
};
|
||||
};
|
||||
|
||||
BcoinService.prototype.start = function(callback) {
|
||||
this._startBcoin(callback);
|
||||
};
|
||||
|
||||
BcoinService.prototype._startBcoin = function(callback) {
|
||||
var self = this;
|
||||
self._bcoin = bcoin.fullnode(self._config);
|
||||
self._initBcoinListeners();
|
||||
log.info('Starting Bcoin full node...');
|
||||
self._bcoin.open().then(function() {
|
||||
self._bcoin.connect().then(function() {
|
||||
self._bcoin.startSync();
|
||||
callback();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
BcoinService.prototype.stop = function(callback) {
|
||||
this._bcoin.stopSync();
|
||||
this._bcoin.disconnect();
|
||||
this._bcoin.close();
|
||||
callback();
|
||||
};
|
||||
|
||||
|
||||
BcoinService.prototype._initBcoinListeners = function() {
|
||||
|
||||
var self = this;
|
||||
self._bcoin.on('error', function(err) {
|
||||
log.debug(err);
|
||||
});
|
||||
|
||||
self._bcoin.chain.on('block', function(block) {
|
||||
log.debug(block);
|
||||
});
|
||||
|
||||
self._bcoin.mempool.on('tx', function(tx) {
|
||||
log.debug(tx);
|
||||
});
|
||||
|
||||
self._bcoin.chain.on('full', function() {
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
module.exports = BcoinService;
|
||||
@ -31,7 +31,6 @@
|
||||
"bitcore-node": "./bin/bitcore-node"
|
||||
},
|
||||
"scripts": {
|
||||
"preinstall": "./scripts/download",
|
||||
"test": "mocha -R spec --recursive",
|
||||
"regtest": "./scripts/regtest",
|
||||
"jshint": "jshint --reporter=node_modules/jshint-stylish ./lib",
|
||||
@ -49,7 +48,7 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"async": "^1.3.0",
|
||||
"bcoin", "^1.0.0-beta.12",
|
||||
"bcoin": "bcoin-org/bcoin#master",
|
||||
"bitcoind-rpc": "^0.6.0",
|
||||
"bitcore-lib": "^0.14",
|
||||
"body-parser": "^1.13.3",
|
||||
|
||||
21
test_bcoin.js
Normal file
21
test_bcoin.js
Normal file
@ -0,0 +1,21 @@
|
||||
var bcoin = require('bcoin').set('main');
|
||||
|
||||
var node = bcoin.fullnode({
|
||||
checkpoints: true,
|
||||
// Primary wallet passphrase
|
||||
logLevel: 'info'
|
||||
});
|
||||
|
||||
// We get a lot of errors sometimes,
|
||||
// usually from peers hanging up on us.
|
||||
// Just ignore them for now.
|
||||
node.on('error', function(err) {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
// Start the node
|
||||
node.open().then(function() {
|
||||
node.connect().then(function() {
|
||||
node.startSync();
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user