Compare commits
22
Commits
diff
..
hot-wallet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7c1e7299f | ||
|
|
9246952c08 | ||
|
|
59d23dc2a7 | ||
|
|
c58676cd69 | ||
|
|
b9917c89da | ||
|
|
26a79d8340 | ||
|
|
f903235c24 | ||
|
|
d8734c1b8e | ||
|
|
c13c06f74f | ||
|
|
ad82fc3975 | ||
|
|
4d0efbaff8 | ||
|
|
c8462afdee | ||
|
|
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
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017-2018 LBRY Inc
|
||||
Copyright (c) 2017-2018 LBRY Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@@ -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 configuration. 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 transaction 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
+551
-555
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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
@@ -496,12 +508,13 @@ class MainController extends AppController {
|
||||
$richList = $this->Addresses->find()->where(['Address <>' => 'bHW58d37s1hBjj3wPBkn5zpCX3F8ZW3uWf'])->order(['Balance' => 'DESC'])->limit(500)->toArray();
|
||||
|
||||
$priceRate = 0;
|
||||
$priceInfo = json_decode($this->redis->get(self::lbcPriceKey));
|
||||
//$priceInfo = json_decode($this->redis->get(self::lbcPriceKey));
|
||||
$priceInfo->price = 0.05;
|
||||
if (isset($priceInfo->price)) {
|
||||
$priceRate = $priceInfo->price;
|
||||
}
|
||||
|
||||
// calculate percentages
|
||||
|
||||
$lbryAddresses = ['rFLUohPG4tP3gZHYoyhvADCtrDMiaYb7Qd', 'r9PGXsejVJb9ZfMf3QVdDEJCzxkd9JLxzL', 'r9srwX7DEN7Mex3a8oR1mKSqQmLBizoJvi', 'bRo4FEeqqxY7nWFANsZsuKEWByEgkvz8Qt', 'bU2XUzckfpdEuQNemKvhPT1gexQ3GG3SC2', 'bay3VA6YTQBL4WLobbG7CthmoGeUKXuXkD', 'bLPbiXBp6Vr3NSnsHzDsLNzoy5o36re9Cz', 'bMvUBo1h5WS46ThHtmfmXftz3z33VHL7wc', 'bVUrbCK8hcZ5XWti7b9eNxKEBxzc1rr393', 'bZja2VyhAC84a9hMwT8dwTU6rDRXowrjxH', 'bMvUBo1h5WS46ThHtmfmXftz3z33VHL7wc', 'bMgqQqYfwzWWYBk5o5dBMXtCndVAoeqy6h', 'bMvUBo1h5WS46ThHtmfmXftz3z33VHL7wc'];
|
||||
$totalBalance = 0;
|
||||
$maxBalance = 0;
|
||||
$minBalance = 0;
|
||||
@@ -519,11 +532,13 @@ class MainController extends AppController {
|
||||
|
||||
$this->set('richList', $richList);
|
||||
$this->set('rate', $priceRate);
|
||||
$this->set('lbryAddresses', $lbryAddresses);
|
||||
}
|
||||
|
||||
public function address($addr = null) {
|
||||
set_time_limit(0);
|
||||
|
||||
$this->loadModel('Blocks');
|
||||
$this->loadModel('Addresses');
|
||||
$this->loadModel('Transactions');
|
||||
$this->loadModel('Inputs');
|
||||
@@ -552,7 +567,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 +605,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 +690,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 +699,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 +712,7 @@ class MainController extends AppController {
|
||||
return 'N/A';
|
||||
}
|
||||
}
|
||||
|
||||
public function apistatus() {
|
||||
$this->autoRender = false;
|
||||
$this->loadModel('Blocks');
|
||||
@@ -864,14 +885,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();
|
||||
@@ -885,16 +906,17 @@ class MainController extends AppController {
|
||||
$this->Addresses->find()->select(['Balance'])->where(['Address =' => 'bVUrbCK8hcZ5XWti7b9eNxKEBxzc1rr393'])->first() +
|
||||
$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 =' => 'bCrboXVztuSbZzVToCWSsu1pEr2oxKHu9v'])->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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
@@ -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 {
|
||||
*/
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
@@ -134,236 +134,7 @@
|
||||
<script type="text/javascript" src="/amcharts/amcharts.js"></script>
|
||||
<script type="text/javascript" src="/amcharts/serial.js"></script>
|
||||
<script type="text/javascript" src="/amcharts/plugins/export/export.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
var chart;
|
||||
var chartData = [];
|
||||
var chartLoadInProgress = false;
|
||||
var minPeriod = 'hh';
|
||||
var validPeriods = ['24h', '72h', '168h', '30d', '90d', '1y'];
|
||||
var defaultPeriod = (validPeriods.indexOf(localStorage.getItem('chartPeriod')) > -1) ? localStorage.getItem('chartPeriod') : '24h';
|
||||
var periodGridCounts = {'24h': 24, '72h': 24, '168h': 14, '30d': 30, '90d': 45, '1y': 12 };
|
||||
AmCharts.ready(function() {
|
||||
chart = AmCharts.makeChart('block-size-chart', {
|
||||
type: 'serial',
|
||||
theme: 'light',
|
||||
mouseWheelZoomEnabled: true,
|
||||
categoryField: 'date',
|
||||
synchronizeGrid: true,
|
||||
dataProvider: chartData,
|
||||
valueAxes: [
|
||||
{
|
||||
id: 'v-block-size',
|
||||
axisColor: '#1e88e5',
|
||||
axisThickness: 2,
|
||||
labelFunction: function(value) {
|
||||
return (Math.round((value / 1000) * 100)/100).toFixed(2) + ' KB';
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'v-price',
|
||||
axisColor: '#00e676',
|
||||
offset: 75,
|
||||
gridAlpha: 0,
|
||||
axisThickness: 2,
|
||||
labelFunction: function(value) {
|
||||
return '$' + value.toFixed(2);
|
||||
}
|
||||
}
|
||||
],
|
||||
categoryAxis: {
|
||||
parseDates: true,
|
||||
minPeriod: minPeriod, // DD for daily
|
||||
autoGridCount: false,
|
||||
minorGridEnabled: true,
|
||||
minorGridAlpha: 0.04,
|
||||
axisColor: '#dadada',
|
||||
twoLineMode: true,
|
||||
dateFormats: [{
|
||||
period: 'fff',
|
||||
format: 'JJ:NN:SS'
|
||||
}, {
|
||||
period: 'ss',
|
||||
format: 'JJ:NN:SS'
|
||||
}, {
|
||||
period: 'mm',
|
||||
format: 'JJ:NN'
|
||||
}, {
|
||||
period: 'hh',
|
||||
format: 'JJ:NN'
|
||||
}, {
|
||||
period: 'DD',
|
||||
format: 'DD'
|
||||
}, {
|
||||
period: 'WW',
|
||||
format: 'DD MMM'
|
||||
}, {
|
||||
period: 'MM',
|
||||
format: 'MMM'
|
||||
}, {
|
||||
period: 'YYYY',
|
||||
format: 'YYYY'
|
||||
}]
|
||||
},
|
||||
graphs: [
|
||||
{
|
||||
id: 'g-block-size',
|
||||
valueAxis: 'v-block-size', // we have to indicate which value axis should be used
|
||||
title: 'Avg Block Size',
|
||||
valueField: 'AvgBlockSize',
|
||||
bullet: 'round',
|
||||
bulletBorderThickness: 1,
|
||||
bulletBorderAlpha: 1,
|
||||
bulletColor: '#ffffff',
|
||||
bulletSize: 5,
|
||||
useLineColorForBulletBorder: true,
|
||||
lineColor: '#1e88e5',
|
||||
hideBulletsCount: 101,
|
||||
balloonText: '[[AvgBlockSize]] KB',
|
||||
switchable: false,
|
||||
balloonFunction: function(item, graph) {
|
||||
var result = graph.balloonText;
|
||||
return result.replace('[[AvgBlockSize]]', (Math.round((item.dataContext.AvgBlockSize / 1000) * 100)/100).toFixed(2));
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'g-price',
|
||||
valueAxis: 'v-price',
|
||||
title: 'Average Price',
|
||||
valueField: 'AvgUSD',
|
||||
bullet: 'round',
|
||||
bulletBorderThickness: 1,
|
||||
bulletBorderAlpha: 1,
|
||||
bulletColor: '#ffffff',
|
||||
bulletSize: 5,
|
||||
useLineColorForBulletBorder: true,
|
||||
lineColor: '#00e676',
|
||||
balloonText: '$[[AvgUSD]]',
|
||||
balloonFunction: function(item, graph) {
|
||||
var result = graph.balloonText;
|
||||
if (!item.dataContext.AvgUSD) {
|
||||
return '';
|
||||
}
|
||||
return result.replace('[[AvgUSD]]', item.dataContext.AvgUSD.toFixed(2));
|
||||
},
|
||||
hideBulletsCount: 101,
|
||||
labelFunction: function(value) {
|
||||
return '$' + value;
|
||||
},
|
||||
}
|
||||
],
|
||||
chartCursor: {
|
||||
cursorAlpha: 0.1,
|
||||
fullWidth: true,
|
||||
valueLineBalloonEnabled: true,
|
||||
categoryBalloonColor: '#333333',
|
||||
cursorColor: '#1e88e5',
|
||||
categoryBalloonDateFormat: minPeriod === 'hh' ? 'D MMM HH:NN ' : 'D MMM'
|
||||
},
|
||||
chartScrollbar: {
|
||||
scrollbarHeight: 36,
|
||||
color: '#888888',
|
||||
gridColor: '#bbbbbb'
|
||||
},
|
||||
legend: {
|
||||
marginLeft: 110,
|
||||
useGraphSettings: true,
|
||||
valueAlign: 'right',
|
||||
valueWidth: 60,
|
||||
spacing: 64,
|
||||
valueFunction: function(item, formatted) {
|
||||
if (item.dataContext) {
|
||||
var g = item.graph;
|
||||
if (g.id === 'g-block-size' && item.dataContext.AvgBlockSize > 0) {
|
||||
return g.balloonText.replace('[[AvgBlockSize]]', (Math.round((item.dataContext.AvgBlockSize / 1000) * 100)/100).toFixed(2) );
|
||||
}
|
||||
if (g.id === 'g-price' && item.dataContext.AvgUSD) {
|
||||
return g.balloonText.replace('[[AvgUSD]]', item.dataContext.AvgUSD.toFixed(2));
|
||||
}
|
||||
}
|
||||
|
||||
return formatted;
|
||||
}
|
||||
},
|
||||
export: {
|
||||
enabled: true,
|
||||
fileName: 'lbry-block-size-chart',
|
||||
position: 'bottom-right',
|
||||
divId: 'chart-export'
|
||||
}
|
||||
});
|
||||
|
||||
loadChartData(defaultPeriod);
|
||||
});
|
||||
|
||||
var loadChartData = function(dataPeriod) {
|
||||
var loadProgress = $('.block-size-chart-container .load-progress');
|
||||
// clear previous chart data
|
||||
$.ajax({
|
||||
url: '/api/v1/charts/blocksize/' + dataPeriod,
|
||||
type: 'get',
|
||||
dataType: 'json',
|
||||
beforeSend: function() {
|
||||
chartLoadInProgress = true;
|
||||
loadProgress.css({ display: 'block' });
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
chartData = [];
|
||||
var data = response.data;
|
||||
for (var period in data) {
|
||||
if (data.hasOwnProperty(period)) {
|
||||
chartData.push({
|
||||
date: Date.parse(period),
|
||||
AvgBlockSize: data[period].AvgBlockSize,
|
||||
AvgUSD: data[period].AvgUSD
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// save selcted period to localStorage
|
||||
localStorage.setItem('chartPeriod', dataPeriod);
|
||||
|
||||
if (chart) {
|
||||
var isHourly = (dataPeriod.indexOf('h') > -1);
|
||||
var gridCount = periodGridCounts[dataPeriod];
|
||||
chart.categoryAxis.minPeriod = isHourly ? 'hh' : 'DD';
|
||||
chart.categoryAxis.dateFormats[4].format = isHourly ? 'DD MMM' : 'DD';
|
||||
chart.chartCursor.categoryBalloonDateFormat = isHourly ? 'D MMM HH:NN ' : 'D MMM YYYY';
|
||||
chart.categoryAxis.gridCount = gridCount;
|
||||
chart.chartScrollbar.gridCount = gridCount;
|
||||
chart.dataProvider = chartData;
|
||||
chart.validateNow();
|
||||
chart.validateData();
|
||||
}
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
chartLoadInProgress = false;
|
||||
loadProgress.css({ display: 'none' });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
$('.block-size-data-links a').on('click', function(evt) {
|
||||
evt.preventDefault();
|
||||
if (chartLoadInProgress) {
|
||||
return;
|
||||
}
|
||||
|
||||
var link = $(this);
|
||||
if (link.hasClass('active')) {
|
||||
return;
|
||||
}
|
||||
|
||||
link.addClass('active').siblings().removeClass('active');
|
||||
var period = link.attr('data-period');
|
||||
loadChartData(period);
|
||||
});
|
||||
|
||||
$('a[data-period="' + defaultPeriod + '"]').addClass('active').siblings().removeClass('active');
|
||||
});
|
||||
</script>
|
||||
<script type="text/javascript" src="/js/block-size-chart.js"></script>
|
||||
<?php $this->end(); ?>
|
||||
|
||||
<div class="block-head">
|
||||
@@ -412,7 +183,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>
|
||||
|
||||
@@ -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,19 +1,34 @@
|
||||
<?php $this->assign('title', 'Stats & Rich List') ?>
|
||||
|
||||
<?php $this->start('script'); ?>
|
||||
<script type="text/javascript">
|
||||
|
||||
</script>
|
||||
<?php $this->end(); ?>
|
||||
|
||||
<?php echo $this->element('header') ?>
|
||||
|
||||
<?php $this->start('script'); ?>
|
||||
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
|
||||
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
|
||||
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
|
||||
<script src="https://www.amcharts.com/lib/3/plugins/responsive/responsive.min.js" type="text/javascript"></script>
|
||||
<script type="text/javascript" src="/js/mining-inflation-chart.js"></script>
|
||||
<?php $this->end(); ?>
|
||||
|
||||
<?php
|
||||
$this->start('css');
|
||||
echo $this->Html->css('/css/mining-inflation-chart.css');
|
||||
echo $this->Html->css('https://www.amcharts.com/lib/3/plugins/export/export.css');
|
||||
$this->end();
|
||||
?>
|
||||
<div class="stats-head">
|
||||
<h3>LBRY Stats</h3>
|
||||
</div>
|
||||
|
||||
<div class="stats-main">
|
||||
<div class="stats-main">
|
||||
|
||||
<div class="mining-inflation-chart-container">
|
||||
<div class="load-progress inc"></div>
|
||||
<h3>Mining Inflation Chart</h3>
|
||||
<div id="mining-inflation-chart" class="chart"></div>
|
||||
<div id="chart-export" class="btn-chart-export"></div>
|
||||
</div>
|
||||
|
||||
<div class="richlist">
|
||||
<h3>LBRY Rich List (Top 500)</h3>
|
||||
<table class="table">
|
||||
@@ -33,6 +48,11 @@
|
||||
<tr>
|
||||
<td class="right topvalign"><?php echo $rank ?></td>
|
||||
<td class="topvalign"><a href="/address/<?php echo $item->Address ?>" target="_blank"><?php echo $item->Address ?></a>
|
||||
<?php if(in_array($item->Address, $lbryAddresses)): ?>
|
||||
<span class="lbry-address">
|
||||
<img src="/img/lbry.png" height="18px" width="18px" title="Address owned by LBRY Inc."/>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($item->Tag) && strlen(trim($item->Tag)) > 0): ?>
|
||||
<div class="tag">
|
||||
<?php if (strlen(trim($item->TagUrl)) > 0): ?><a href="<?php echo $item->TagUrl ?>" target="_blank" rel="nofollow"><?php echo $tiem->Tag ?></a><?php else: echo $item->Tag; endif; ?>
|
||||
|
||||
@@ -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->Claim && ($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; ?>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
*
|
||||
!*/
|
||||
!.git*
|
||||
|
||||
@@ -5,7 +5,7 @@ Version: 1.1.2
|
||||
|
||||
## Description
|
||||
|
||||
Smoothly animates the `dataProvider`
|
||||
Smoothly animates the `dataProvider`.
|
||||
|
||||
It works with serial, pie, XY, funnel, and radar.
|
||||
|
||||
@@ -96,13 +96,13 @@ http://www.apache.org/licenses/LICENSE-2.0
|
||||
## Changelog
|
||||
|
||||
### 1.1.2
|
||||
* Fixing a bug with the minimum/maximum
|
||||
* Fixing a bug with the minimum/maximum.
|
||||
|
||||
### 1.1.1
|
||||
* It now automatically sets the minimum/maximum on the value axes while animating
|
||||
* It now automatically sets the minimum/maximum on the value axes while animating.
|
||||
|
||||
### 1.1.0
|
||||
* Adding in support for XY charts
|
||||
* Adding in support for XY charts.
|
||||
|
||||
### 1.0.0
|
||||
* Initial release
|
||||
* Initial release.
|
||||
@@ -5,28 +5,28 @@ Version: 1.0.16
|
||||
|
||||
## Description
|
||||
|
||||
By default all amCharts libraries accept data in JSON format. It needs to be
|
||||
By default, all amCharts libraries accept data in JSON format. It needs to be
|
||||
there when the web page loads, defined in-line or loaded via custom code.
|
||||
|
||||
This plugin introduces are native wrapper that enables automatic loading of data
|
||||
from external data data sources in CSV and JSON formats.
|
||||
This plugin introduces our native wrapper that enables automatic loading of data
|
||||
from external data sources in CSV and JSON formats.
|
||||
|
||||
Most of the times you will just need to provide a URL of the external data
|
||||
Most of the time, you will just need to provide a URL of the external data
|
||||
source - static file or dynamically generated - and it will do the rest.
|
||||
|
||||
|
||||
## Important notice
|
||||
|
||||
Due to security measures implemented in most of the browsers, the external data
|
||||
loader will work only when the page with the chart or map is loaded via web
|
||||
Due to security measures implemented in most of the browsers, the external data
|
||||
loader will work only when the page with the chart or map is loaded via web
|
||||
server.
|
||||
|
||||
So, any of the examples loaded locally (file:///) will not work.
|
||||
|
||||
The page needs to be loaded via web server (http://) in order to work properly.
|
||||
|
||||
Loading data from another domain than the web page is loaded is possible but is
|
||||
a subject for `Access-Control-Allow-Origin` policies defined by the web server
|
||||
Loading data from another domain than the web page is loaded is possible, but is
|
||||
a subject for `Access-Control-Allow-Origin` policies defined by the web server
|
||||
you are loading data from.
|
||||
|
||||
For more about loading data across domains use the following thread:
|
||||
@@ -75,10 +75,10 @@ AmCharts.makeChart( "chartdiv", {
|
||||
} );
|
||||
```
|
||||
|
||||
That's it. The plugin will make sure the files are loaded and dataProvider is
|
||||
That's it. The plugin will make sure the files are loaded and dataProvider is
|
||||
populated with their content *before* the chart is built.
|
||||
|
||||
Some formats, like CSV, will require additional parameters needed to parse the
|
||||
Some formats like CSV, will require additional parameters needed to parse the
|
||||
data, such as "separator".
|
||||
|
||||
If the "format" is omitted, the plugin will assume JSON.
|
||||
@@ -104,33 +104,33 @@ chart["dataLoader"] = {
|
||||
|
||||
Property | Default | Description
|
||||
-------- | ------- | -----------
|
||||
async | true | If set to false (not recommended) everything will wait until data is fully loaded
|
||||
complete | | Callback function to execute when loader is done
|
||||
delimiter | , | [CSV only] a delimiter for columns (use \t for tab delimiters)
|
||||
emptyAs | undefined | [CSV only] replace empty columns with whatever is set here
|
||||
error | | Callback function to execute if file load fails
|
||||
init | | Callback function to execute when Data Loader is initialized, before any loading starts
|
||||
format | json | Type of data: json, csv
|
||||
headers | | An array of objects with two properties (key and value) to attach to HTTP request
|
||||
load | | Callback function to execute when file is successfully loaded (might be invoked multiple times)
|
||||
noStyles | false | If set to true no styles will be applied to "Data loading" curtain
|
||||
numberFields | | [CSV only] An array of fields in data to treat as numbers
|
||||
postProcess | | If set to function reference, that function will be called to "post-process" loaded data before passing it on to chart. The handler function will receive two parameters: loaded data, Data Loader options
|
||||
async | true | If set to false (not recommended), everything will wait until data is fully loaded.
|
||||
complete | | Callback function to execute when loader is done.
|
||||
delimiter | , | [CSV only] a delimiter for columns (use \t for tab delimiters).
|
||||
emptyAs | undefined | [CSV only] replace empty columns with whatever is set here.
|
||||
error | | Callback function to execute if file load fails.
|
||||
init | | Callback function to execute when Data Loader is initialized, before any loading starts.
|
||||
format | json | Type of data: json, csv.
|
||||
headers | | An array of objects with two properties (key and value) to attach to HTTP request.
|
||||
load | | Callback function to execute when file is successfully loaded (might be invoked multiple times).
|
||||
noStyles | false | If set to true, no styles will be applied to "Data loading" curtain.
|
||||
numberFields | | [CSV only] An array of fields in data to treat as numbers.
|
||||
postProcess | | If set to function reference, that function will be called to "post-process" loaded data before passing it on to chart. The handler function will receive two parameters: loaded data, Data Loader options.
|
||||
progress | | Set this to function reference to track progress of the load. The function will be passed in three parameters: global progress, individual file progress, file URL.
|
||||
showErrors | true | Show loading errors in a chart curtain
|
||||
showCurtain | true| Show curtain over the chart area when loading data
|
||||
reload | 0 | Reload data every X seconds
|
||||
reverse | false | [CSV only] add data points in revers order
|
||||
skip | 0 | [CSV only] skip X first rows in data (includes first row if useColumnNames is used)
|
||||
skipEmpty | true | [CSV only] Ignore empty lines in data
|
||||
timestamp | false | Add current timestamp to data URLs (to avoid caching)
|
||||
useColumnNames | false | [CSV only] Use first row in data as column names when parsing
|
||||
showErrors | true | Show loading errors in a chart curtain.
|
||||
showCurtain | true| Show curtain over the chart area when loading data.
|
||||
reload | 0 | Reload data every X seconds.
|
||||
reverse | false | [CSV only] add data points in revers order.
|
||||
skip | 0 | [CSV only] skip X first rows in data (includes first row if useColumnNames is used).
|
||||
skipEmpty | true | [CSV only] Ignore empty lines in data.
|
||||
timestamp | false | Add current timestamp to data URLs (to avoid caching).
|
||||
useColumnNames | false | [CSV only] Use first row in data as column names when parsing.
|
||||
|
||||
|
||||
## Using in JavaScript Stock Chart
|
||||
|
||||
In JavaScript Stock Chart it works exactly the same as in other chart types,
|
||||
with the exception that `dataLoader` is set as a property to the data set
|
||||
In JavaScript Stock Chart, it works exactly the same as in other chart types,
|
||||
with the exception that `dataLoader` is set as a property to the data set
|
||||
definition. I.e.:
|
||||
|
||||
```
|
||||
@@ -174,7 +174,7 @@ var chart = AmCharts.makeChart("chartdiv", {
|
||||
|
||||
### Can I also load event data the same way?
|
||||
|
||||
Sure. You just add a `eventDataLoader` object to your data set. All the same
|
||||
Sure. You just add a `eventDataLoader` object to your data set. All the same
|
||||
settings apply.
|
||||
|
||||
|
||||
@@ -251,9 +251,9 @@ The three available functions are as follows:
|
||||
|
||||
Function | Parameters | Description
|
||||
-------- | ---------- | -----------
|
||||
AmCharts.loadFile() | url, options, callback | Loads the file and passes it into callback function (unparsed)
|
||||
AmCharts.parseCSV() | data, options | Parses data in string CSV format and returns JavaScript Array
|
||||
AmCharts.parseJSON() | data | Parses data in string JSON format and returns JavaScript Array
|
||||
AmCharts.loadFile() | url, options, callback | Loads the file and passes it into callback function (unparsed).
|
||||
AmCharts.parseCSV() | data, options | Parses data in string CSV format and returns JavaScript Array.
|
||||
AmCharts.parseJSON() | data | Parses data in string JSON format and returns JavaScript Array.
|
||||
|
||||
The options passed into standalone functions are the same as discussed in [Complete list of available dataLoader settings](#complete-list-of-available-dataloader-settings) chapter.
|
||||
|
||||
@@ -280,16 +280,16 @@ AmCharts.loadFile(dataset_url, {}, function(data) {
|
||||
|
||||
## Translating into other languages
|
||||
|
||||
Depending on configuration options the plugin will display a small number of
|
||||
Depending on configuration options, the plugin will display a small number of
|
||||
text prompts, like 'Data loading...'.
|
||||
|
||||
Plugin will try matching chart's `language` property and display text prompts in
|
||||
Plugin will try matching chart's `language` property and display text prompts in
|
||||
a corresponding language. For that the plugin needs to have the translations.
|
||||
|
||||
Some of the plugin translations are in **lang** subdirectory. Simply include the
|
||||
Some of the plugin translations are in **lang** subdirectory. Simply include the
|
||||
one you need.
|
||||
|
||||
If there is no translation to your language readily available, just grab en.js,
|
||||
If there is no translation to your language readily available, just grab en.js,
|
||||
copy it and translate.
|
||||
|
||||
The structure is simple:
|
||||
@@ -302,7 +302,7 @@ The phrase in English must be left intact.
|
||||
|
||||
When you're done, you can include your language as a JavaScript file.
|
||||
|
||||
P.S. send us your translation so we can include it for the benefits of other
|
||||
P.S. send us your translation so we can include it for the benefits of other
|
||||
users. Thanks!
|
||||
|
||||
|
||||
@@ -354,72 +354,72 @@ http://www.apache.org/licenses/LICENSE-2.0
|
||||
## Changelog
|
||||
|
||||
### 1.0.16
|
||||
* Added "numberFields" config array
|
||||
* Added "numberFields" config array.
|
||||
|
||||
### 1.0.15
|
||||
* Added "emptyAs" config property. Empty CSV values will be set to this (default `undefined`)
|
||||
* Added "emptyAs" config property. Empty CSV values will be set to this (default `undefined`).
|
||||
|
||||
### 1.0.14
|
||||
* Added "init" event handler, which is called **before** loading starts
|
||||
* Added "init" event handler, which is called **before** loading starts.
|
||||
|
||||
### 1.0.13
|
||||
* Added "progress" handler, which can be used to monitor data load progress
|
||||
* Added "progress" handler, which can be used to monitor data load progress.
|
||||
|
||||
### 1.0.12
|
||||
* Better default options handling in external calls to AmCharts.loadFile
|
||||
* Fixed the latest version of Stock Chart not resetting to default pre-defined period
|
||||
* New example: Using Data Loader functions externally (map_json_external_function.html)
|
||||
* Better default options handling in external calls to AmCharts.loadFile.
|
||||
* Fixed the latest version of Stock Chart not resetting to default pre-defined period.
|
||||
* New example: Using Data Loader functions externally (map_json_external_function.html).
|
||||
|
||||
### 1.0.11
|
||||
* New translation: Added French translation. Thanks Remy!
|
||||
* Tweaks to allow better animation after data load on Pie chart
|
||||
* Tweaks to allow better animation after data load on Pie chart.
|
||||
|
||||
### 1.0.10
|
||||
* Fixed error related to headers not being set when using standalone data load functions
|
||||
* Fixed error related to headers not being set when using standalone data load functions.
|
||||
|
||||
### 1.0.9
|
||||
* Plugin will now ignore empty CSV lines by default (configurable with `skipEmpty` property)
|
||||
* Plugin will now ignore empty CSV lines by default (configurable with `skipEmpty` property).
|
||||
|
||||
### 1.0.8
|
||||
* Added `headers` config variable which allows adding custom headers to HTTP requests
|
||||
* Added `headers` config variable which allows adding custom headers to HTTP requests.
|
||||
|
||||
### 1.0.7
|
||||
* Fixed an issue with the Pie chart when it is being loaded in inactive tab
|
||||
* Fixed an issue with the Pie chart when it is being loaded in inactive tab.
|
||||
|
||||
### 1.0.6
|
||||
* Added support for Gauge chart (loads `arrows` array)
|
||||
* Added support for Gauge chart (loads `arrows` array).
|
||||
|
||||
### 1.0.5
|
||||
* Fixed JS error if periodSelector was not defined in chart config
|
||||
* Now all callback functions (complete, error, load) receive additional parameter: chart
|
||||
* postProcess function will now have "this" context set to Data Loader object as well as receive chart reference as third paramater
|
||||
* Fixed JS error if periodSelector was not defined in chart config.
|
||||
* Now all callback functions (complete, error, load) receive additional parameter: chart.
|
||||
* postProcess function will now have "this" context set to Data Loader object as well as receive chart reference as third parameter.
|
||||
|
||||
### 1.0.4
|
||||
* Added `chart.dataLoader.loadData()` function which can be used to manually trigger all data reload
|
||||
* Added `chart.dataLoader.loadData()` function which can be used to manually trigger all data reload.
|
||||
|
||||
### 1.0.3
|
||||
* Fixed the bug where defaults were not being applied properly
|
||||
* Fixed the bug with translations not being applied properly
|
||||
* Cleaned up the code (to pass JSHint validation)
|
||||
* Fixed the bug where defaults were not being applied properly.
|
||||
* Fixed the bug with translations not being applied properly.
|
||||
* Cleaned up the code (to pass JSHint validation).
|
||||
|
||||
### 1.0.2
|
||||
* Fixed the issue with modified Array prototypes
|
||||
* Fixed the issue with modified Array prototypes.
|
||||
|
||||
### 1.0.1
|
||||
* Added `complete`, `load` and `error` properties that can be set with function handlers to be invoked on load completion, successful file load or failed load respectively
|
||||
* Fixed language container initialization bug
|
||||
* Fixed bug that was causing parse errors not be displayed
|
||||
* Added `complete`, `load` and `error` properties that can be set with function handlers to be invoked on load completion, successful file load or failed load respectively.
|
||||
* Fixed language container initialization bug.
|
||||
* Fixed bug that was causing parse errors not be displayed.
|
||||
|
||||
### 1.0
|
||||
* Added GANTT chart support
|
||||
* Added GANTT chart support.
|
||||
|
||||
### 0.9.2
|
||||
* Added global data load methods that can be used to load and parse data by code outside plugin
|
||||
* Trim CSV column names
|
||||
* Translation added: Lithuanian
|
||||
* Added global data load methods that can be used to load and parse data by code outside plugin.
|
||||
* Trim CSV column names.
|
||||
* Translation added: Lithuanian.
|
||||
|
||||
### 0.9.1
|
||||
* Fix chart animations not playing after asynchronous load
|
||||
* Fix chart animations not playing after asynchronous load.
|
||||
|
||||
### 0.9
|
||||
* Initial release
|
||||
* Initial release.
|
||||
File diff suppressed because it is too large.
Load diff
@@ -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 }
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
.mining-inflation-chart-container { width: 1200px; margin: 0 auto 48px auto; box-shadow: 0 2px 6px rgba(0,0,0,.175); border: 1px solid rgba(0,0,0,.15); padding: 24px 36px; position: relative; overflow: hidden }
|
||||
.mining-inflation-chart-container .load-progress { position: absolute; top: 0; left: 0; width: 100%; height: 3px; background: #1e88e5; animation: indeterminate 4s linear infinite; }
|
||||
.mining-inflation-chart-container .chart { height: 414px }
|
||||
.mining-inflation-chart-container .btn-chart-export { position: absolute; right: 40px; bottom: 36px }
|
||||
@keyframes indeterminate {
|
||||
from { left: -70%; }
|
||||
to { left: 100% }
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
@@ -0,0 +1,228 @@
|
||||
var chart;
|
||||
var chartData = [];
|
||||
var chartLoadInProgress = false;
|
||||
var minPeriod = 'hh';
|
||||
var validPeriods = ['24h', '72h', '168h', '30d', '90d', '1y'];
|
||||
var defaultPeriod = (validPeriods.indexOf(localStorage.getItem('chartPeriod')) > -1) ? localStorage.getItem('chartPeriod') : '24h';
|
||||
var periodGridCounts = {'24h': 24, '72h': 24, '168h': 14, '30d': 30, '90d': 45, '1y': 12 };
|
||||
AmCharts.ready(function() {
|
||||
chart = AmCharts.makeChart('block-size-chart', {
|
||||
type: 'serial',
|
||||
theme: 'light',
|
||||
mouseWheelZoomEnabled: true,
|
||||
categoryField: 'date',
|
||||
synchronizeGrid: true,
|
||||
dataProvider: chartData,
|
||||
valueAxes: [
|
||||
{
|
||||
id: 'v-block-size',
|
||||
axisColor: '#1e88e5',
|
||||
axisThickness: 2,
|
||||
labelFunction: function(value) {
|
||||
return (Math.round((value / 1000) * 100)/100).toFixed(2) + ' KB';
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'v-price',
|
||||
axisColor: '#00e676',
|
||||
offset: 75,
|
||||
gridAlpha: 0,
|
||||
axisThickness: 2,
|
||||
labelFunction: function(value) {
|
||||
return '$' + value.toFixed(2);
|
||||
}
|
||||
}
|
||||
],
|
||||
categoryAxis: {
|
||||
parseDates: true,
|
||||
minPeriod: minPeriod, // DD for daily
|
||||
autoGridCount: false,
|
||||
minorGridEnabled: true,
|
||||
minorGridAlpha: 0.04,
|
||||
axisColor: '#dadada',
|
||||
twoLineMode: true,
|
||||
dateFormats: [{
|
||||
period: 'fff',
|
||||
format: 'JJ:NN:SS'
|
||||
}, {
|
||||
period: 'ss',
|
||||
format: 'JJ:NN:SS'
|
||||
}, {
|
||||
period: 'mm',
|
||||
format: 'JJ:NN'
|
||||
}, {
|
||||
period: 'hh',
|
||||
format: 'JJ:NN'
|
||||
}, {
|
||||
period: 'DD',
|
||||
format: 'DD'
|
||||
}, {
|
||||
period: 'WW',
|
||||
format: 'DD MMM'
|
||||
}, {
|
||||
period: 'MM',
|
||||
format: 'MMM'
|
||||
}, {
|
||||
period: 'YYYY',
|
||||
format: 'YYYY'
|
||||
}]
|
||||
},
|
||||
graphs: [
|
||||
{
|
||||
id: 'g-block-size',
|
||||
valueAxis: 'v-block-size', // we have to indicate which value axis should be used
|
||||
title: 'Avg Block Size',
|
||||
valueField: 'AvgBlockSize',
|
||||
bullet: 'round',
|
||||
bulletBorderThickness: 1,
|
||||
bulletBorderAlpha: 1,
|
||||
bulletColor: '#ffffff',
|
||||
bulletSize: 5,
|
||||
useLineColorForBulletBorder: true,
|
||||
lineColor: '#1e88e5',
|
||||
hideBulletsCount: 101,
|
||||
balloonText: '[[AvgBlockSize]] KB',
|
||||
switchable: false,
|
||||
balloonFunction: function(item, graph) {
|
||||
var result = graph.balloonText;
|
||||
return result.replace('[[AvgBlockSize]]', (Math.round((item.dataContext.AvgBlockSize / 1000) * 100)/100).toFixed(2));
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'g-price',
|
||||
valueAxis: 'v-price',
|
||||
title: 'Average Price',
|
||||
valueField: 'AvgUSD',
|
||||
bullet: 'round',
|
||||
bulletBorderThickness: 1,
|
||||
bulletBorderAlpha: 1,
|
||||
bulletColor: '#ffffff',
|
||||
bulletSize: 5,
|
||||
useLineColorForBulletBorder: true,
|
||||
lineColor: '#00e676',
|
||||
balloonText: '$[[AvgUSD]]',
|
||||
balloonFunction: function(item, graph) {
|
||||
var result = graph.balloonText;
|
||||
if (!item.dataContext.AvgUSD) {
|
||||
return '';
|
||||
}
|
||||
return result.replace('[[AvgUSD]]', item.dataContext.AvgUSD.toFixed(2));
|
||||
},
|
||||
hideBulletsCount: 101,
|
||||
labelFunction: function(value) {
|
||||
return '$' + value;
|
||||
},
|
||||
}
|
||||
],
|
||||
chartCursor: {
|
||||
cursorAlpha: 0.1,
|
||||
fullWidth: true,
|
||||
valueLineBalloonEnabled: true,
|
||||
categoryBalloonColor: '#333333',
|
||||
cursorColor: '#1e88e5',
|
||||
categoryBalloonDateFormat: minPeriod === 'hh' ? 'D MMM HH:NN ' : 'D MMM'
|
||||
},
|
||||
chartScrollbar: {
|
||||
scrollbarHeight: 36,
|
||||
color: '#888888',
|
||||
gridColor: '#bbbbbb'
|
||||
},
|
||||
legend: {
|
||||
marginLeft: 110,
|
||||
useGraphSettings: true,
|
||||
valueAlign: 'right',
|
||||
valueWidth: 60,
|
||||
spacing: 64,
|
||||
valueFunction: function(item, formatted) {
|
||||
if (item.dataContext) {
|
||||
var g = item.graph;
|
||||
if (g.id === 'g-block-size' && item.dataContext.AvgBlockSize > 0) {
|
||||
return g.balloonText.replace('[[AvgBlockSize]]', (Math.round((item.dataContext.AvgBlockSize / 1000) * 100)/100).toFixed(2) );
|
||||
}
|
||||
if (g.id === 'g-price' && item.dataContext.AvgUSD) {
|
||||
return g.balloonText.replace('[[AvgUSD]]', item.dataContext.AvgUSD.toFixed(2));
|
||||
}
|
||||
}
|
||||
|
||||
return formatted;
|
||||
}
|
||||
},
|
||||
export: {
|
||||
enabled: true,
|
||||
fileName: 'lbry-block-size-chart',
|
||||
position: 'bottom-right',
|
||||
divId: 'chart-export'
|
||||
}
|
||||
});
|
||||
|
||||
loadChartData(defaultPeriod);
|
||||
});
|
||||
|
||||
var loadChartData = function(dataPeriod) {
|
||||
var loadProgress = $('.block-size-chart-container .load-progress');
|
||||
// clear previous chart data
|
||||
$.ajax({
|
||||
url: '/api/v1/charts/blocksize/' + dataPeriod,
|
||||
type: 'get',
|
||||
dataType: 'json',
|
||||
beforeSend: function() {
|
||||
chartLoadInProgress = true;
|
||||
loadProgress.css({ display: 'block' });
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
chartData = [];
|
||||
var data = response.data;
|
||||
for (var period in data) {
|
||||
if (data.hasOwnProperty(period)) {
|
||||
chartData.push({
|
||||
date: Date.parse(period),
|
||||
AvgBlockSize: data[period].AvgBlockSize,
|
||||
AvgUSD: data[period].AvgUSD
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// save selcted period to localStorage
|
||||
localStorage.setItem('chartPeriod', dataPeriod);
|
||||
|
||||
if (chart) {
|
||||
var isHourly = (dataPeriod.indexOf('h') > -1);
|
||||
var gridCount = periodGridCounts[dataPeriod];
|
||||
chart.categoryAxis.minPeriod = isHourly ? 'hh' : 'DD';
|
||||
chart.categoryAxis.dateFormats[4].format = isHourly ? 'DD MMM' : 'DD';
|
||||
chart.chartCursor.categoryBalloonDateFormat = isHourly ? 'D MMM HH:NN ' : 'D MMM YYYY';
|
||||
chart.categoryAxis.gridCount = gridCount;
|
||||
chart.chartScrollbar.gridCount = gridCount;
|
||||
chart.dataProvider = chartData;
|
||||
chart.validateNow();
|
||||
chart.validateData();
|
||||
}
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
chartLoadInProgress = false;
|
||||
loadProgress.css({ display: 'none' });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
$('.block-size-data-links a').on('click', function(evt) {
|
||||
evt.preventDefault();
|
||||
if (chartLoadInProgress) {
|
||||
return;
|
||||
}
|
||||
|
||||
var link = $(this);
|
||||
if (link.hasClass('active')) {
|
||||
return;
|
||||
}
|
||||
|
||||
link.addClass('active').siblings().removeClass('active');
|
||||
var period = link.attr('data-period');
|
||||
loadChartData(period);
|
||||
});
|
||||
|
||||
$('a[data-period="' + defaultPeriod + '"]').addClass('active').siblings().removeClass('active');
|
||||
});
|
||||
@@ -0,0 +1,265 @@
|
||||
function getReward(blockHeight) {
|
||||
if (blockHeight == 0) {
|
||||
return 400000000;
|
||||
}
|
||||
else if (blockHeight <= 5100) {
|
||||
return 1;
|
||||
}
|
||||
else if (blockHeight <= 55000) {
|
||||
return 1 + Math.floor((blockHeight - 5001) / 100);
|
||||
}
|
||||
else {
|
||||
var level = Math.floor((blockHeight - 55001) / 32);
|
||||
var reduction = Math.floor((Math.floor(Math.sqrt((8 * level) + 1)) - 1) / 2);
|
||||
while(!(withinLevelBounds(reduction, level))) {
|
||||
if(Math.floor((reduction * reduction + reduction) / 2) > level) {
|
||||
reduction--;
|
||||
}
|
||||
else {
|
||||
reduction++;
|
||||
}
|
||||
}
|
||||
return Math.max(0, 500 - reduction);
|
||||
}
|
||||
}
|
||||
|
||||
function withinLevelBounds(reduction, level) {
|
||||
if(Math.floor((reduction * reduction + reduction) / 2) > level) {
|
||||
return false;
|
||||
}
|
||||
reduction += 1;
|
||||
if(Math.floor((reduction * reduction + reduction) / 2) <= level) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function getAverageBlockTime(blocks) {
|
||||
var numBlocks = blocks.length;
|
||||
var windowSize = 100;
|
||||
var sum = 0;
|
||||
for(i = numBlocks - windowSize; i < numBlocks; i++) {
|
||||
sum += blocks[i].block_time - blocks[i-1].block_time;
|
||||
}
|
||||
return sum / windowSize;
|
||||
}
|
||||
|
||||
function buildChartData(blockData) {
|
||||
var chartData = [];
|
||||
var supply = 0;
|
||||
var reward = 0;
|
||||
var averageBlockTime = getAverageBlockTime(blockData);
|
||||
var blockTime = 0;
|
||||
var lastBlock = 4071017; // Last block with reward
|
||||
var skip = 100;
|
||||
var blocksPerYear = Math.floor((3600*24*365) / averageBlockTime);
|
||||
var historicalSupply = {};
|
||||
var lastYearSupply = 0;
|
||||
var lastYearBlock = 0;
|
||||
var inflationRate = 0;
|
||||
for(var i = 0; i < lastBlock; i++) {
|
||||
reward = getReward(i);
|
||||
supply += reward;
|
||||
historicalSupply[i + 1] = supply;
|
||||
if(i == 0) { // Reward for 1st block set to 0 for scale
|
||||
reward = 0;
|
||||
}
|
||||
if(i < blockData.length) {
|
||||
// Historical Data
|
||||
var b = blockData[i];
|
||||
blockTime = b.block_time;
|
||||
}
|
||||
else {
|
||||
// Future blocks
|
||||
skip = 1000;
|
||||
blockTime += averageBlockTime;
|
||||
}
|
||||
// Inflation Rate
|
||||
if(i + 1 - blocksPerYear <= 0) {
|
||||
lastYearBlock = 1;
|
||||
}
|
||||
else {
|
||||
lastYearBlock = i + 1 - blocksPerYear;
|
||||
}
|
||||
lastYearSupply = historicalSupply[lastYearBlock];
|
||||
inflationRate = ((supply - lastYearSupply) / lastYearSupply) * 100;
|
||||
if(i % skip == 0) { // Only push 1/<skip> of all blocks to optimize data loading
|
||||
chartData.push({
|
||||
date: new Date(blockTime * 1000),
|
||||
date: new Date(blockTime * 1000),
|
||||
AvailableSupply: supply,
|
||||
RewardLBC: reward,
|
||||
InflationRate: inflationRate,
|
||||
BlockId: i + 1
|
||||
});
|
||||
}
|
||||
}
|
||||
return chartData;
|
||||
}
|
||||
|
||||
function loadChartData() {
|
||||
var api_url = "https://chainquery.lbry.io/api/sql?query=";
|
||||
var query = "SELECT id, block_time FROM block";
|
||||
var url = api_url + query;
|
||||
var loadProgress = $('.mining-inflation-chart-container .load-progress');
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'get',
|
||||
dataType: 'json',
|
||||
beforeSend: function() {
|
||||
chartLoadInProgress = true;
|
||||
loadProgress.css({ display: 'block' });
|
||||
},
|
||||
success: function(response) {
|
||||
if(response.success) {
|
||||
chartData = buildChartData(response.data);
|
||||
if(chart) {
|
||||
chart.dataProvider = chartData;
|
||||
chart.validateNow();
|
||||
chart.validateData();
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log("Could not fetch block data.");
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
chartLoadInProgress = false;
|
||||
loadProgress.css({ display: 'none' });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var chart;
|
||||
var chartData = [];
|
||||
var chartLoadInProgress = false;
|
||||
AmCharts.ready(function() {
|
||||
chart = AmCharts.makeChart('mining-inflation-chart', {
|
||||
type: 'serial',
|
||||
theme: 'light',
|
||||
mouseWheelZoomEnabled: true,
|
||||
height: '100%',
|
||||
categoryField: 'date',
|
||||
synchronizeGrid: true,
|
||||
dataProvider: chartData,
|
||||
responsive: {
|
||||
enabled: true,
|
||||
},
|
||||
valueAxes: [
|
||||
{
|
||||
id: 'v-supply',
|
||||
axisColor: '#1e88e5',
|
||||
axisThickness: 2,
|
||||
position: 'left',
|
||||
labelFunction: function(value) {
|
||||
return (Math.round((value / 1000000) * 1000000)/1000000).toFixed(2);
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'v-reward',
|
||||
axisColor: '#0b7a06',
|
||||
axisThickness: 2,
|
||||
position: 'left',
|
||||
offset: 75,
|
||||
},
|
||||
{
|
||||
id: 'v-inflation-rate',
|
||||
axisColor: '#ff9900',
|
||||
axisThickness: 2,
|
||||
position: 'right',
|
||||
labelFunction: function(value) {
|
||||
return value.toFixed(2);
|
||||
}
|
||||
},
|
||||
],
|
||||
categoryAxis: {
|
||||
parseDates: true,
|
||||
autoGridCount: false,
|
||||
minorGridEnabled: true,
|
||||
minorGridAlpha: 0.04,
|
||||
axisColor: '#dadada',
|
||||
twoLineMode: true
|
||||
},
|
||||
graphs: [
|
||||
{
|
||||
id: 'g-supply',
|
||||
valueAxis: 'v-supply', // we have to indicate which value axis should be used
|
||||
title: 'Available supply (millions LBC)',
|
||||
valueField: 'AvailableSupply',
|
||||
bullet: 'round',
|
||||
bulletBorderThickness: 1,
|
||||
bulletBorderAlpha: 1,
|
||||
bulletColor: '#ffffff',
|
||||
bulletSize: 5,
|
||||
useLineColorForBulletBorder: true,
|
||||
lineColor: '#1e88e5',
|
||||
hideBulletsCount: 101,
|
||||
balloonText: '[[AvailableSupply]]',
|
||||
balloonFunction: function(item, graph) {
|
||||
var result = graph.balloonText;
|
||||
return result.replace('[[AvailableSupply]]', (Math.round((item.dataContext.AvailableSupply / 1000000) * 1000000)/1000000).toFixed(2));
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'g-reward',
|
||||
valueAxis: 'v-reward',
|
||||
title: 'Block Reward (LBC)',
|
||||
valueField: 'RewardLBC',
|
||||
bullet: 'round',
|
||||
bulletBorderThickness: 1,
|
||||
bulletBorderAlpha: 1,
|
||||
bulletColor: '#ffffff',
|
||||
bulletSize: 5,
|
||||
useLineColorForBulletBorder: true,
|
||||
lineColor: '#0b7a06',
|
||||
balloonText: '[[RewardLBC]] LBC<br>Block [[BlockId]]',
|
||||
hideBulletsCount: 101
|
||||
},
|
||||
{
|
||||
id: 'g-inflation-rate',
|
||||
valueAxis: 'v-inflation-rate',
|
||||
title: 'Annualized Inflation Rate',
|
||||
valueField: 'InflationRate',
|
||||
bullet: 'round',
|
||||
bulletBorderThickness: 1,
|
||||
bulletBorderAlpha: 1,
|
||||
bulletColor: '#ffffff',
|
||||
bulletSize: 5,
|
||||
useLineColorForBulletBorder: true,
|
||||
lineColor: '#ff9900',
|
||||
balloonText: '[[InflationRate]]%',
|
||||
hideBulletsCount: 101,
|
||||
balloonFunction: function(item, graph) {
|
||||
var result = graph.balloonText;
|
||||
return result.replace('[[InflationRate]]', item.dataContext.InflationRate.toFixed(2));
|
||||
}
|
||||
}
|
||||
],
|
||||
chartCursor: {
|
||||
cursorAlpha: 0.1,
|
||||
fullWidth: true,
|
||||
valueLineBalloonEnabled: true,
|
||||
categoryBalloonColor: '#333333',
|
||||
cursorColor: '#1e88e5'
|
||||
},
|
||||
chartScrollbar: {
|
||||
scrollbarHeight: 36,
|
||||
color: '#888888',
|
||||
gridColor: '#bbbbbb'
|
||||
},
|
||||
legend: {
|
||||
marginLeft: 110,
|
||||
useGraphSettings: true,
|
||||
valueText: "",
|
||||
spacing: 64,
|
||||
|
||||
},
|
||||
export: {
|
||||
enabled: true,
|
||||
fileName: 'lbry-supply-chart',
|
||||
position: 'bottom-right',
|
||||
divId: 'chart-export'
|
||||
}
|
||||
});
|
||||
loadChartData();
|
||||
});
|
||||
Reference in new issue
Block a user