Replace ~/.bitcoin with process.env.HOME
This commit is contained in:
parent
6c7501b45f
commit
be525b055d
@ -1,13 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var start = require('../lib/scaffold/start');
|
var start = require('../lib/scaffold/start');
|
||||||
|
var path = require('path');
|
||||||
|
|
||||||
start({
|
start({
|
||||||
path: process.cwd(),
|
path: process.cwd(),
|
||||||
config: {
|
config: {
|
||||||
datadir: process.env.BITCORENODE_DIR || '~/.bitcoin',
|
datadir: process.env.BITCORENODE_DIR || path.resolve(process.env.HOME, '.bitcoin'),
|
||||||
network: process.env.BITCORENODE_NETWORK || 'livenet',
|
network: process.env.BITCORENODE_NETWORK || 'livenet',
|
||||||
port: 3000
|
port: process.env.BITCORENODE_PORT || 3001
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
14
lib/node.js
14
lib/node.js
@ -57,12 +57,11 @@ Node.DEFAULT_DAEMON_CONFIG = 'whitelist=127.0.0.1\n' + 'txindex=1\n';
|
|||||||
|
|
||||||
Node.prototype._loadBitcoinConf = function(config) {
|
Node.prototype._loadBitcoinConf = function(config) {
|
||||||
$.checkArgument(config.datadir, 'Please specify "datadir" in configuration options');
|
$.checkArgument(config.datadir, 'Please specify "datadir" in configuration options');
|
||||||
var datadir = config.datadir.replace(/^~/, process.env.HOME);
|
var configPath = config.datadir + '/bitcoin.conf';
|
||||||
var configPath = datadir + '/bitcoin.conf';
|
|
||||||
this.bitcoinConfiguration = {};
|
this.bitcoinConfiguration = {};
|
||||||
|
|
||||||
if (!fs.existsSync(datadir)) {
|
if (!fs.existsSync(config.datadir)) {
|
||||||
mkdirp.sync(datadir);
|
mkdirp.sync(config.datadir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs.existsSync(configPath)) {
|
if (!fs.existsSync(configPath)) {
|
||||||
@ -329,13 +328,12 @@ Node.prototype._loadDB = function(config) {
|
|||||||
$.checkArgument(config.datadir, 'Please specify "datadir" in configuration options');
|
$.checkArgument(config.datadir, 'Please specify "datadir" in configuration options');
|
||||||
$.checkState(this.network, 'Network property not defined');
|
$.checkState(this.network, 'Network property not defined');
|
||||||
var regtest = Networks.get('regtest');
|
var regtest = Networks.get('regtest');
|
||||||
var datadir = config.datadir.replace(/^~/, process.env.HOME);
|
|
||||||
if (this.network === Networks.livenet) {
|
if (this.network === Networks.livenet) {
|
||||||
options.path = datadir + '/bitcore-node.db';
|
config.db.path = config.datadir + '/bitcore-node.db';
|
||||||
} else if (this.network === Networks.testnet) {
|
} else if (this.network === Networks.testnet) {
|
||||||
options.path = datadir + '/testnet3/bitcore-node.db';
|
config.db.path = config.datadir + '/testnet3/bitcore-node.db';
|
||||||
} else if (this.network === regtest) {
|
} else if (this.network === regtest) {
|
||||||
options.path = datadir + '/regtest/bitcore-node.db';
|
config.db.path = config.datadir + '/regtest/bitcore-node.db';
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Unknown network: ' + this.network);
|
throw new Error('Unknown network: ' + this.network);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,8 +39,7 @@ function start(options) {
|
|||||||
var fullConfig = _.clone(config);
|
var fullConfig = _.clone(config);
|
||||||
|
|
||||||
// expand to the full path
|
// expand to the full path
|
||||||
var datadir = config.datadir.replace(/^~/, process.env.HOME);
|
fullConfig.datadir = path.resolve(configPath, config.datadir);
|
||||||
fullConfig.datadir = path.resolve(configPath, datadir);
|
|
||||||
|
|
||||||
// load the modules
|
// load the modules
|
||||||
fullConfig.db = {
|
fullConfig.db = {
|
||||||
|
|||||||
@ -101,7 +101,7 @@ describe('Bitcoind Node', function() {
|
|||||||
describe('#_loadBitcoinConf', function() {
|
describe('#_loadBitcoinConf', function() {
|
||||||
it('will parse a bitcoin.conf file', function() {
|
it('will parse a bitcoin.conf file', function() {
|
||||||
var node = new Node({});
|
var node = new Node({});
|
||||||
node._loadBitcoinConf({datadir: '~/.bitcoin'});
|
node._loadBitcoinConf({datadir: process.env.HOME + '/.bitcoin'});
|
||||||
should.exist(node.bitcoinConfiguration);
|
should.exist(node.bitcoinConfiguration);
|
||||||
node.bitcoinConfiguration.should.deep.equal({
|
node.bitcoinConfiguration.should.deep.equal({
|
||||||
server: 1,
|
server: 1,
|
||||||
@ -349,7 +349,7 @@ describe('Bitcoind Node', function() {
|
|||||||
};
|
};
|
||||||
var config = {
|
var config = {
|
||||||
DB: DB,
|
DB: DB,
|
||||||
datadir: '~/.bitcoin'
|
datadir: process.env.HOME + '/.bitcoin'
|
||||||
};
|
};
|
||||||
|
|
||||||
var node = new Node(config);
|
var node = new Node(config);
|
||||||
@ -363,7 +363,7 @@ describe('Bitcoind Node', function() {
|
|||||||
};
|
};
|
||||||
var config = {
|
var config = {
|
||||||
DB: DB,
|
DB: DB,
|
||||||
datadir: '~/.bitcoin'
|
datadir: process.env.HOME + '/.bitcoin'
|
||||||
};
|
};
|
||||||
|
|
||||||
var node = new Node(config);
|
var node = new Node(config);
|
||||||
@ -373,7 +373,7 @@ describe('Bitcoind Node', function() {
|
|||||||
});
|
});
|
||||||
it('error with unknown network', function() {
|
it('error with unknown network', function() {
|
||||||
var config = {
|
var config = {
|
||||||
datadir: '~/.bitcoin'
|
datadir: process.env.HOME + '/.bitcoin'
|
||||||
};
|
};
|
||||||
|
|
||||||
var node = new Node(config);
|
var node = new Node(config);
|
||||||
@ -388,7 +388,7 @@ describe('Bitcoind Node', function() {
|
|||||||
};
|
};
|
||||||
var config = {
|
var config = {
|
||||||
DB: DB,
|
DB: DB,
|
||||||
datadir: '~/.bitcoin'
|
datadir: process.env.HOME + '/.bitcoin'
|
||||||
};
|
};
|
||||||
|
|
||||||
var node = new Node(config);
|
var node = new Node(config);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user