From facea3bd1345e11a9b5ea152ffddd2d9f1c97db0 Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Wed, 21 Jun 2017 13:36:07 -0400 Subject: [PATCH] wip --- lib/constants.js | 2 +- lib/node.js | 15 +------- lib/services/bcoin/index.js | 71 +++++++++++++++++++++++++++++++++++++ package.json | 3 +- test_bcoin.js | 21 +++++++++++ 5 files changed, 95 insertions(+), 17 deletions(-) create mode 100644 lib/services/bcoin/index.js create mode 100644 test_bcoin.js diff --git a/lib/constants.js b/lib/constants.js index 593a910f..0e9cd8bb 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -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 } }; diff --git a/lib/node.js b/lib/node.js index 8dac6387..a376cdb8 100644 --- a/lib/node.js +++ b/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); diff --git a/lib/services/bcoin/index.js b/lib/services/bcoin/index.js new file mode 100644 index 00000000..ee4ea366 --- /dev/null +++ b/lib/services/bcoin/index.js @@ -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; diff --git a/package.json b/package.json index e07b524e..f8b1924a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test_bcoin.js b/test_bcoin.js new file mode 100644 index 00000000..24bca856 --- /dev/null +++ b/test_bcoin.js @@ -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(); + }); +});