Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60580adb0b | ||
|
|
3363bd1cb9 | ||
|
|
a8a956f2bc | ||
|
|
b91b3681d3 | ||
|
|
190d998e4c | ||
|
|
667097f35d | ||
|
|
8d552afe8f | ||
|
|
ad4615cc5a | ||
|
|
3ad5db032b | ||
|
|
e25cd7807e | ||
|
|
71c7834521 | ||
|
|
27ff22ff5a |
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
||||
/vendor/*
|
||||
/config/app.php
|
||||
/tmp/*
|
||||
/config/lbry.php
|
||||
/logs/*
|
||||
lbryexplorer.zip
|
||||
lbryexplorer.komodoproject
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
# 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](https://github.com/lbryio/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 `<path to>/block-explorer/webroot` where `<path to>` 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.
|
||||
|
||||
|
||||
## 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)
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
"mobiledetect/mobiledetectlib": "2.*",
|
||||
"cakephp/migrations": "~1.0",
|
||||
"cakephp/plugin-installer": "~1.0",
|
||||
"mdanter/ecc": "^0.4.2",
|
||||
"mdanter/ecc": "^0.5.0",
|
||||
"nesbot/carbon": "~1.18",
|
||||
"endroid/qrcode": "^2.2.2",
|
||||
"predis/predis": "^1.1.1"
|
||||
|
||||
Generated
+488
-494
File diff suppressed because it is too large.
Load diff
@@ -220,3 +220,6 @@ Type::build('timestamp')
|
||||
if (Configure::read('debug')) {
|
||||
Plugin::load('DebugKit', ['bootstrap' => true]);
|
||||
}
|
||||
|
||||
Configure::load('lbry');
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'Lbry' => [
|
||||
'RpcUrl' => 'http://user:password@127.0.0.1:9245',
|
||||
],
|
||||
|
||||
'Redis' => [
|
||||
'Url' => 'tcp://127.0.0.1:6379',
|
||||
]
|
||||
];
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
cd /var/www/lbry.block.ng
|
||||
cd /home/lbry/explorer.lbry.io
|
||||
bin/cake block addrtxamounts
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
cd /var/www/lbry.block.ng
|
||||
cd /home/lbry/explorer.lbry.io
|
||||
bin/cake block parsenewblocks
|
||||
rm tmp/lock/parsenewblocks
|
||||
rm tmp/lock/parsenewblocks 2>/dev/null
|
||||
bin/cake block parsetxs
|
||||
rm tmp/lock/parsetxs
|
||||
rm tmp/lock/parsetxs 2>/dev/null
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
<?php
|
||||
|
||||
define('TMP', '/tmp/');
|
||||
define('DS', '/');
|
||||
|
||||
class BlockSyncThread extends \Thread {
|
||||
private $_startHeight;
|
||||
private $_endHeight;
|
||||
private $_maxHeight;
|
||||
|
||||
public function __construct($startBlock, $endBlock, $maxHeight) {
|
||||
$this->_startHeight = $startBlock;
|
||||
$this->_endHeight = $endBlock;
|
||||
$this->_maxHeight = $maxHeight;
|
||||
}
|
||||
|
||||
public function run() {
|
||||
$conn = new \PDO("mysql:host=localhost;dbname=lbry", 'lbry-admin', '46D861aX#!yQ');
|
||||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$data_error = false;
|
||||
$conn->beginTransaction();
|
||||
|
||||
// TODO: Batch block synchronisation from memory to DB
|
||||
|
||||
for ($curr_height = $this->_startHeight; $curr_height <= $this->_endHeight; $curr_height++) {
|
||||
$idx_str = str_pad($curr_height, strlen($this->_maxHeight), '0', STR_PAD_LEFT);
|
||||
|
||||
// get the block hash
|
||||
$req = ['method' => 'getblockhash', 'params' => [$curr_height]];
|
||||
$response = BlockStuff::curl_json_post(BlockStuff::rpcurl, json_encode($req));
|
||||
$json = json_decode($response);
|
||||
$curr_block_hash = $json->result;
|
||||
|
||||
$req = ['method' => 'getblock', 'params' => [$curr_block_hash]];
|
||||
$response = BlockStuff::curl_json_post(BlockStuff::rpcurl, json_encode($req));
|
||||
$json = json_decode($response);
|
||||
$curr_block = $json->result;
|
||||
|
||||
$stmt = $conn->prepare('UPDATE Blocks SET Confirmations = ? WHERE Height = ?');
|
||||
try {
|
||||
$stmt->execute([$curr_block->confirmations, $curr_height]);
|
||||
echo "[$idx_str/$this->_maxHeight] Updated block height: $curr_height with confirmations $curr_block->confirmations.\n";
|
||||
} catch (Exception $e) {
|
||||
$data_error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($data_error) {
|
||||
echo "Rolling back changes.\n";
|
||||
$conn->rollBack();
|
||||
return;
|
||||
}
|
||||
|
||||
echo "Committing data.\n";
|
||||
$conn->commit();
|
||||
}
|
||||
}
|
||||
|
||||
class BlockStuff {
|
||||
const rpcurl = 'http://lrpc:lrpc@127.0.0.1:9245';
|
||||
public static function blocksync() {
|
||||
self::lock('blocksync');
|
||||
|
||||
$conn = new \PDO("mysql:host=localhost;dbname=lbry", 'lbry-admin', '46D861aX#!yQ');
|
||||
|
||||
$stmt = $conn->prepare('SELECT Height FROM Blocks ORDER BY Height DESC LIMIT 1');
|
||||
$stmt->execute([]);
|
||||
$max_block = $stmt->fetch(PDO::FETCH_OBJ);
|
||||
if ($max_block) {
|
||||
$chunk_limit = 2;
|
||||
$curr_height = 0;
|
||||
$chunks = floor($max_block->Height / $chunk_limit);
|
||||
$threads = [];
|
||||
for ($i = 0; $i < $chunk_limit; $i++) {
|
||||
$start = $curr_height;
|
||||
$end = ($i == ($chunk_limit - 1)) ? $max_block->Height : $start + $chunks;
|
||||
$curr_height += $chunks + 1;
|
||||
$thread = new BlockSyncThread($start, $end, $max_block->Height);
|
||||
$threads[] = $thread;
|
||||
|
||||
$thread->start();
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($threads); $i++) {
|
||||
$threads[$i]->join();
|
||||
}
|
||||
}
|
||||
|
||||
self::unlock('blocksync');
|
||||
}
|
||||
|
||||
public static function curl_json_post($url, $data, $headers = []) {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
//Log::debug('Request execution completed.');
|
||||
if ($response === false) {
|
||||
$error = curl_error($ch);
|
||||
$errno = curl_errno($ch);
|
||||
curl_close($ch);
|
||||
|
||||
throw new \Exception(sprintf('The request failed: %s', $error), $errno);
|
||||
} else {
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
// Close any open file handle
|
||||
return $response;
|
||||
}
|
||||
|
||||
public static function lock($process_name) {
|
||||
if (!is_dir(TMP . 'lock')) {
|
||||
mkdir(TMP . 'lock');
|
||||
}
|
||||
$lock_file = TMP . 'lock' . DS . $process_name;
|
||||
if (file_exists($lock_file)) {
|
||||
echo "$process_name is already running.\n";
|
||||
exit(0);
|
||||
}
|
||||
file_put_contents($lock_file, '1');
|
||||
}
|
||||
|
||||
public static function unlock($process_name) {
|
||||
$lock_file = TMP . 'lock' . DS . $process_name;
|
||||
if (file_exists($lock_file)) {
|
||||
unlink($lock_file);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
BlockStuff::blocksync();
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
cd /var/www/lbry.block.ng
|
||||
cd /home/lbry/explorer.lbry.io
|
||||
bin/cake block parsetxs
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
cd /var/www/lbry.block.ng
|
||||
cd /home/lbry/explorer.lbry.io
|
||||
bin/cake block buildclaimindex
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
cd /var/www/lbry.block.ng/cron
|
||||
php -d extension=pthreads.so blockstuff.php
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
cd /var/www/lbry.block.ng
|
||||
cd /home/lbry/explorer.lbry.io
|
||||
bin/cake block fixzerooutputs
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
pkill -f forevermempool
|
||||
rm -f /home/lbry/explorer.lbry.io/tmp/lock/forevermempool 2>/dev/null
|
||||
cd /home/lbry/explorer.lbry.io
|
||||
bin/cake block forevermempool &
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
cd /var/www/lbry.block.ng
|
||||
bin/cake block forevermempool &
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
cd /var/www/lbry.block.ng
|
||||
cd /home/lbry/explorer.lbry.io
|
||||
bin/cake block parsemempool
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
cd /var/www/lbry.block.ng
|
||||
cd /home/lbry/explorer.lbry.io
|
||||
bin/cake aux pricehistory
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
cd /var/www/lbry.block.ng
|
||||
cd /home/lbry/explorer.lbry.io
|
||||
bin/cake block updatespends
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
cd /var/www/lbry.block.ng
|
||||
cd /home/lbry/explorer.lbry.io
|
||||
bin/cake aux verifytags
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ use Mdanter\Ecc\Crypto\Signature\Signer;
|
||||
use Mdanter\Ecc\Serializer\PublicKey\PemPublicKeySerializer;
|
||||
use Mdanter\Ecc\Serializer\PublicKey\DerPublicKeySerializer;
|
||||
use Mdanter\Ecc\Serializer\Signature\DerSignatureSerializer;
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\ConnectionManager;
|
||||
use Cake\Log\Log;
|
||||
use Endroid\QrCode\ErrorCorrectionLevel;
|
||||
@@ -15,7 +16,7 @@ use Endroid\QrCode\QrCode;
|
||||
|
||||
class MainController extends AppController {
|
||||
|
||||
const rpcurl = 'http://lrpc:lrpc@127.0.0.1:9245';
|
||||
public static $rpcurl;
|
||||
|
||||
const lbcPriceKey = 'lbc.price';
|
||||
|
||||
@@ -29,7 +30,8 @@ class MainController extends AppController {
|
||||
|
||||
public function initialize() {
|
||||
parent::initialize();
|
||||
$this->redis = new \Predis\Client('tcp://127.0.0.1:6379');
|
||||
self::$rpcurl = Configure::read('Lbry.RpcUrl');
|
||||
$this->redis = new \Predis\Client(Configure::read('Redis.Url'));
|
||||
try {
|
||||
$this->redis->info('mem');
|
||||
} catch (\Predis\Connection\ConnectionException $e) {
|
||||
@@ -400,7 +402,11 @@ class MainController extends AppController {
|
||||
}
|
||||
|
||||
$offset = ($page - 1) * $pageLimit;
|
||||
$blocks = $this->Blocks->find()->offset($offset)->limit($pageLimit)->order(['Height' => 'DESC'])->toArray();
|
||||
$currentBlock = $this->Blocks->find()->select(['Height'])->order(['Height' => 'DESC'])->first();
|
||||
$blocks = $this->Blocks->find()->select(
|
||||
['Height', 'Difficulty', 'TransactionHashes', 'BlockSize', 'Nonce', 'BlockTime']
|
||||
)->offset($offset)->limit($pageLimit)->order(['Height' => 'DESC'])->toArray();
|
||||
$this->set('currentBlock', $currentBlock);
|
||||
$this->set('blocks', $blocks);
|
||||
$this->set('pageLimit', $pageLimit);
|
||||
$this->set('numPages', $numPages);
|
||||
@@ -421,7 +427,7 @@ class MainController extends AppController {
|
||||
try {
|
||||
// update the block confirmations
|
||||
$req = ['method' => 'getblock', 'params' => [$block->Hash]];
|
||||
$response = self::curl_json_post(self::rpcurl, json_encode($req));
|
||||
$response = self::curl_json_post(self::$rpcurl, json_encode($req));
|
||||
$json = json_decode($response);
|
||||
$rpc_block = $json->result;
|
||||
if (isset($rpc_block->confirmations)) {
|
||||
@@ -460,7 +466,9 @@ class MainController extends AppController {
|
||||
$conn->execute('UPDATE Transactions SET TransactionSize = ? WHERE Id = ?', [$tx->TransactionSize, $tx->Id]);
|
||||
}
|
||||
|
||||
$maxBlock = $this->Blocks->find()->select(['Height'])->order(['Height' => 'desc'])->first();
|
||||
$block = $this->Blocks->find()->select(['Confirmations', 'Height'])->where(['Hash' => $tx->BlockHash])->first();
|
||||
$confirmations = $block ? (($maxBlock->Height - $block->Height) + 1) : '0';
|
||||
$inputs = $this->Inputs->find()->contain(['InputAddresses'])->where(['TransactionId' => $tx->Id])->order(['PrevoutN' => 'asc'])->toArray();
|
||||
$outputs = $this->Outputs->find()->contain(['OutputAddresses', 'SpendInput' => ['fields' => ['Id', 'TransactionHash', 'PrevoutN', 'PrevoutHash']]])->where(['Outputs.TransactionId' => $tx->Id])->order(['Vout' => 'asc'])->toArray();
|
||||
for ($i = 0; $i < count($outputs); $i++) {
|
||||
@@ -482,7 +490,7 @@ class MainController extends AppController {
|
||||
|
||||
$this->set('tx', $tx);
|
||||
$this->set('block', $block);
|
||||
$this->set('confirmations', $block ? number_format($block->Confirmations, 0, '', ',') : '0');
|
||||
$this->set('confirmations', $confirmations);
|
||||
$this->set('fee', $fee);
|
||||
$this->set('inputs', $inputs);
|
||||
$this->set('outputs', $outputs);
|
||||
@@ -524,6 +532,7 @@ class MainController extends AppController {
|
||||
public function address($addr = null) {
|
||||
set_time_limit(0);
|
||||
|
||||
$this->loadModel('Blocks');
|
||||
$this->loadModel('Addresses');
|
||||
$this->loadModel('Transactions');
|
||||
$this->loadModel('Inputs');
|
||||
@@ -552,7 +561,6 @@ class MainController extends AppController {
|
||||
$tagRequestAmount = '25.' . rand(11111111, 99999999);
|
||||
}
|
||||
|
||||
|
||||
$address = $this->Addresses->find()->where(['Address' => $addr])->first();
|
||||
if (!$address) {
|
||||
if (strlen($addr) === 34) {
|
||||
@@ -591,13 +599,18 @@ class MainController extends AppController {
|
||||
$stmt = $conn->execute('SELECT A.TotalReceived, A.TotalSent, A.Balance FROM Addresses A WHERE A.Id = ?', [$address->Id]);
|
||||
$totals = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
|
||||
$stmt = $conn->execute(sprintf('SELECT T.Id, T.Hash, T.InputCount, T.OutputCount, T.Value, ' .
|
||||
'TA.DebitAmount, TA.CreditAmount, ' .
|
||||
'B.Height, B.Confirmations, IFNULL(T.TransactionTime, T.CreatedTime) AS TxTime ' .
|
||||
'FROM Transactions T ' .
|
||||
'LEFT JOIN Blocks B ON T.BlockHash = B.Hash ' .
|
||||
'RIGHT JOIN (SELECT TransactionId, DebitAmount, CreditAmount FROM TransactionsAddresses ' .
|
||||
' WHERE AddressId = ? ORDER BY TransactionTime DESC LIMIT %d, %d) TA ON TA.TransactionId = T.Id', $offset, $pageLimit), [$addressId]);
|
||||
$currentBlock = $this->Blocks->find()->select(['Height'])->order(['Height' => 'desc'])->first();
|
||||
$currentHeight = $currentBlock ? intval($currentBlock->Height) : 0;
|
||||
|
||||
$stmt = $conn->execute(sprintf(
|
||||
'SELECT T.Id, T.Hash, T.InputCount, T.OutputCount, T.Value, ' .
|
||||
' TA.DebitAmount, TA.CreditAmount, ' .
|
||||
' B.Height, (CASE WHEN B.Height IS NOT NULL THEN ((' . $currentHeight . ' - B.Height) + 1) ELSE NULL END) AS Confirmations, ' .
|
||||
' IFNULL(T.TransactionTime, T.CreatedTime) AS TxTime ' .
|
||||
'FROM Transactions T ' .
|
||||
'LEFT JOIN Blocks B ON T.BlockHash = B.Hash ' .
|
||||
'RIGHT JOIN (SELECT TransactionId, DebitAmount, CreditAmount FROM TransactionsAddresses ' .
|
||||
' WHERE AddressId = ? ORDER BY TransactionTime DESC LIMIT %d, %d) TA ON TA.TransactionId = T.Id', $offset, $pageLimit), [$addressId]);
|
||||
$recentTxs = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
||||
|
||||
$totalRecvAmount = $totals->TotalReceived == 0 ? '0' : $totals->TotalReceived + 0;
|
||||
@@ -671,7 +684,7 @@ class MainController extends AppController {
|
||||
private function _gethashrate() {
|
||||
$req = ['method' => 'getnetworkhashps', 'params' => []];
|
||||
try {
|
||||
$res = json_decode(self::curl_json_post(self::rpcurl, json_encode($req)));
|
||||
$res = json_decode(self::curl_json_post(self::$rpcurl, json_encode($req)));
|
||||
if (!isset($res->result)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -680,10 +693,11 @@ class MainController extends AppController {
|
||||
return 'N/A';
|
||||
}
|
||||
}
|
||||
|
||||
private function _gettxoutsetinfo() {
|
||||
$req = ['method' => 'gettxoutsetinfo', 'params' => []];
|
||||
try {
|
||||
$res = json_decode(self::curl_json_post(self::rpcurl, json_encode($req)));
|
||||
$res = json_decode(self::curl_json_post(self::$rpcurl, json_encode($req)));
|
||||
if (!isset($res->result)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -692,6 +706,7 @@ class MainController extends AppController {
|
||||
return 'N/A';
|
||||
}
|
||||
}
|
||||
|
||||
public function apistatus() {
|
||||
$this->autoRender = false;
|
||||
$this->loadModel('Blocks');
|
||||
@@ -864,14 +879,14 @@ class MainController extends AppController {
|
||||
public function apiutxosupply() {
|
||||
$this->autoRender = false;
|
||||
$this->loadModel('Addresses');
|
||||
|
||||
|
||||
$circulating = 0;
|
||||
$reservedcommunity = 0;
|
||||
$reservedoperational = 0;
|
||||
$reservedinstitutional = 0;
|
||||
$reservedtotal = 0;
|
||||
$circulating = 0;
|
||||
|
||||
|
||||
$txoutsetinfo = $this->_gettxoutsetinfo();
|
||||
$reservedcommunity = $this->Addresses->find()->select(['Balance'])->where(['Address =' => 'rFLUohPG4tP3gZHYoyhvADCtrDMiaYb7Qd'])->first();
|
||||
$reservedoperational = $this->Addresses->find()->select(['Balance'])->where(['Address =' => 'r9PGXsejVJb9ZfMf3QVdDEJCzxkd9JLxzL'])->first();
|
||||
@@ -886,15 +901,15 @@ class MainController extends AppController {
|
||||
$this->Addresses->find()->select(['Balance'])->where(['Address =' => 'bZja2VyhAC84a9hMwT8dwTU6rDRXowrjxH'])->first() +
|
||||
$this->Addresses->find()->select(['Balance'])->where(['Address =' => 'bMvUBo1h5WS46ThHtmfmXftz3z33VHL7wc'])->first() +
|
||||
$this->Addresses->find()->select(['Balance'])->where(['Address =' => 'bMgqQqYfwzWWYBk5o5dBMXtCndVAoeqy6h'])->first();
|
||||
|
||||
|
||||
$reservedtotal = $reservedcommunity->Balance + $reservedoperational->Balance + $reservedinstitutional->Balance + $reservedaux->Balance;
|
||||
|
||||
|
||||
|
||||
|
||||
$circulating = $txoutsetinfo->total_amount - $reservedtotal;
|
||||
|
||||
|
||||
return $this->_jsonResponse(['success' => true, 'utxosupply' => ['total' => $txoutsetinfo->total_amount, 'circulating' => $circulating]]);
|
||||
}
|
||||
|
||||
|
||||
private static function curl_json_post($url, $data, $headers = []) {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
|
||||
@@ -4,12 +4,15 @@ namespace App\Shell;
|
||||
|
||||
use Cake\Console\ConsoleOutput;
|
||||
use Cake\Console\Shell;
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\ConnectionManager;
|
||||
use Cake\Log\Log;
|
||||
use Mdanter\Ecc\EccFactory;
|
||||
|
||||
class AuxShell extends Shell {
|
||||
|
||||
public static $rpcurl;
|
||||
|
||||
const bittrex = 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-LBC';
|
||||
|
||||
const blockchainticker = 'https://blockchain.info/ticker';
|
||||
@@ -20,12 +23,11 @@ class AuxShell extends Shell {
|
||||
|
||||
const scriptAddress = [5, 122];
|
||||
|
||||
const rpcurl = 'http://lrpc:lrpc@127.0.0.1:9245';
|
||||
|
||||
const tagrcptaddress = 'bLockNgmfvnnnZw7bM6SPz6hk5BVzhevEp';
|
||||
|
||||
public function initialize() {
|
||||
parent::initialize();
|
||||
self::$rpcurl = Configure::read('Lbry.RpcUrl');
|
||||
$this->loadModel('Addresses');
|
||||
$this->loadModel('Inputs');
|
||||
$this->loadModel('Outputs');
|
||||
@@ -126,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
|
||||
|
||||
+24
-20
@@ -4,24 +4,27 @@ namespace App\Shell;
|
||||
|
||||
use Cake\Console\ConsoleOutput;
|
||||
use Cake\Console\Shell;
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\ConnectionManager;
|
||||
use Cake\Log\Log;
|
||||
use Mdanter\Ecc\EccFactory;
|
||||
|
||||
class BlockShell extends Shell {
|
||||
|
||||
public static $rpcurl;
|
||||
|
||||
public static $redisurl;
|
||||
|
||||
const mempooltxkey = 'lbc.mempooltx';
|
||||
|
||||
const pubKeyAddress = [0, 85];
|
||||
|
||||
const scriptAddress = [5, 122];
|
||||
|
||||
const rpcurl = 'http://lrpc:lrpc@127.0.0.1:9245';
|
||||
|
||||
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');
|
||||
@@ -42,7 +45,7 @@ class BlockShell extends Shell {
|
||||
$txid = $otx->TransactionId;
|
||||
$tx = $this->Transactions->find()->select(['Hash'])->where(['Id' => $txid])->first();
|
||||
$req = ['method' => 'getrawtransaction', 'params' => [$tx->Hash]];
|
||||
$response = self::curl_json_post(self::rpcurl, json_encode($req));
|
||||
$response = self::curl_json_post(self::$rpcurl, json_encode($req));
|
||||
$json = json_decode($response);
|
||||
$tx_result = $json->result;
|
||||
$raw_tx = $tx_result;
|
||||
@@ -160,7 +163,7 @@ class BlockShell extends Shell {
|
||||
$req = ['method' => 'getvalueforname', 'params' => [$claim_name]];
|
||||
$json = null;
|
||||
try {
|
||||
$json = json_decode(self::curl_json_post(self::rpcurl, json_encode($req)));
|
||||
$json = json_decode(self::curl_json_post(self::$rpcurl, json_encode($req)));
|
||||
if (!$json) {
|
||||
echo "[$idx_str/$count] getvalueforname failed for [$out->Hash:$vout]. Skipping.\n";
|
||||
continue;
|
||||
@@ -295,7 +298,7 @@ class BlockShell extends Shell {
|
||||
$req = ['method' => 'getvalueforname', 'params' => [$claim_name]];
|
||||
$json = null;
|
||||
try {
|
||||
$json = json_decode(self::curl_json_post(self::rpcurl, json_encode($req)));
|
||||
$json = json_decode(self::curl_json_post(self::$rpcurl, json_encode($req)));
|
||||
if ($json) {
|
||||
$claim_data = [];
|
||||
$claim_id = $json->result->claimId;
|
||||
@@ -391,7 +394,7 @@ class BlockShell extends Shell {
|
||||
// getraw
|
||||
$req = ['method' => 'getrawtransaction', 'params' => [$tx->Hash]];
|
||||
$start_ms = round(microtime(true) * 1000);
|
||||
$response = self::curl_json_post(self::rpcurl, json_encode($req));
|
||||
$response = self::curl_json_post(self::$rpcurl, json_encode($req));
|
||||
$diff_ms = (round(microtime(true) * 1000)) - $start_ms;
|
||||
$total_diff += $diff_ms;
|
||||
echo "getrawtx took {$diff_ms}ms. ";
|
||||
@@ -673,7 +676,7 @@ class BlockShell extends Shell {
|
||||
private function processtx($tx_hash, $block_ts, $block_data, &$data_error) {
|
||||
// Get the raw transaction (Use getrawtx daemon instead (for speed!!!)
|
||||
$req = ['method' => 'getrawtransaction', 'params' => [$tx_hash]];
|
||||
$response = self::curl_json_post(self::rpcurl, json_encode($req));
|
||||
$response = self::curl_json_post(self::$rpcurl, json_encode($req));
|
||||
$json = json_decode($response);
|
||||
$tx_result = $json->result;
|
||||
$raw_tx = $tx_result;
|
||||
@@ -1075,12 +1078,13 @@ class BlockShell extends Shell {
|
||||
try {
|
||||
// Get the best block hash
|
||||
$req = ['method' => 'getbestblockhash', 'params' => []];
|
||||
$response = self::curl_json_post(self::rpcurl, json_encode($req));
|
||||
$response = self::curl_json_post(self::$rpcurl, json_encode($req));
|
||||
$json = json_decode($response);
|
||||
print_r($response); print_r($json);
|
||||
$best_hash = $json->result;
|
||||
|
||||
$req = ['method' => 'getblock', 'params' => [$best_hash]];
|
||||
$response = self::curl_json_post(self::rpcurl, json_encode($req));
|
||||
$response = self::curl_json_post(self::$rpcurl, json_encode($req));
|
||||
$json = json_decode($response);
|
||||
$best_block = $json->result;
|
||||
|
||||
@@ -1103,20 +1107,20 @@ class BlockShell extends Shell {
|
||||
for ($curr_height = $min_height; $curr_height <= $max_height; $curr_height++) {
|
||||
// get the block hash
|
||||
$req = ['method' => 'getblockhash', 'params' => [$curr_height]];
|
||||
$response = self::curl_json_post(self::rpcurl, json_encode($req));
|
||||
$response = self::curl_json_post(self::$rpcurl, json_encode($req));
|
||||
$json = json_decode($response);
|
||||
$curr_block_hash = $json->result;
|
||||
|
||||
$next_block_hash = null;
|
||||
if ($curr_height < $max_height) {
|
||||
$req = ['method' => 'getblockhash', 'params' => [$curr_height + 1]];
|
||||
$response = self::curl_json_post(self::rpcurl, json_encode($req));
|
||||
$response = self::curl_json_post(self::$rpcurl, json_encode($req));
|
||||
$json = json_decode($response);
|
||||
$next_block_hash = $json->result;
|
||||
}
|
||||
|
||||
$req = ['method' => 'getblock', 'params' => [$curr_block_hash]];
|
||||
$response = self::curl_json_post(self::rpcurl, json_encode($req));
|
||||
$response = self::curl_json_post(self::$rpcurl, json_encode($req));
|
||||
$json = json_decode($response);
|
||||
$curr_block = $json->result;
|
||||
|
||||
@@ -1127,7 +1131,7 @@ class BlockShell extends Shell {
|
||||
$next_block = null;
|
||||
if ($next_block_hash != null) {
|
||||
$req = ['method' => 'getblock', 'params' => [$next_block_hash]];
|
||||
$response = self::curl_json_post(self::rpcurl, json_encode($req));
|
||||
$response = self::curl_json_post(self::$rpcurl, json_encode($req));
|
||||
$json = json_decode($response);
|
||||
$next_block = $json->result;
|
||||
}
|
||||
@@ -1243,7 +1247,7 @@ class BlockShell extends Shell {
|
||||
while (true) {
|
||||
try {
|
||||
$data = ['method' => 'getrawmempool', 'params' => []];
|
||||
$res = self::curl_json_post(self::rpcurl, json_encode($data));
|
||||
$res = self::curl_json_post(self::$rpcurl, json_encode($data));
|
||||
$json = json_decode($res);
|
||||
$txs = $json->result;
|
||||
$now = new \DateTime('now', new \DateTimeZone('UTC'));
|
||||
@@ -1301,7 +1305,7 @@ class BlockShell extends Shell {
|
||||
} catch (\Exception $e) {
|
||||
// ignore possible disconnect errors
|
||||
}
|
||||
|
||||
|
||||
$conn->connect();
|
||||
}
|
||||
|
||||
@@ -1852,7 +1856,7 @@ class BlockShell extends Shell {
|
||||
// Other standard: pay to pubkey hash
|
||||
$define['p2pk'] = array('type' => 'pubkeyhash',
|
||||
'reqSigs' => 1,
|
||||
'data_index_for_hash' => 1);
|
||||
'data_index_for_hash' => 0);
|
||||
$rule['p2pk'] = [
|
||||
'0' => '/^[0-9a-f]+$/i',
|
||||
'1' => '/^OP_CHECKSIG/'
|
||||
@@ -2070,7 +2074,7 @@ class BlockShell extends Shell {
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -2200,4 +2204,4 @@ class BlockShell extends Shell {
|
||||
*/
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
@@ -412,7 +412,7 @@
|
||||
<tr>
|
||||
<td class="right"><a href="/blocks/<?php echo $block->Height ?>"><?php echo $block->Height ?></a></td>
|
||||
<td class="pad-left"><?php echo number_format($block->Difficulty, 8, '.', '') ?></td>
|
||||
<td class="right"><?php echo number_format($block->Confirmations, 0, '', ',') ?></td>
|
||||
<td class="right"><?php echo number_format((($currentBlock->Height - $block->Height) + 1), 0, '', ',') ?></td>
|
||||
<td class="right"><?php echo count(json_decode($block->TransactionHashes)) ?></td>
|
||||
<td class="right"><?php echo round($block->BlockSize / 1024, 2) . 'KB' ?></td>
|
||||
<td class="right pad-left"><?php echo $block->Nonce ?></td>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
*
|
||||
!*/
|
||||
!.git*
|
||||
|
||||
Reference in new issue
Block a user