From f83be008f384ba5c3a1102cdd5c69d64bbab8458 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 11 Nov 2014 13:27:36 -0800 Subject: [PATCH] allow hardcoded peers. --- lib/bitcoind.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/bitcoind.js b/lib/bitcoind.js index d7fa8714..e45e2f1d 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -51,6 +51,8 @@ function Bitcoin(options) { this.config = this.options.datadir + '/bitcoin.conf'; + this.network = Bitcoin[this.options.testnet ? 'testnet' : 'livenet']; + if (!fs.existsSync(this.options.datadir)) { mkdirp.sync(this.options.datadir); } @@ -66,6 +68,28 @@ function Bitcoin(options) { ); } + // Add hardcoded peers + var data = fs.readFileSync(this.config, 'utf8'); + if (this.network.peers.length) { + var peers = this.network.peers.reduce(function(out, peer) { + if (!~data.indexOf('addnode=' + peer)) { + return out + 'addnode=' + peer + '\n'; + } + return out; + }, '\n'); + fs.writeFileSync(data + peers); + } + + // Copy config into testnet dir + if (this.network.name === 'testnet') { + if (!fs.existsSync(this.datadir + '/testnet3')) { + fs.mkdirSync(this.datadir + '/testnet3'); + } + fs.writeFileSync( + this.datadir + '/testnet3/bitcoin.conf', + fs.readFileSync(this.config)); + } + Object.keys(exports).forEach(function(key) { self[key] = exports[key]; }); @@ -79,6 +103,20 @@ function Bitcoin(options) { Bitcoin.prototype.__proto__ = EventEmitter.prototype; +Bitcoin.livenet = { + name: 'livenet', + peers: [ + // hardcoded peers + ] +}; + +Bitcoin.testnet = { + name: 'testnet', + peers: [ + // hardcoded peers + ] +}; + // Make sure signal handlers are not overwritten Bitcoin._signalQueue = []; Bitcoin._processOn = process.on;