Browse Source

add a new api endpoint returning pairing info for the block explorer

feat-mydojo_upgrade_explorer
kenshin-samourai 5 years ago
parent
commit
1f9a514917
  1. 41
      accounts/support-rest-api.js
  2. 2
      docker/my-dojo/docker-compose.yaml
  3. 4
      docker/my-dojo/node/Dockerfile
  4. 1
      docker/my-dojo/tor/restart.sh

41
accounts/support-rest-api.js

@ -4,6 +4,7 @@
*/
'use strict'
const fs = require('fs')
const validator = require('validator')
const bodyParser = require('body-parser')
const errors = require('../lib/errors')
@ -68,6 +69,13 @@ class SupportRestApi {
HttpServer.sendAuthError
)
this.httpServer.app.get(
`/${keys.prefixes.support}/pairing/explorer`,
authMgr.checkHasAdminProfile.bind(authMgr),
this.getPairingExplorer.bind(this),
HttpServer.sendAuthError
)
this.httpServer.app.get(
`/${keys.prefixes.support}/pairing`,
authMgr.checkHasAdminProfile.bind(authMgr),
@ -299,6 +307,39 @@ class SupportRestApi {
}
}
/**
* Get pairing info for the local block explorer
*/
async getPairingExplorer(req, res) {
try {
let url = ''
if (process.env.EXPLORER_INSTALL == 'on') {
try {
url = fs.readFileSync('/var/lib/tor/hsv3explorer/hostname', 'utf8')
url = url.replace('\n', '')
} catch(e) {
Logger.error(e, 'SupportRestApi.getPairing() : Cannot read explorer onion address')
}
}
const ret = {
'pairing': {
'type': 'explorer.btcRpcExplorer',
'url': url,
'key': process.env.EXPLORER_KEY
}
}
HttpServer.sendRawData(res, JSON.stringify(ret, null, 2))
} catch(e) {
const ret = {
status: 'error'
}
Logger.error(e, 'SupportRestApi.getPairingExplorer() : Support pairing error')
HttpServer.sendError(res, JSON.stringify(ret, null, 2))
} finally {
debugApi && Logger.info(`Completed GET /pairing/explorer`)
}
}
/**
* Validate arguments related to GET xpub info requests
* @param {object} req - http request object

2
docker/my-dojo/docker-compose.yaml

@ -30,6 +30,7 @@ services:
- ./conf/docker-common.conf
- ./conf/docker-mysql.conf
- ./conf/docker-bitcoind.conf
- ./conf/docker-explorer.conf
- ./conf/docker-node.conf
restart: on-failure
command: "/home/node/app/wait-for-it.sh db:3306 --timeout=720 --strict -- /home/node/app/restart.sh"
@ -39,6 +40,7 @@ services:
- "8082"
volumes:
- data-nodejs:/data
- data-tor:/var/lib/tor
depends_on:
- db
networks:

4
docker/my-dojo/node/Dockerfile

@ -4,6 +4,10 @@ ENV LOGS_DIR /data/logs
ENV APP_DIR /home/node/app
# Add node user to tor group
RUN addgroup --system -gid 1107 tor && \
usermod -a -G tor node
# Install forever
RUN npm install -g forever

1
docker/my-dojo/tor/restart.sh

@ -29,6 +29,7 @@ if [ "$EXPLORER_INSTALL" == "on" ]; then
tor_options+=(--HiddenServiceDir /var/lib/tor/hsv3explorer)
tor_options+=(--HiddenServiceVersion 3)
tor_options+=(--HiddenServicePort "80 172.29.1.3:9080")
tor_options+=(--HiddenServiceDirGroupReadable 1)
fi
if [ "$TOR_USE_BRIDGES" == "on" ]; then

Loading…
Cancel
Save