From 76f2d147a62b7edcffbd0a7089a1d01df6310f17 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 17 Oct 2014 12:54:58 -0700 Subject: [PATCH] disable multiple instantiations. --- lib/bitcoind.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/bitcoind.js b/lib/bitcoind.js index 152d219f..ce529568 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -24,6 +24,11 @@ function Bitcoin(options) { return new Bitcoin(options); } + if (Object.keys(this.instances).length) { + throw new + Error('bitcoind.js cannot be instantiated more than once.'); + } + EventEmitter.call(this); this.options = options || {}; @@ -46,12 +51,6 @@ function Bitcoin(options) { this.config = this.options.datadir + '/bitcoin.conf'; - if (this.instances[this.options.datadir]) { - throw new Error('' - + 'bitcoind.js cannot be instantiated' - + ' more than once on the same datadir.'); - } - if (!fs.existsSync(this.options.datadir)) { mkdirp.sync(this.options.datadir); } @@ -98,7 +97,7 @@ Bitcoin.instances = {}; Bitcoin.prototype.instances = Bitcoin.instances; Bitcoin.__defineGetter__('global', function() { - return Bitcoin.instances[process.env.HOME + '/.bitcoin']; + return Bitcoin.instances[Object.keys(Bitcoin.instances)[0]]; }); Bitcoin.prototype.start = function(options, callback) {