Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
Restructure BSQ explorer as system service for easy installation
Browse files Browse the repository at this point in the history
* Re-implement as systemd service using bisq-seednode.env
* Merge all python code into single executable script
* Merge all shell scripts into single "daemon" wrapper
* Upgrade all python code to python3 syntax
* Remove dead python code for Bitcoin RPC queries
* Remove dependency on python-bitcoinrpc
* Add one command installation script for BSQ explorer
* Rewrite README with new installation instructions
  • Loading branch information
wiz committed Jan 4, 2020
1 parent 46f9fa1 commit 1310ca2
Show file tree
Hide file tree
Showing 12 changed files with 499 additions and 550 deletions.
147 changes: 38 additions & 109 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,137 +1,66 @@
# Bisq BSQ Explorer
# BSQ Block Explorer

## Overview
The BSQ explorer provides basic information about BSQ transactions.
It is based on static html pages which are rendered from json files generated by a Bisq application running on the
server. Beside http server and Bisq (we run a seednode instance) we require bitcoind as the Bisq node is running in
fullnode mode.
Follow these instructions to setup a [BSQ Block Explorer](https://explorer.bisq.network) using data from your [Bisq Seednode](https://github.com/bisq-network/bisq/tree/master/seednode). Keep in mind you need a dedicated seednode for the BSQ explorer, as the JSON data dump puts too much load on it to seed the network properly.

## Bisq Seednode

### Installation
Requires Bisq seednode with `--dumpBlockchainData=true`
First, [setup your Bisq Seednode](https://github.com/bisq-network/bisq/tree/master/seednode#bisq-seed-node) so you have Tor, Bitcoin, and bisq-seednode running and fully synced. Then, enable BSQ data output on your Bisq Seednode with the following command

#### Web Server
```
sudo apt-get update
sudo apt-get install nginx
```bash
sudo sed -i -e 's!BISQ_DUMP_BLOCKCHAIN=false!BISQ_DUMP_BLOCKCHAIN=true!' /etc/default/bisq-seednode.env
sudo service bisq-seednode restart
```

Check that it's running
It will take 10+ minutes before the seednode starts saving BSQ transaction data.

```
systemctl status nginx
```
Copy nginx.config to /etc/nginx/sites-available and symlink from /etc/nginx/sites-enabled. Remove sym link to
default site. Replace `hostname` with site name.
### Let's Encrypt

Install certificate
Next, request an SSL certificate for your server from Let's Encrypt using certbot-nginx

```
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx
sudo certbot --nginx
```bash
sudo apt-get update -q
sudo apt-get install -q -y nginx-core python-certbot-nginx
sudo certbot --nginx --agree-tos --non-interactive -m [email protected] -d explorer.example.com
```

Set automatic certificate renewal in crontab. Try to renew every month. Edit crontab...
After obtaining your SSL certificate, you should be able to see the default page at https://explorer.example.com/

```
sudo crontab -e
```
...and paste this line2
```
0 0 1 * * certbot renew
```
### BSQ Indexer

#### Explorer
Some needed pyhton packages
```
sudo pip install python-bitcoinrpc
sudo pip install simplejson
sudo pip install gitpython
```

Setup variables for other commands below to use:
```
export EXPLORER_HOME=<your full path to explorer>
export DATADIR=<path to bisq db directory>
```

examples:
```
#we assume you cloned this repo to: /home/user/bisq-explorer
#we assume bisq-seednode was run with --appName=seed_2002 and testnet is used as network
export EXPLORER_HOME=/home/user/bisq-explorer
export DATADIR=/home/user/.local/share/seed_2002/btc_testnet/db
Clone this repo to bisq user's homedir
```bash
curl -s https://raw.githubusercontent.com/bisq-network/bisq-explorer/master/install_bsq_explorer_debian.sh | sudo bash
```

HTML need to point to explorer/www
```
cd /var/www
sudo ln -s ${EXPLORER_HOME}/www html
```
### Nginx

Copy Bisq seednode db directory contents to `$EXPLORER_HOME`
```
mkdir ${EXPLORER_HOME}/data
cp -r ${DATADIR}/* ${EXPLORER_HOME}/data
Install the nginx.conf from this repository, substituting explorer.example.com for your server hostname
```bash
sudo wget -O /etc/nginx/nginx.conf https://raw.githubusercontent.com/bisq-network/bisq-explorer/master/nginx.conf
sudo sed -i -e '!__HOSTNAME__!explorer.example.com!g' /etc/nginx/nginx.conf
sudo service nginx restart
```

For the update script `inotifywait` is needed, it's part of inotify-tools
```
sudo apt install inotify-tools
```
You should now be able to access your BSQ explorer at https://explorer.example.com/

#### Bitcoin
Bitcoin blocknotify script needs `nc`
```
sudo apt install netcat-openbsd
```
### Tor onion (optional)

Example `bitcoin.conf`
Add these lines to the bottom of /etc/tor/torrc
```
# Uncomment to run on testnet
#testnet=1
lang=en
whitelist=127.0.0.1
rpcallowip=127.0.0.1
rpcport=18332
server=1
txindex=1
rpcuser=bisquser
rpcpassword=bisqpasswd
blocknotify=bash $HOME/.bitcoin/blocknotify %s
HiddenServiceDir /var/lib/tor/bsqexplorer/
HiddenServicePort 80 127.0.0.1:80
HiddenServiceVersion 2
```
Example `blocknotify`

Then restart Tor with the following command
```bash
sudo service tor restart
```
#!/bin/bash
echo $1 | nc -w 1 127.0.0.1 5110

```
### Run
After Tor restarts, it will generate your onion hostname, get it by doing:

Copy update_monitor.sh to a location outside of the explorer directory where the
script will be run from. Then edit it to configure the DATADIR and EXPLORER_HOME derictories.

You can use these commands to edit the files:
```
sed -Ei 's|DATADIR=.*|DATADIR='"${DATADIR}"'|' update_monitor.sh
sed -Ei 's|EXPLORER_HOME=.*|EXPLORER_HOME='"${EXPLORER_HOME}"'|' update_monitor.sh
```bash
sudo cat /var/lib/tor/bsqexplorer/hostname
```

To start the update monitor
```
./update_monitor.sh
```

To update the explorer state, using the data from bisq seednode it's possible
to run the update manually.
```
cd ${EXPLORER_HOME}
./update_data.sh ${DATADIR}
```
Then you can also access your BSQ explorer over Tor at http://foo.onion/
18 changes: 18 additions & 0 deletions bsq-explorer-update
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -a
source /etc/default/bisq-seednode.env
set +a
if [ -z "${BISQ_JSON_DIR}" ] || [ -z "${BSQ_EXPLORER_ROOT}" ];then
echo "Environment variable missing! Check bisq-seednode.env configuration!"
exit 1
fi

while inotifywait -r -e modify,move,create,delete "${BISQ_JSON_DIR}"
do
echo "Bisq has updated JSON data dump for BSQ transactions!"
sleep 5
echo "Syncing JSON from Bisq ${BISQ_JSON_DIR} to ${BSQ_EXPLORER_ROOT}/data/"
rsync -rt --exclude '*.tmp' "${BISQ_JSON_DIR}" "${BSQ_EXPLORER_ROOT}/data/"
echo "Re-indexing BSQ Explorer webroot"
/usr/local/bin/bsq-index
done
20 changes: 20 additions & 0 deletions bsq-explorer.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[Unit]
Description=BSQ Explorer
After=network.target

[Service]
ExecStart=/usr/local/bin/bsq-explorer-update
ExecStop=/bin/kill -TERM ${MAINPID}
Restart=on-failure

User=bisq
Group=bisq

PrivateTmp=true
ProtectSystem=full
NoNewPrivileges=true
PrivateDevices=true
MemoryDenyWriteExecute=false

[Install]
WantedBy=multi-user.target
Loading

0 comments on commit 1310ca2

Please sign in to comment.