Compare commits

..
22 Commits
Author SHA1 Message Date
Akinwale Ariwodola d426c1fd0c fix merge conflicts with master 2018-10-19 13:53:08 +02:00
Akinwale Ariwodola 2164abd52f Merge remote-tracking branch 'origin/master' into pr33 2018-10-19 13:51:51 +02:00
marcdeb1 c13c06f74f Claim LBRY link and Thumbnail (#32)
* Claim LBRY link and Thumbnail
* Added getLink function to Model
* Changed getLink function name
2018-10-19 12:49:22 +01:00
Akinwale Ariwodola ad82fc3975 Merge pull request #36 from marcdeb1/db_column_name
Changed LatestTransactionTime column name
2018-10-18 12:20:46 +01:00
marcdeb1 4d0efbaff8 Changed LatestTransactionTime column name 2018-10-11 07:42:46 +02:00
marcdeb1 07a0d0c0fe Added 'View' link next to Claim label 2018-10-11 07:20:53 +02:00
marcdeb1 c09da8ade8 Added claim link to transaction 2018-10-10 14:47:17 +02:00
marcdeb1 1a082dc794 Changed getLink function name 2018-10-10 14:41:45 +02:00
marcdeb1 69734f2add Changed getLink function name 2018-10-10 14:40:42 +02:00
marcdeb1 1505548a3a Added getLink function to Model 2018-10-10 13:25:48 +02:00
marcdeb1 0d1bd292fe Claim LBRY link and Thumbnail 2018-10-10 12:36:47 +02:00
Akinwale Ariwodola c8462afdee Update README.md with installation instructions (#30) 2018-08-09 21:30:21 +01:00
Akinwale Ariwodola a8a956f2bc update confirmations calculation on block list page 2018-07-26 12:22:51 +01:00
Akinwale Ariwodola b91b3681d3 tweak confirmation calculation 2018-07-26 12:14:48 +01:00
Akinwale Ariwodola 190d998e4c Merge branch 'master' of https://github.com/lbryio/block-explorer 2018-07-26 12:08:56 +01:00
Akinwale Ariwodola 667097f35d better confirmations calculation 2018-07-26 12:08:15 +01:00
Akinwale Ariwodola 8d552afe8f removed unused cron file 2018-07-26 10:30:13 +00:00
Akinwale Ariwodola ad4615cc5a forevermempool reset cron 2018-07-26 07:59:20 +01:00
Akinwale Ariwodola 3ad5db032b fix p2pk hash index 2018-07-26 07:27:12 +01:00
Akinwale Ariwodola e25cd7807e Merge pull request #26 from lbryio/diff
show diff on address page when tx spends back into the same wallet
2018-07-21 01:26:13 +01:00
Akinwale Ariwodola 71c7834521 move RPC URL value to configuration file 2018-07-21 00:18:24 +00:00
Akinwale Ariwodola 27ff22ff5a Updated mdanter/ecc version. Some cron file updates based on new environment. 2018-07-19 19:19:59 +00:00
29 changed files with 773 additions and 792 deletions

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
/vendor/*
/config/app.php
/tmp/*
/config/lbry.php
/logs/*
lbryexplorer.zip
lbryexplorer.komodoproject
+91
View File
@@ -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
View File
@@ -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
+551 -555
View File
File diff suppressed because it is too large. Load diff
+3
View File
@@ -220,3 +220,6 @@ Type::build('timestamp')
if (Configure::read('debug')) {
Plugin::load('DebugKit', ['bootstrap' => true]);
}
Configure::load('lbry');
+11
View File
@@ -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
View File
@@ -1,4 +1,4 @@
#!/bin/sh
cd /var/www/lbry.block.ng
cd /home/lbry/explorer.lbry.io
bin/cake block addrtxamounts
+3 -3
View File
@@ -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
-137
View File
@@ -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
View File
@@ -1,4 +1,4 @@
#!/bin/sh
cd /var/www/lbry.block.ng
cd /home/lbry/explorer.lbry.io
bin/cake block parsetxs
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/sh
cd /var/www/lbry.block.ng
cd /home/lbry/explorer.lbry.io
bin/cake block buildclaimindex
-3
View File
@@ -1,3 +0,0 @@
#!/bin/sh
cd /var/www/lbry.block.ng/cron
php -d extension=pthreads.so blockstuff.php
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/sh
cd /var/www/lbry.block.ng
cd /home/lbry/explorer.lbry.io
bin/cake block fixzerooutputs
+5
View File
@@ -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 &
-4
View File
@@ -1,4 +0,0 @@
#!/bin/sh
cd /var/www/lbry.block.ng
bin/cake block forevermempool &
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/sh
cd /var/www/lbry.block.ng
cd /home/lbry/explorer.lbry.io
bin/cake block parsemempool
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/sh
cd /var/www/lbry.block.ng
cd /home/lbry/explorer.lbry.io
bin/cake aux pricehistory
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/sh
cd /var/www/lbry.block.ng
cd /home/lbry/explorer.lbry.io
bin/cake block updatespends
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/sh
cd /var/www/lbry.block.ng
cd /home/lbry/explorer.lbry.io
bin/cake aux verifytags
+3 -3
View File
@@ -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;
@@ -163,11 +163,11 @@ CREATE TABLE `TransactionsAddresses`
`AddressId` BIGINT UNSIGNED NOT NULL,
`DebitAmount` DECIMAL(18,8) DEFAULT 0 NOT NULL COMMENT 'Sum of the inputs to this address for the tx',
`CreditAmount` DECIMAL(18,8) DEFAULT 0 NOT NULL COMMENT 'Sum of the outputs to this address for the tx',
`LatestTransactionTime` DATETIME DEFAULT UTC_TIMESTAMP() NOT NULL,
`TransactionTime` DATETIME DEFAULT UTC_TIMESTAMP() NOT NULL,
PRIMARY KEY `PK_TransactionAddress` (`TransactionId`, `AddressId`),
FOREIGN KEY `Idx_TransactionsAddressesTransaction` (`TransactionId`) REFERENCES `Transactions` (`Id`),
FOREIGN KEY `Idx_TransactionsAddressesAddress` (`AddressId`) REFERENCES `Addresses` (`Id`),
INDEX `Idx_TransactionsAddressesLatestTransactionTime` (`LatestTransactionTime`),
INDEX `Idx_TransactionsAddressesTransactionTime` (`TransactionTime`),
INDEX `Idx_TransactionsAddressesDebit` (`DebitAmount`),
INDEX `Idx_TransactionsAddressesCredit` (`CreditAmount`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;
+41 -22
View File
@@ -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)) {
@@ -446,6 +452,8 @@ class MainController extends AppController {
$this->loadModel('Transactions');
$this->loadModel('Inputs');
$this->loadModel('Outputs');
$this->loadModel('Claims');
$sourceAddress = $this->request->query('address');
$tx = $this->Transactions->find()->select(
@@ -460,13 +468,17 @@ 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++) {
$outputs[$i]->IsClaim = (strpos($outputs[$i]->ScriptPubKeyAsm, 'CLAIM') > -1);
$outputs[$i]->IsSupportClaim = (strpos($outputs[$i]->ScriptPubKeyAsm, 'SUPPORT_CLAIM') > -1);
$outputs[$i]->IsUpdateClaim = (strpos($outputs[$i]->ScriptPubKeyAsm, 'UPDATE_CLAIM') > -1);
$claim = $this->Claims->find()->where(['TransactionHash' => $tx->Hash, 'Vout' => $outputs[$i]->Vout])->first();
$outputs[$i]->Claim = $claim;
}
$totalIn = 0;
@@ -482,7 +494,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 +536,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 +565,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 +603,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 +688,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 +697,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 +710,7 @@ class MainController extends AppController {
return 'N/A';
}
}
public function apistatus() {
$this->autoRender = false;
$this->loadModel('Blocks');
@@ -864,14 +883,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 +905,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);
+13 -1
View File
@@ -5,7 +5,19 @@ namespace App\Model\Entity;
use Cake\ORM\Entity;
class Claim extends Entity {
function getLbryLink() {
$link = $this->Name;
if (isset($this->Publisher->Name)) {
$link = $this->Publisher->Name . '/' . $link;
}
$link = 'lbry://' . $link;
return $link;
}
function getExplorerLink() {
$link = '/claims/' . $this->ClaimId;
return $link;
}
}
?>
?>
+5 -3
View File
@@ -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
View File
@@ -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 {
*/
}
?>
?>
+1 -1
View File
@@ -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>
+6 -30
View File
@@ -40,14 +40,6 @@
$a = ['purple', 'orange', 'blue', 'teal', 'green', 'yellow'];
$autoThumbText = '';
$link = $claim->Name;
$rawLink = $claim->Name;
if (isset($claim->Publisher->Name)) {
$link = urlencode($claim->Publisher->Name) . '/' . $link;
$rawLink = $claim->Publisher->Name . '/' . $rawLink;
}
$link = 'lbry://' . $link;
$rawLink = 'lbry://' . $rawLink;
if ($claim->ClaimType == 1) { $autoThumbText = strtoupper(substr($claim->Name, 1, min( strlen($claim->Name), 10 ))); } else {
$str = str_replace(' ', '', (strlen(trim($claim->Title)) > 0) ? $claim->Title : $claim->Name);
$autoThumbText = strtoupper(mb_substr($str, 0, min( strlen($str), 10 )));
@@ -81,7 +73,7 @@ if (strlen(trim($desc)) == 0) {
<div class="claim-info">
<div data-autothumb="<?php echo $autoThumbText ?>" class="thumbnail <?php echo $a[mt_rand(0, count($a) - 1)] ?>">
<?php if (!$claim->IsNSFW && strlen(trim($claim->ThumbnailUrl)) > 0): ?>
<img src="<?php echo $claim->ThumbnailUrl ?>" alt="" />
<img src="<?php echo htmlspecialchars($claim->ThumbnailUrl) ?>" alt="" />
<?php else: ?>
<div class="autothumb"><?php echo $autoThumbText ?></div>
<?php endif; ?>
@@ -144,7 +136,7 @@ if (strlen(trim($desc)) == 0) {
<div class="value half-width"><?php echo strlen(trim($claim->Language)) > 0 ? ($claim->Language == 'en' ? 'English' : '') : '<em>Unspecified</em>' ?></div>
</div>
<?php endif; ?>
<a href="<?php echo $link ?>" class="open-lbry-link">Open in LBRY</a>
<a href="<?php echo $claim->getLbryLink() ?>" class="open-lbry-link">Open in LBRY</a>
</div>
<div class="clear"></div>
@@ -165,14 +157,6 @@ if (strlen(trim($desc)) == 0) {
}
$autoThumbText = '';
$link = $claim->Name;
$rawLink = $claim->Name;
if (isset($claim->Publisher->Name)) {
$link = urlencode($claim->Publisher->Name) . '/' . $link;
$rawLink = $claim->Publisher->Name . '/' . $rawLink;
}
$link = 'lbry://' . $link;
$rawLink = 'lbry://' . $rawLink;
$cost = '';
if (isset($claim->Price) && $claim->Price > 0) {
$cost = $this->Amount->formatCurrency($claim->Price) . ' LBC';
@@ -216,7 +200,7 @@ if (strlen(trim($desc)) == 0) {
<div data-autothumb="<?php echo $autoThumbText ?>" class="thumbnail <?php echo $a[mt_rand(0, count($a) - 1)] ?>">
<?php if (!$claim->IsNSFW && strlen(trim($claim->ThumbnailUrl)) > 0): ?>
<img src="<?php echo $claim->ThumbnailUrl ?>" alt="" />
<img src="<?php echo htmlspecialchars($claim->ThumbnailUrl) ?>" alt="" />
<?php else: ?>
<div class="autothumb"><?php echo $autoThumbText ?></div>
<?php endif; ?>
@@ -224,7 +208,7 @@ if (strlen(trim($desc)) == 0) {
<div class="metadata">
<div class="title" title="<?php echo $claim->ClaimType == 1 ? $claim->Name : ((strlen(trim($claim->Title)) > 0) ? $claim->Title : '') ?>"><?php echo $claim->ClaimType == 1 ? $claim->Name : ((strlen(trim($claim->Title)) > 0) ? $claim->Title : '<em>No Title</em>') ?></div>
<div class="link" title="<?php echo $rawLink ?>"><a href="<?php echo $link ?>" rel="nofollow"><?php echo $rawLink ?></a></div>
<div class="link" title="<?php echo $claim->getLbryLink() ?>"><a href="<?php echo $claim->getLbryLink() ?>" rel="nofollow"><?php echo $claim->getLbryLink() ?></a></div>
<div class="desc"><?php echo strlen(trim($claim->Description)) > 0 ? $claim->Description : '<em>No description available</em>' ?></div>
@@ -291,14 +275,6 @@ if (strlen(trim($desc)) == 0) {
$row++;
}
$autoThumbText = '';
$link = $claim->Name;
$rawLink = $claim->Name;
if (isset($claim->Publisher->Name)) {
$link = urlencode($claim->Publisher->Name) . '/' . $link;
$rawLink = $claim->Publisher->Name . '/' . $rawLink;
}
$link = 'lbry://' . $link;
$rawLink = 'lbry://' . $rawLink;
$cost = '';
if (isset($claim->Price) && $claim->Price > 0) {
$cost = $this->Amount->formatCurrency($claim->Price) . ' LBC';
@@ -342,7 +318,7 @@ if (strlen(trim($desc)) == 0) {
<div data-autothumb="<?php echo $autoThumbText ?>" class="thumbnail <?php echo $a[mt_rand(0, count($a) - 1)] ?>">
<?php if (!$claim->IsNSFW && strlen(trim($claim->ThumbnailUrl)) > 0): ?>
<img src="<?php echo $claim->ThumbnailUrl ?>" alt="" />
<img src="<?php echo htmlspecialchars($claim->ThumbnailUrl) ?>" alt="" />
<?php else: ?>
<div class="autothumb"><?php echo $autoThumbText ?></div>
<?php endif; ?>
@@ -350,7 +326,7 @@ if (strlen(trim($desc)) == 0) {
<div class="metadata">
<div class="title" title="<?php echo $claim->ClaimType == 1 ? $claim->Name : ((strlen(trim($claim->Title)) > 0) ? $claim->Title : '') ?>"><?php echo $claim->ClaimType == 1 ? $claim->Name : ((strlen(trim($claim->Title)) > 0) ? $claim->Title : '<em>No Title</em>') ?></div>
<div class="link" title="<?php echo $rawLink ?>"><a href="<?php echo $link ?>" rel="nofollow"><?php echo $rawLink ?></a></div>
<div class="link" title="<?php echo $claim->getLbryLink() ?>"><a href="<?php echo $claim->getLbryLink() ?>" rel="nofollow"><?php echo $claim->getLbryLink() ?></a></div>
<div class="desc"><?php echo strlen(trim($claim->Description)) > 0 ? $claim->Description : '<em>No description available</em>' ?></div>
+1
View File
@@ -136,6 +136,7 @@
foreach ($outputs as $out): ?>
<div id="output-<?php echo $out->Vout ?>" class="output <?php if (isset($out['OutputAddresses']) && count($out['OutputAddresses']) > 0 && $out['OutputAddresses'][0]->Address == $sourceAddress): ?>is-source<?php endif; ?>">
<div class="labels">
<?php if($out->IsClaim or $out->IsSupportClaim or $out->IsUpdateClaim): ?><a class="view-claim" href="<?php echo $out->Claim->getExplorerLink() ?>">View</a><?php endif; ?>
<?php if($out->IsSupportClaim): ?><div class="support">SUPPORT</div><?php endif; ?>
<?php if($out->IsUpdateClaim): ?><div class="update">UPDATE</div><?php endif; ?>
<?php if($out->IsClaim): ?><div class="claim">CLAIM</div><?php endif; ?>
+4
View File
@@ -0,0 +1,4 @@
*
!*/
!.git*
+1
View File
@@ -252,6 +252,7 @@ footer .content .page-time { position: absolute; right: 12px; bottom: 0px; paddi
.tx-details-layout .outputs .output .labels .support { background: #ffeb3b }
.tx-details-layout .outputs .output .labels .update { background: #ea80fc }
.tx-details-layout .outputs .output .labels .claim { background: #76ff03 }
.tx-details-layout .outputs .output .view-claim { font-size: 80%; }
.tx-details-layout .inputs .input .value, .tx-details-layout .outputs .output .value { font-weight: normal }
.tx-details-layout .inputs .input.is-source, .tx-details-layout .outputs .output.is-source { border-right-width: 18px; border-right-color: #1e88e5; background: #e3f2fd }
.tx-details-layout .inputs .input.highlighted, .tx-details-layout .outputs .output.highlighted { background: #f1f8e9 }