From 3363bd1cb91d57b918b5e8e0ba00d4d273421e5b Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Mon, 6 Aug 2018 12:36:38 +0100 Subject: [PATCH] Update README.md with installation instructions. --- README.md | 84 +++++++++++++++++++++++++++++++ config/lbry.default.php | 11 ++++ sql/lbryexplorer.ddl.sql | 2 +- src/Controller/MainController.php | 2 +- src/Shell/AuxShell.php | 2 +- src/Shell/BlockShell.php | 7 +-- 6 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 config/lbry.default.php diff --git a/README.md b/README.md index e69de29..31f764c 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,84 @@ +# LBRY Block Explorer + +A simple PHP block explorer for browsing transactions and claims on the [LBRY](https://lbry.io) blockchain. The explorer was developed using CakePHP which is a model-view-controller (MVC) PHP framework. + +## Installation +There are some prerequisites that need to be installed before the explorer can be accessed. +* Web server - Apache, caddy or nginx +* lbrycrd with txindex turned on +* Python claims decoder (https://github.com/cryptodevorg/lbry-decoder) +* MariaDB 10.2 or higher +* Redis Server (optional, only required for the CakePHP redis cache engine, or to run `forevermempool`) +* PHP 7.2 or higher + * php-fpm + * igbinary extension (https://github.com/igbinary/igbinary) + * phpredis extension (https://github.com/phpredis/phpredis) +* composer (PHP package manager) + +### Installation steps +* Clone the Github repository. `git clone https://github.com/lbryio/block-explorer` +* Create a MariaDB database using the DDL found in `block-explorer/sql/lbryexplorer.ddl.sql` +* Change the working directory to the cloned directory and run composer. +``` +cd block-explorer +composer update +``` +* Create the directories, `tmp` and `logs` in the `block-explorer` folder if they have not been created yet, and make sure that they are writable by the web server. +* Copy `config/app.default.php` to `config/app.php`. Edit the database connection values to correspond to your environment. +* Copy `config/lbry.default.php` to `config/lbry.php`. Update the values for LBRY RPC URL and the Redis URL to correspond to your environment. +* Configure your web server with the host root folder set to `/block-explorer/webroot` where `` is the absolute path to the configuraiton. Here is a sample nginx configuration. You can make changes to this configuration to correspond to your environment. +``` +server { + listen 80; + server_name my.explorer.com; + + root /var/www/block-explorer/webroot; + index index.php; + + location / { + try_files $uri $uri/ /index.php?$args; + } + + # pass the PHP scripts to FastCGI server listening on the php-fpm socket + location ~ \.php$ { + try_files $uri =404; + include /etc/nginx/fastcgi_params; + fastcgi_pass 127.0.0.1:9000; + fastcgi_index index.php; + fastcgi_ignore_client_abort on; + fastcgi_param PHP_AUTH_USER $remote_user; + fastcgi_param PHP_AUTH_PW $http_authorization; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + } +} +``` +* Restart your web server. + +### Cron jobs +There are a few scripts which can be set up as cron jobs or scheduled tasks. +#### blocks.sh +Detect new LBRY blocks. Can also be configured to be triggered using the lbrycrd `blocknotify` flag. This cron will create new blocks obtained from lbrycrd starting from the highest block number in the database, and then create the corresponding block transactions. If there are pending transactions created by the forevermempool script, they will be automatically associated with the respective blocks. +#### claimindex.sh +Create claims found on the LBRY blockchain in the database. This requires the Python decoder to be running in the background. +#### pricehistory.sh +Get the current LBC price in USD and store the value in the `PriceHistory` table. This also caches the most recent price in Redis. +#### forever.sh +Run the `forevermempool` script, and restart if necessary. The `forevermempool` script checks the LBRY blockchain mempool every second and creates transactions found in the database. The script makes use of Redis for caching the pending transation IDs. + +## Usage +Launch the URL for the configured web server root in a browser. + +## Running from Source +There are no particular steps required to run from source. + +## Contributing +Contributions to this project are welcome, encouraged, and compensated. For more details, see https://lbry.io/faq/contributing + +## License +This project is MIT licensed. For the full license, see [LICENSE](LICENSE). + +## Security +We take security seriously. Please contact security@lbry.io regarding any security issues. Our PGP key is [here](https://keybase.io/lbry/key.asc) if you need it. + +## Contact +The primary contact for this project is [@akinwale](https://github.com/akinwale) (akinwale@lbry.io) diff --git a/config/lbry.default.php b/config/lbry.default.php new file mode 100644 index 0000000..f1a5a2b --- /dev/null +++ b/config/lbry.default.php @@ -0,0 +1,11 @@ + [ + 'RpcUrl' => 'http://user:password@127.0.0.1:9245', + ], + + 'Redis' => [ + 'Url' => 'tcp://127.0.0.1:6379', + ] +]; diff --git a/sql/lbryexplorer.ddl.sql b/sql/lbryexplorer.ddl.sql index 50e04d0..d151efb 100644 --- a/sql/lbryexplorer.ddl.sql +++ b/sql/lbryexplorer.ddl.sql @@ -1,4 +1,4 @@ -l--DROP DATABASE IF EXISTS lbry; +--DROP DATABASE IF EXISTS lbry; CREATE DATABASE lbry DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci; USE lbry; diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 42e6443..5ac133c 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -31,7 +31,7 @@ class MainController extends AppController { public function initialize() { parent::initialize(); self::$rpcurl = Configure::read('Lbry.RpcUrl'); - $this->redis = new \Predis\Client('tcp://127.0.0.1:6379'); + $this->redis = new \Predis\Client(Configure::read('Redis.Url')); try { $this->redis->info('mem'); } catch (\Predis\Connection\ConnectionException $e) { diff --git a/src/Shell/AuxShell.php b/src/Shell/AuxShell.php index 2c8731d..2495a9c 100644 --- a/src/Shell/AuxShell.php +++ b/src/Shell/AuxShell.php @@ -128,7 +128,7 @@ class AuxShell extends Shell { self::lock('pricehistory'); $conn = ConnectionManager::get('default'); - $redis = new \Predis\Client('tcp://127.0.0.1:6379'); + $redis = new \Predis\Client(Configure::read('Redis.Url')); try { // Only allow 5-minute update intervals diff --git a/src/Shell/BlockShell.php b/src/Shell/BlockShell.php index efb3855..f7530a8 100644 --- a/src/Shell/BlockShell.php +++ b/src/Shell/BlockShell.php @@ -13,17 +13,18 @@ class BlockShell extends Shell { public static $rpcurl; + public static $redisurl; + const mempooltxkey = 'lbc.mempooltx'; const pubKeyAddress = [0, 85]; const scriptAddress = [5, 122]; - const redisurl = 'tcp://127.0.0.1:6379'; - public function initialize() { parent::initialize(); self::$rpcurl = Configure::read('Lbry.RpcUrl'); + self::$redisurl = Configure::read('Redis.Url'); $this->loadModel('Blocks'); $this->loadModel('Addresses'); $this->loadModel('Claims'); @@ -2073,7 +2074,7 @@ print_r($response); print_r($json); } public static function _init_redis() { - $redis = new \Predis\Client(self::redisurl); + $redis = new \Predis\Client(self::$redisurl); try { $redis->info('mem'); } catch (\Predis\Connection\ConnectionException $e) {