diff --git a/lib/node.js b/lib/node.js index c2350b50..1c97c361 100644 --- a/lib/node.js +++ b/lib/node.js @@ -228,6 +228,7 @@ Node.prototype._startService = function(serviceInfo, callback) { Node.prototype._logTitle = function() { if (this.configPath) { log.info('Using config:', this.configPath); + log.info('Using network:', this.getNetworkName()); } }; diff --git a/lib/scaffold/start.js b/lib/scaffold/start.js index 378e96c3..e8654575 100644 --- a/lib/scaffold/start.js +++ b/lib/scaffold/start.js @@ -61,7 +61,6 @@ function checkConfigVersion2(fullConfig) { * @param {Object} options.config - The parsed bitcore-node.json configuration file * @param {Array} options.config.services - An array of services names. * @param {Object} options.config.servicesConfig - Parameters to pass to each service - * @param {String} options.config.datadir - A relative (to options.path) or absolute path to the datadir * @param {String} options.config.network - 'livenet', 'testnet' or 'regtest * @param {Number} options.config.port - The port to use for the web service */ diff --git a/lib/services/bitcoind.js b/lib/services/bitcoind.js index 4e79fcd6..7e0e04f9 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -1,6 +1,7 @@ 'use strict'; var fs = require('fs'); +var path = require('path'); var spawn = require('child_process').spawn; var util = require('util'); var mkdirp = require('mkdirp'); @@ -16,6 +17,7 @@ var Transaction = bitcore.Transaction; var index = require('../'); var errors = index.errors; var log = index.log; +var utils = require('../utils'); var Service = require('../service'); /** @@ -318,8 +320,17 @@ Bitcoin.prototype._loadSpawnConfiguration = function(node) { $.checkArgument(this.options.spawn.datadir, 'Please specify "spawn.datadir" in bitcoind config options'); $.checkArgument(this.options.spawn.exec, 'Please specify "spawn.exec" in bitcoind config options'); + if (!utils.isAbsolutePath(this.options.spawn.datadir)) { + $.checkState(this.node.configPath); + $.checkState(utils.isAbsolutePath(this.node.configPath)); + var baseConfigPath = path.dirname(this.node.configPath); + this.options.spawn.datadir = path.resolve(baseConfigPath, this.options.spawn.datadir); + } + var spawnOptions = this.options.spawn; - var configPath = spawnOptions.datadir + '/bitcoin.conf'; + var configPath = path.resolve(spawnOptions.datadir, './bitcoin.conf'); + + log.info('Using bitcoin config file:', configPath); this.spawn = {}; this.spawn.datadir = this.options.spawn.datadir; diff --git a/test/services/bitcoind.unit.js b/test/services/bitcoind.unit.js index 8719f7f5..f486113a 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -340,6 +340,13 @@ describe('Bitcoin Service', function() { }); describe('#_loadSpawnConfiguration', function() { + var sandbox = sinon.sandbox.create(); + beforeEach(function() { + sandbox.stub(log, 'info'); + }); + afterEach(function() { + sandbox.restore(); + }); it('will parse a bitcoin.conf file', function() { var TestBitcoin = proxyquire('../../lib/services/bitcoind', { fs: { @@ -352,7 +359,9 @@ describe('Bitcoin Service', function() { } }); var bitcoind = new TestBitcoin(baseConfig); - bitcoind._loadSpawnConfiguration({datadir: process.env.HOME + '/.bitcoin'}); + bitcoind.options.spawn.datadir = '/tmp/.bitcoin'; + var node = {}; + bitcoind._loadSpawnConfiguration(node); should.exist(bitcoind.spawn.config); bitcoind.spawn.config.should.deep.equal({ addressindex: 1, @@ -374,6 +383,33 @@ describe('Bitcoin Service', function() { zmqpubrawtx: 'tcp://127.0.0.1:28332' }); }); + it('will expand relative datadir to absolute path', function() { + var TestBitcoin = proxyquire('../../lib/services/bitcoind', { + fs: { + readFileSync: readFileSync, + existsSync: sinon.stub().returns(true), + writeFileSync: sinon.stub() + }, + mkdirp: { + sync: sinon.stub() + } + }); + var config = { + node: { + network: bitcore.Networks.testnet, + configPath: '/tmp/.bitcore/bitcore-node.json' + }, + spawn: { + datadir: './data', + exec: 'testpath' + } + }; + var bitcoind = new TestBitcoin(config); + bitcoind.options.spawn.datadir = './data'; + var node = {}; + bitcoind._loadSpawnConfiguration(node); + bitcoind.options.spawn.datadir.should.equal('/tmp/.bitcore/data'); + }); it('should throw an exception if txindex isn\'t enabled in the configuration', function() { var TestBitcoin = proxyquire('../../lib/services/bitcoind', { fs: { @@ -420,7 +456,9 @@ describe('Bitcoin Service', function() { } }; var bitcoind = new TestBitcoin(config); - bitcoind._loadSpawnConfiguration({datadir: process.env.HOME + '/.bitcoin'}); + bitcoind.options.spawn.datadir = '/tmp/.bitcoin'; + var node = {}; + bitcoind._loadSpawnConfiguration(node); }); });