Browse Source

Accept bitcoind rpc and influxdb options as a connection URI

fix-133-memory-crash
Nadav Ivgi 6 years ago
parent
commit
99e2ac2051
  1. 30
      app/defaultCredentials.js
  2. 17
      bin/cli.js

30
app/defaultCredentials.js

@ -1,22 +1,30 @@
var os = require('os');
var path = require('path');
var url = require('url');
var btcUri = process.env.BTCEXP_BITCOIND_URI ? url.parse(process.env.BTCEXP_BITCOIND_URI, true) : { query: { } };
var btcAuth = btcUri.auth ? btcUri.auth.split(':') : [];
var ifxUri = process.env.BTCEXP_INFLUXDB_URI ? url.parse(process.env.BTCEXP_INFLUXDB_URI, true) : { query: { } };
var ifxAuth = ifxUri.auth ? ifxUri.auth.split(':') : [];
var ifxActive = !!process.env.BTCEXP_ENABLE_INFLUXDB || Object.keys(process.env).some(k => k.startsWith('BTCEXP_INFLUXDB_'));
module.exports = {
rpc: {
host: process.env.BTCEXP_BITCOIND_HOST || "127.0.0.1",
port: process.env.BTCEXP_BITCOIND_PORT || 8332,
username: process.env.BTCEXP_BITCOIND_USER,
password: process.env.BTCEXP_BITCOIND_PASS,
cookie: process.env.BTCEXP_BITCOIND_COOKIE || path.join(os.homedir(), '.bitcoin', '.cookie'),
host: btcUri.hostname || process.env.BTCEXP_BITCOIND_HOST || "127.0.0.1",
port: btcUri.port || process.env.BTCEXP_BITCOIND_PORT || 8332,
username: btcAuth[0] || process.env.BTCEXP_BITCOIND_USER,
password: btcAuth[1] || process.env.BTCEXP_BITCOIND_PASS,
cookie: btcUri.query.cookie || process.env.BTCEXP_BITCOIND_COOKIE || path.join(os.homedir(), '.bitcoin', '.cookie'),
},
influxdb:{
active: !!process.env.BTCEXP_ENABLE_INFLUXDB,
host: process.env.BTCEXP_INFLUXDB_HOST || "127.0.0.1",
port: process.env.BTCEXP_INFLUXDB_PORT || 8086,
database: process.env.BTCEXP_INFLUXDB_DBNAME || "influxdb",
username: process.env.BTCEXP_INFLUXDB_USER || "admin",
password: process.env.BTCEXP_INFLUXDB_PASS || "admin"
active: ifxActive,
host: ifxUri.hostname || process.env.BTCEXP_INFLUXDB_HOST || "127.0.0.1",
port: ifxUri.port || process.env.BTCEXP_INFLUXDB_PORT || 8086,
database: ifxUri.pathname && ifxUri.pathname.substr(1) || process.env.BTCEXP_INFLUXDB_DBNAME || "influxdb",
username: ifxAuth[0] || process.env.BTCEXP_INFLUXDB_USER || "admin",
password: ifxAuth[1] || process.env.BTCEXP_INFLUXDB_PASS || "admin"
},
// optional: enter your api access key from ipstack.com below

17
bin/cli.js

@ -9,6 +9,7 @@ const args = require('meow')(`
-l, --login <password> protect web interface with a password [default: no password]
--coin <coin> crypto-coin to enable [default: BTC]
-b, --bitcoind-uri <uri> connection URI for bitcoind rpc (overrides the options below)
-H, --bitcoind-host <host> hostname for bitcoind rpc [default: 127.0.0.1]
-P, --bitcoind-port <port> port for bitcoind rpc [default: 8332]
-c, --bitcoind-cookie <path> path to bitcoind cookie file [default: 8332]
@ -23,7 +24,9 @@ const args = require('meow')(`
--sentry-url <sentry-url> sentry url [default: disabled]
--enable-influxdb enable influxdb for logging network stats [default: false]
--influxdb-uri <uri> connection URI for influxdb (overrides the options below)
--influxdb-host <host> hostname for influxdb [default: 127.0.0.1]
--influxdb-port <port> port for influxdb [default: 8086]
--influxdb-user <user> username for influxdb [default: admin]
--influxdb-pass <pass> password for influxdb [default: admin]
--influxdb-dbname <db> database name for influxdb [default: influxdb]
@ -32,16 +35,22 @@ const args = require('meow')(`
-h, --help output usage information
-v, --version output version number
Example
Examples
$ btc-rpc-explorer --port 8080 --bitcoind-port 18443 --bitcoind-cookie ~/.bitcoin/regtest/.cookie
$ btc-rpc-explorer -p 8080 -P 18443 -c ~/.bitcoin/regtest.cookie
All options may also be specified as environment variables:
Or using connection URIs
$ btc-rpc-explorer -b bitcoin://bob:myPassword@127.0.0.1:18443/
$ btc-rpc-explorer -b bitcoin://127.0.0.1:18443/?cookie=$HOME/.bitcoin/regtest/.cookie
$ btc-rpc-explorer --influxdb-uri influx://bob:myPassword@127.0.0.1:8086/dbName
All options may also be specified as environment variables
$ BTCEXP_PORT=8080 BTCEXP_BITCOIND_PORT=18443 BTCEXP_BITCOIND_COOKIE=~/.bitcoin/regtest/.cookie btc-rpc-explorer
`, { flags: { port: {alias:'p'}, login: {alias:'l'}
, bitcoindHost: {alias:'H'}, bitcoindPort: {alias:'P'}, bitcoindCookie: {alias:'c'}
, bitcoindUser: {alias:'u'}, bitcoindPass: {alias:'w'}
, bitcoindUri: {alias:'b'}, bitcoindHost: {alias:'H'}, bitcoindPort: {alias:'P'}
, bitcoindCookie: {alias:'c'}, bitcoindUser: {alias:'u'}, bitcoindPass: {alias:'w'}
, demo: {type:'boolean'}, enableInfluxdb: {type:'boolean'}, nodeEnv: {alias:'e', default:'production'}
} }
).flags;

Loading…
Cancel
Save