Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add optional block explorer #107

Merged
merged 7 commits into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions accounts/support-rest-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
'use strict'

const fs = require('fs')
const validator = require('validator')
const bodyParser = require('body-parser')
const errors = require('../lib/errors')
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
79 changes: 62 additions & 17 deletions doc/DOCKER_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
MyDojo is a set of Docker containers providing a full Samourai backend composed of:
* a bitcoin full node accessible as an ephemeral Tor hidden service,
* a backend database,
* a backend modules with an API accessible as a static Tor hidden service,
* a maintenance tool accessible through a Tor web browser.
* backend modules with an API accessible as a static Tor hidden service,
* a maintenance tool accessible through a Tor web browser,
* an optional block explorer ([BTC RPC Explorer](https://github.com/janoside/btc-rpc-explorer)) accessible as a static Tor hidden service.


## Table of Content ##
Expand All @@ -15,6 +16,7 @@ MyDojo is a set of Docker containers providing a full Samourai backend composed
- [Upgrade procedure](#upgrade)
- [Dojo shell script](#shell_script)
- [Dojo maintenance tool](#maintenance_tool)
- [Block explorer](#explorer)
- [Pairing your wallet to your Dojo](#pairing)
- [Network connections](#network)

Expand All @@ -38,21 +40,23 @@ MyDojo is a set of Docker containers providing a full Samourai backend composed
Host machine | (Tor hidden services)
______________________________ | _____________________________
| | |
| ------------------- |
| ------------------- dmznet |
| | Tor Container | |
| ------------------- |
| | | |
| ------------------- | |
| | Nginx Container | | dmznet |
| | Nginx Container | | |
| ------------------- | |
|- - - - - - - - - - - | - - - - - - - | - - - - - - - - - - - |
| -------------------- -------------------- |
|- - - - - - - - - - - | - - -|- - - - | - - - - - - - - - - - |
| -------------------- | -------------------- |
| | Nodejs Container | ------ | Bitcoind Container | |
| -------------------- | -------------------- |
| | | | |
| -------------------- | -------------------- |
| | MySQL Container | ---- | BTC RPC Explorer | |
| -------------------- -------------------- |
| | |
| ------------------- |
| | MySQL Container | dojonet |
| ------------------- |
| |
| dojonet |
|______________________________________________________________|


Expand All @@ -73,11 +77,13 @@ MyDojo is a set of Docker containers providing a full Samourai backend composed

## Configuration files ##

Each new release of Dojo is packaged with 4 template files stored in the `<dojo_dir>/docker/my-dojo/conf` directory:
Each new release of Dojo is packaged with 6 template files stored in the `<dojo_dir>/docker/my-dojo/conf` directory:
- docker-common.conf.tpl
- docker-bitcoin.conf.tpl
- docker-explorer.conf.tpl
- docker-mysql.conf.tpl
- docker-node.conf.tpl
- docker-tor.conf.tpl

These template files define default values for configuration options of your Dojo.

Expand Down Expand Up @@ -127,13 +133,19 @@ This procedure allows to install a new Dojo from scratch.
* `MYSQL_ROOT_PASSWORD` = password protecting the root account of MySQL,
* `MYSQL_USER` = login of the account used to access the database of your Dojo,
* `MYSQL_PASSWORD` = password of the account used to access the database of your Dojo.
Note: These values can't be changed after the first installation.

* Edit docker-node.conf.tpl and provide a new value for the following parameters:
* `NODE_API_KEY` = API key which will be required from your Samourai Wallet / Sentinel for its interactions with the API of your Dojo,
* `NODE_ADMIN_KEY` = API key which will be required from the maintenance tool for accessing a set of advanced features provided by the API of your Dojo,
* `NODE_JWT_SECRET` = secret used by your Dojo for the initialization of a cryptographic key signing Json Web Tokens.
These parameters will protect the access to your Dojo. Be sure to provide alphanumeric values with enough entropy.

* If you want to activate the local block explorer, edit docker-explorer.conf.tpl:
* set the value of `EXPLORER_INSTALL` to `on`,
* set the value of `EXPLORER_KEY` with a password that will be required to access the block explorer.
See this [section](#explorer) for more details.

* Dojo provides a few additional settings for advanced setups:
* static onion address for your full node,
* bitcoind RPC API exposed to external apps,
Expand All @@ -151,7 +163,7 @@ This procedure allows to install a new Dojo from scratch.
./dojo.sh install
```

Docker and Docker Compose are going to build the images and containers of your Dojo. This operation will take a few minutes (download and setup of all required software components). After completion, your Dojo will be launched and will begin the initialization of the full node (Bitcoin Initial Block Download and syncing of the database). This step will take several hours/days according to the specs of your machine. Be patient. Use CTRL+C to stop the display of the full logs.
Docker and Docker Compose are going to build the images and containers of your Dojo. This operation will take several minutes (download and setup of all required software components). After completion, your Dojo will be launched and will begin the initialization of the full node (Bitcoin Initial Block Download and syncing of the database). This step will take several hours/days according to the specs of your machine. Be patient. Use CTRL+C to stop the display of the full logs.


* Monitor the progress made for the initialization of the database with this command displaying the logs of the tracker
Expand All @@ -163,7 +175,7 @@ Docker and Docker Compose are going to build the images and containers of your D
Exit the logs with CTRL+C when the syncing of the database has completed.


* Retrieve the Tor onion addresses (v2 and v3) of the API of your Dojo
* Retrieve the Tor onion addresses (v3) of the API and block explorer of your Dojo

```
./dojo.sh onion
Expand Down Expand Up @@ -198,7 +210,7 @@ This procedure allows to upgrade your Dojo with a new version.

Docker and Docker Compose are going to build new images and containers for your Dojo. After completion, the updated version of your Dojo will be launched automatically.

Note: The upgrade process will override all manual modifications of the files stored under the `<dojo_dir>` directory with an exception for the three configuration files stored in the `<dojo_dir>/docker/my-dojo/conf` directory.
Note: The upgrade process will override all manual modifications of the files stored under the `<dojo_dir>` directory with an exception for the configuration files stored in the `<dojo_dir>/docker/my-dojo/conf` directory.


<a name="shell_script"/>
Expand Down Expand Up @@ -231,13 +243,14 @@ Available commands:
dojo.sh logs tracker : display the logs of the Tracker (nodejs)
dojo.sh logs pushtx : display the logs of the pushTx API (nodejs)
dojo.sh logs pushtx-orchest : display the logs of the Orchestrator (nodejs)
dojo.sh logs explorer : display the logs of the Explorer

Available options (for api, tracker, pushtx and pushtx-orchest modules):
Available options (for api, tracker, pushtx, pushtx-orchest and explorer modules):
-d [VALUE] : select the type of log to be displayed.
VALUE can be output (default) or error.
-n [VALUE] : display the last VALUE lines

onion Display the Tor onion address allowing your wallet to access your Dojo.
onion Display the Tor onion addresses allowing to access the API, maintenance tool and block explorer of your Dojo.

restart Restart your Dojo.

Expand All @@ -264,6 +277,27 @@ The maintenance tool requires that you allow javascript for the site.
Sign in with the value entered for `NODE_ADMIN_KEY`.


<a name="explorer"/>

## Block explorer ##

An optional block explorer ([BTC RPC Explorer](https://github.com/janoside/btc-rpc-explorer)) is accessible through your Tor browser.

You can retrieve the onion address of the block explorer with the command

```
./dojo.sh onion
```

Sign in with a login (can be any value) and the password set in your Dojo configuration (value entered for `EXPLORER_KEY`).

Notes:

* Current version doesn't support the display of detailed information for a Bitcoin address,

* Calls to the RPC API of your bitcoind through the interface of the block explorer are deactivated.


<a name="pairing"/>

## Pairing your wallet to your Dojo ##
Expand All @@ -272,11 +306,20 @@ Once the database has finished syncing, you can pair your Samourai Wallet with y

1. Open the maintenance tool in a Tor browser (Tor v3 onion address) and sign in with your admin key.

2. Get your smartphone and launch the Samourai Wallet app. Scan the QRCode displayed in the "Pairing" tab of the maintenance tool.
2. Get your smartphone and launch the Samourai Wallet app. Scan the first QRCode displayed in the "Pairing" tab of the maintenance tool.

If you experience any problems when pairing, try re-installing the app and select "Connect to existing Dojo" from the [⋮] menu.


## Pairing your wallet to your local block explorer (coming "soon") ##

You can pair your Samourai Wallet with your local block explorer in 2 steps:

1. Open the maintenance tool in a Tor browser (Tor v3 onion address) and sign in with your admin key.

2. Get your smartphone and launch the Samourai Wallet app. Scan the second QRCode displayed in the "Pairing" tab of the maintenance tool.


<a name="network"/>

## Network connections ##
Expand All @@ -287,6 +330,8 @@ If OXT is selected as the default source for imports, OXT clearnet API is access

The maintenance tool is accessed as a Tor hidden service (static onion address).

The block explorer is accessed as a Tor hidden service (static onion address).

The Bitcoin node only allows incoming connections from Tor (ephemeral onion address).

The Bitcoin node attempts outgoing connections to both Tor and clearnet nodes (through the Tor local proxy).
1 change: 1 addition & 0 deletions docker/my-dojo/.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DOJO_BITCOIND_VERSION_TAG=1.3.0
DOJO_NODEJS_VERSION_TAG=1.3.0
DOJO_NGINX_VERSION_TAG=1.3.0
DOJO_TOR_VERSION_TAG=1.2.0
DOJO_EXPLORER_VERSION_TAG=1.0.0


#########################################
Expand Down
16 changes: 16 additions & 0 deletions docker/my-dojo/conf/docker-explorer.conf.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#########################################
# CONFIGURATION OF EXPLORER CONTAINER
#########################################


# Install and run a block explorer inside Dojo
# Value: on | off
EXPLORER_INSTALL=off


# Password required for accessing the block explorer
# (login can be anything)
# Keep this password secret!
# Provide a value with a high entropy!
# Type: alphanumeric
EXPLORER_KEY=myExplorerPassword
4 changes: 4 additions & 0 deletions docker/my-dojo/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -39,6 +40,7 @@ services:
- "8082"
volumes:
- data-nodejs:/data
- data-tor:/var/lib/tor
depends_on:
- db
networks:
Expand All @@ -57,6 +59,7 @@ services:
command: "/wait-for node:8080 --timeout=720 -- nginx"
expose:
- "80"
- "9080"
volumes:
- data-nginx:/data
depends_on:
Expand All @@ -74,6 +77,7 @@ services:
context: ./tor
env_file:
- ./.env
- ./conf/docker-explorer.conf
- ./conf/docker-tor.conf
restart: on-failure
command: /restart.sh
Expand Down
Loading