Merge pull request #49 from marcdeb1/chainquery

Chainquery integration
This commit is contained in:
Niko 2019-02-13 13:01:12 -05:00 committed by GitHub
commit 1b13f2711b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 1396 additions and 892 deletions

View file

@ -5,7 +5,6 @@ dist: trusty
sudo: false sudo: false
php: php:
- 5.6
- 7.0 - 7.0
- 7.1 - 7.1

View file

@ -6,9 +6,10 @@
"license": "MIT", "license": "MIT",
"require": { "require": {
"php": ">=5.6", "php": ">=5.6",
"cakephp/cakephp": "3.4.*", "cakephp/cakephp": "3.7.1",
"mobiledetect/mobiledetectlib": "2.*", "mobiledetect/mobiledetectlib": "2.*",
"cakephp/migrations": "~1.0", "cakephp/migrations": "~1.0",
"psr/simple-cache": "^1.0.0",
"cakephp/plugin-installer": "~1.0", "cakephp/plugin-installer": "~1.0",
"mdanter/ecc": "^0.5.0", "mdanter/ecc": "^0.5.0",
"nesbot/carbon": "~1.18", "nesbot/carbon": "~1.18",

704
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -218,20 +218,20 @@ return [
* See vendor\cakephp\cakephp\src\Database\Driver for complete list * See vendor\cakephp\cakephp\src\Database\Driver for complete list
*/ */
'Datasources' => [ 'Datasources' => [
'default' => [ 'default' => [ // Chainquery database connection
'className' => 'Cake\Database\Connection', 'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql', 'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false, 'persistent' => false,
'host' => 'localhost', 'host' => 'chainquery.lbry.io',
/** /**
* CakePHP will use the default DB port based on the driver selected * CakePHP will use the default DB port based on the driver selected
* MySQL on MAMP uses port 8889, MAMP users will want to uncomment * MySQL on MAMP uses port 8889, MAMP users will want to uncomment
* the following line and set the port accordingly * the following line and set the port accordingly
*/ */
//'port' => 'non_standard_port_number', //'port' => '3000',
'username' => 'my_app', 'username' => 'username',
'password' => 'secret', 'password' => 'secret',
'database' => 'my_app', 'database' => 'my_db',
'encoding' => 'utf8', 'encoding' => 'utf8',
'timezone' => 'UTC', 'timezone' => 'UTC',
'flags' => [], 'flags' => [],
@ -257,7 +257,28 @@ return [
*/ */
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'], //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
'url' => env('DATABASE_URL', null), 'url' => env('DATABASE_URL', 'chainquery.lbry.io:3600'),
],
'localdb' => [ // Local db for price history
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
/**
* CakePHP will use the default DB port based on the driver selected
* MySQL on MAMP uses port 8889, MAMP users will want to uncomment
* the following line and set the port accordingly
*/
//'port' => '3306',
'username' => 'username',
'password' => 'secret',
'database' => 'lbry',
'encoding' => 'utf8',
'timezone' => 'UTC',
'flags' => [],
'cacheMetadata' => true,
'log' => false,
], ],
/** /**

View file

@ -49,6 +49,7 @@ require __DIR__ . '/paths.php';
*/ */
require CORE_PATH . 'config' . DS . 'bootstrap.php'; require CORE_PATH . 'config' . DS . 'bootstrap.php';
use App\Application;
use Cake\Cache\Cache; use Cake\Cache\Cache;
use Cake\Console\ConsoleErrorHandler; use Cake\Console\ConsoleErrorHandler;
use Cake\Core\App; use Cake\Core\App;
@ -60,7 +61,8 @@ use Cake\Datasource\ConnectionManager;
use Cake\Error\ErrorHandler; use Cake\Error\ErrorHandler;
use Cake\Log\Log; use Cake\Log\Log;
use Cake\Mailer\Email; use Cake\Mailer\Email;
use Cake\Network\Request; use Cake\Mailer\TransportFactory;
use Cake\Http\ServerRequest;
use Cake\Utility\Inflector; use Cake\Utility\Inflector;
use Cake\Utility\Security; use Cake\Utility\Security;
@ -150,10 +152,12 @@ if (!Configure::read('App.fullBaseUrl')) {
Cache::setConfig(Configure::consume('Cache')); Cache::setConfig(Configure::consume('Cache'));
ConnectionManager::setConfig(Configure::consume('Datasources')); ConnectionManager::setConfig(Configure::consume('Datasources'));
Email::setConfigTransport(Configure::consume('EmailTransport')); //Email::setConfigTransport(Configure::consume('EmailTransport'));
TransportFactory::setConfig(Configure::consume('EmailTransport'));
Email::setConfig(Configure::consume('Email')); Email::setConfig(Configure::consume('Email'));
Log::setConfig(Configure::consume('Log')); Log::setConfig(Configure::consume('Log'));
Security::salt(Configure::consume('Security.salt')); //Security::salt(Configure::consume('Security.salt'));
Security::setSalt(Configure::consume('Security.salt'));
/* /*
* The default crypto extension in 3.0 is OpenSSL. * The default crypto extension in 3.0 is OpenSSL.
@ -165,12 +169,12 @@ Security::salt(Configure::consume('Security.salt'));
/* /*
* Setup detectors for mobile and tablet. * Setup detectors for mobile and tablet.
*/ */
Request::addDetector('mobile', function ($request) { ServerRequest::addDetector('mobile', function ($request) {
$detector = new \Detection\MobileDetect(); $detector = new \Detection\MobileDetect();
return $detector->isMobile(); return $detector->isMobile();
}); });
Request::addDetector('tablet', function ($request) { ServerRequest::addDetector('tablet', function ($request) {
$detector = new \Detection\MobileDetect(); $detector = new \Detection\MobileDetect();
return $detector->isTablet(); return $detector->isTablet();
@ -218,8 +222,9 @@ Type::build('timestamp')
* Debug Kit should not be installed on a production system * Debug Kit should not be installed on a production system
*/ */
if (Configure::read('debug')) { if (Configure::read('debug')) {
Plugin::load('DebugKit', ['bootstrap' => true]); //Plugin::load('DebugKit', ['bootstrap' => true]);
Application::addPlugin('DebugKit', ['bootstrap' => true]);
} }
Configure::load('lbry'); Configure::load('lbry','lbry.default');

View file

@ -72,9 +72,3 @@ Router::scope('/', function (RouteBuilder $routes) {
//$routes->fallbacks(DashedRoute::class); //$routes->fallbacks(DashedRoute::class);
}); });
/**
* Load all plugin routes. See the Plugin documentation on
* how to customize the loading of plugin routes.
*/
Plugin::routes();

23
dev.sh Executable file
View file

@ -0,0 +1,23 @@
#!/bin/bash
set -e
PHPBIN=php7.2
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ ! -e "config/app.php" ]; then
cp "$DIR/config/app.default.php" "$DIR/config/app.php"
fi
if ! which $PHPBIN 2>/dev/null; then
PHPBIN=php
fi
#Composer update
composer update
#$PHPBIN composer.phar install
$PHPBIN --server localhost:8000 --docroot "$DIR/webroot" "$DIR/webroot/index.php"

View file

@ -15,6 +15,7 @@ use Endroid\QrCode\LabelAlignment;
use Endroid\QrCode\QrCode; use Endroid\QrCode\QrCode;
use Endroid\QrCode\Response\QrCodeResponse; use Endroid\QrCode\Response\QrCodeResponse;
class MainController extends AppController { class MainController extends AppController {
public static $rpcurl; public static $rpcurl;
@ -95,21 +96,17 @@ class MainController extends AppController {
$lbcUsdPrice = $this->_getLatestPrice(); $lbcUsdPrice = $this->_getLatestPrice();
$this->set('lbcUsdPrice', $lbcUsdPrice); $this->set('lbcUsdPrice', $lbcUsdPrice);
$blocks = $this->Blocks->find()->select(['Chainwork', 'Confirmations', 'Difficulty', 'Hash', 'Height', 'TransactionHashes', 'BlockTime', 'BlockSize'])-> $blocks = $this->Blocks->find()->select(['chainwork', 'confirmations', 'difficulty', 'hash', 'height', 'transaction_hashes', 'block_time', 'block_size'])->order(['height' => 'desc'])->limit(6)->toArray();
order(['Height' => 'desc'])->limit(6)->toArray();
for ($i = 0; $i < count($blocks); $i++) { for ($i = 0; $i < count($blocks); $i++) {
$tx_hashes = json_decode($blocks[$i]->TransactionHashes); $tx_hashes = preg_split('#,#', $blocks[$i]->transaction_hashes);
$blocks[$i]->TransactionCount = count($tx_hashes); $blocks[$i]->transaction_count = count($tx_hashes);
} }
// hash rate // hash rate
$hashRate = $this->_formatHashRate($this->_gethashrate()); $hashRate = $this->_formatHashRate($this->_gethashrate());
// recent claims // recent claims
$claims = $this->Claims->find()->select(['TransactionHash', 'Name', 'Vout', 'ClaimId', 'ClaimType', 'Author', 'Title', 'Description', 'ContentType', //$claims = $this->Claims->find()->distinct(['Claims.claim_id'])->select($this->Claims)->select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->order(['Claims.created_at' => 'DESC'])->limit(5)->toArray();
'IsNSFW', 'Language', 'ThumbnailUrl', 'Created'])-> $claims = $this->Claims->find()->select($this->Claims)->select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->order(['Claims.created_at' => 'DESC'])->limit(5)->toArray();
distinct(['Claims.ClaimId'])->
contain(['Publisher' => ['fields' => ['Name']]])->order(['Claims.Created' => 'DESC'])->limit(5)->toArray();
$this->set('recentBlocks', $blocks); $this->set('recentBlocks', $blocks);
$this->set('recentClaims', $claims); $this->set('recentClaims', $claims);
@ -121,7 +118,9 @@ class MainController extends AppController {
$this->loadModel('Transactions'); $this->loadModel('Transactions');
$canConvert = false; $canConvert = false;
$priceInfo = json_decode($this->redis->get(self::lbcPriceKey)); if(isset($this->redis)) {
$priceInfo = json_decode($this->redis->get(self::lbcPriceKey));
}
if (isset($priceInfo->price)) { if (isset($priceInfo->price)) {
$canConvert = true; $canConvert = true;
} }
@ -133,7 +132,7 @@ class MainController extends AppController {
$page = intval($this->request->query('page')); $page = intval($this->request->query('page'));
$conn = ConnectionManager::get('default'); $conn = ConnectionManager::get('default');
$stmt = $conn->execute('SELECT COUNT(Id) AS Total FROM Claims'); $stmt = $conn->execute('SELECT COUNT(id) AS Total FROM claim');
$count = $stmt->fetch(\PDO::FETCH_OBJ); $count = $stmt->fetch(\PDO::FETCH_OBJ);
$numClaims = $count->Total; $numClaims = $count->Total;
@ -146,10 +145,11 @@ class MainController extends AppController {
} }
$offset = ($page - 1) * $pageLimit; $offset = ($page - 1) * $pageLimit;
$claims = $this->Claims->find()->distinct(['Claims.ClaimId'])->contain(['Stream', 'Publisher' => ['fields' => ['Name']]])->order(['Claims.Created' => 'DESC'])->offset($offset)->limit($pageLimit)->toArray(); $claims = $this->Claims->find()->select($this->Claims)->select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->order(['Claims.created_at' => 'DESC'])->offset($offset)->limit($pageLimit)->toArray();
for ($i = 0; $i < count($claims); $i++) { for ($i = 0; $i < count($claims); $i++) {
if ($canConvert && $claims[$i]->Fee > 0 && $claims[$i]->FeeCurrency == 'USD') { if ($canConvert && $claims[$i]->fee > 0 && $claims[$i]->fee_currency == 'USD') {
$claims[$i]->Price = $claims[$i]->Fee / $priceInfo->price; $claims[$i]->price = $claims[$i]->fee / $priceInfo->price;
} }
if (isset($claims[$i]->Stream)) { if (isset($claims[$i]->Stream)) {
@ -169,13 +169,13 @@ class MainController extends AppController {
$this->set('currentPage', $page); $this->set('currentPage', $page);
$this->set('claims', $claims); $this->set('claims', $claims);
} else { } else {
$claim = $this->Claims->find()->contain(['Stream', 'Publisher' => ['fields' => ['ClaimId', 'Name']]])->where(['Claims.ClaimId' => $id])->order(['Claims.Created' => 'DESC'])->first(); $claim = $this->Claims->find()->select($this->Claims)->select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->where(['Claims.claim_id' => $id])->order(['Claims.created_at' => 'DESC'])->first();
if (!$claim) { if (!$claim) {
return $this->redirect('/'); return $this->redirect('/');
} }
if ($canConvert && $claim->Fee > 0 && $claim->FeeCurrency == 'USD') { if ($canConvert && $claim->fee > 0 && $claim->fee_currency == 'USD') {
$claim->Price = $claim->Fee / $priceInfo->price; $claim->price = $claim->fee / $priceInfo->price;
} }
if (isset($claim->Stream)) { if (isset($claim->Stream)) {
@ -189,14 +189,12 @@ class MainController extends AppController {
} }
$moreClaims = []; $moreClaims = [];
if (isset($claim->Publisher) || $claim->ClaimType == 1) { if (isset($claim->publisher) || $claim->claim_type == 1) {
// find more claims for the publisher // find more claims for the publisher
$moreClaims = $this->Claims->find()->contain(['Stream', 'Publisher' => ['fields' => ['Name']]])-> $moreClaims = $this->Claims->find()->select($this->Claims)->select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->where(['Claims.claim_type' => 1, 'Claims.id <>' => $claim->id, 'Claims.publisher_id' => isset($claim->publisher) ? $claim->publisher_id : $claim->claim_id])->limit(9)->order(['Claims.fee' => 'DESC', 'RAND()' => 'DESC'])->toArray();
where(['Claims.ClaimType' => 2, 'Claims.Id <>' => $claim->Id, 'Claims.PublisherId' => isset($claim->Publisher) ? $claim->Publisher->ClaimId : $claim->ClaimId])->
limit(9)->order(['Claims.Fee' => 'DESC', 'RAND()' => 'DESC'])->toArray();
for ($i = 0; $i < count($moreClaims); $i++) { for ($i = 0; $i < count($moreClaims); $i++) {
if ($canConvert && $moreClaims[$i]->Fee > 0 && $moreClaims[$i]->FeeCurrency == 'USD') { if ($canConvert && $moreClaims[$i]->fee > 0 && $moreClaims[$i]->fee_currency == 'USD') {
$moreClaims[$i]->Price = $moreClaims[$i]->Fee / $priceInfo->price; $moreClaims[$i]->price = $moreClaims[$i]->fee / $priceInfo->price;
} }
if (isset($moreClaims[$i]->Stream)) { if (isset($moreClaims[$i]->Stream)) {
@ -210,7 +208,6 @@ class MainController extends AppController {
} }
} }
} }
$this->set('claim', $claim); $this->set('claim', $claim);
$this->set('moreClaims', $moreClaims); $this->set('moreClaims', $moreClaims);
} }
@ -219,115 +216,19 @@ class MainController extends AppController {
public function realtime() { public function realtime() {
$this->loadModel('Blocks'); $this->loadModel('Blocks');
$this->loadModel('Transactions'); $this->loadModel('Transactions');
$this->loadModel('Outputs');
// load 10 blocks and transactions // load 10 blocks and transactions
$conn = ConnectionManager::get('default'); $blocks = $this->Blocks->find()->select(['height', 'block_time', 'transaction_hashes'])->order(['height' => 'desc'])->limit(10)->toArray();
$blocks = $this->Blocks->find()->select(['Height', 'BlockTime', 'TransactionHashes'])->order(['Height' => 'desc'])->limit(10)->toArray();
for ($i = 0; $i < count($blocks); $i++) { for ($i = 0; $i < count($blocks); $i++) {
$tx_hashes = json_decode($blocks[$i]->TransactionHashes); $tx_hashes = preg_split('#,#', $blocks[$i]->transaction_hashes);
$blocks[$i]->TransactionCount = count($tx_hashes); $blocks[$i]->transaction_count = count($tx_hashes);
} }
$stmt = $conn->execute('SELECT T.Hash, T.InputCount, T.OutputCount, T.Value, IFNULL(T.TransactionTime, T.CreatedTime) AS TxTime ' . $transactions = $this->Transactions->find()->select(['Transactions.id', 'Transactions.hash', 'Transactions.value', 'Transactions.input_count', 'Transactions.output_count', 'Transactions.transaction_time', 'Transactions.created_at'])->order(['Transactions.created_at' => 'desc'])->limit(10)->toArray();
'FROM Transactions T ORDER BY CreatedTime DESC LIMIT 10');
$txs = $stmt->fetchAll(\PDO::FETCH_OBJ);
$this->set('blocks', $blocks); $this->set('blocks', $blocks);
$this->set('txs', $txs); $this->set('txs', $transactions);
}
public function apiblocksize($timePeriod = '24h') {
$this->autoRender = false;
if (!$this->request->is('get')) {
return $this->_jsonError('Invalid HTTP request method.', 400);
}
$validPeriods = ['24h', '72h', '168h', '30d', '90d', '1y'];
if (!in_array($timePeriod, $validPeriods)) {
return $this->_jsonError('Invalid time period specified.', 400);
}
$isHourly = (strpos($timePeriod, 'h') !== false);
$now = new \DateTime('now', new \DateTimeZone('UTC'));
$dateFormat = $isHourly ? 'Y-m-d H:00:00' : 'Y-m-d';
$sqlDateFormat = $isHourly ? '%Y-%m-%d %H:00:00' : '%Y-%m-%d';
$intervalPrefix = $isHourly ? 'PT' : 'P';
$start = $now->sub(new \DateInterval($intervalPrefix . strtoupper($timePeriod)));
$resultSet = [];
$conn = ConnectionManager::get('default');
// get avg block sizes for the time period
$stmt = $conn->execute("SELECT AVG(BlockSize) AS AvgBlockSize, DATE_FORMAT(FROM_UNIXTIME(BlockTime), '$sqlDateFormat') AS TimePeriod " .
"FROM Blocks WHERE DATE_FORMAT(FROM_UNIXTIME(BlockTime), '$sqlDateFormat') >= ? GROUP BY TimePeriod ORDER BY TimePeriod ASC", [$start->format($dateFormat)]);
$avgBlockSizes = $stmt->fetchAll(\PDO::FETCH_OBJ);
foreach ($avgBlockSizes as $size) {
if (!isset($resultSet[$size->TimePeriod])) {
$resultSet[$size->TimePeriod] = [];
}
$resultSet[$size->TimePeriod]['AvgBlockSize'] = (float) $size->AvgBlockSize;
}
// get avg prices
$stmt = $conn->execute("SELECT AVG(USD) AS AvgUSD, DATE_FORMAT(Created, '$sqlDateFormat') AS TimePeriod " .
"FROM PriceHistory WHERE DATE_FORMAT(Created, '$sqlDateFormat') >= ? GROUP BY TimePeriod ORDER BY TimePeriod ASC", [$start->format($dateFormat)]);
$avgPrices = $stmt->fetchAll(\PDO::FETCH_OBJ);
foreach ($avgPrices as $price) {
if (!isset($resultSet[$price->TimePeriod])) {
$resultSet[$price->TimePeriod] = [];
}
$resultSet[$price->TimePeriod]['AvgUSD'] = (float) $price->AvgUSD;
}
return $this->_jsonResponse(['success' => true, 'data' => $resultSet]);
}
public function apirealtimeblocks() {
// load 10 blocks
$this->autoRender = false;
$this->loadModel('Blocks');
$blocks = $this->Blocks->find()->select(['Height', 'BlockTime', 'TransactionHashes'])->order(['Height' => 'desc'])->limit(10)->toArray();
for ($i = 0; $i < count($blocks); $i++) {
$tx_hashes = json_decode($blocks[$i]->TransactionHashes);
$blocks[$i]->TransactionCount = count($tx_hashes);
unset($blocks[$i]->TransactionHashes);
}
$this->_jsonResponse(['success' => true, 'blocks' => $blocks]);
}
public function apirealtimetx() {
// load 10 transactions
$this->autoRender = false;
$conn = ConnectionManager::get('default');
$stmt = $conn->execute('SELECT T.Hash, T.InputCount, T.OutputCount, T.Value, IFNULL(T.TransactionTime, T.CreatedTime) AS TxTime ' .
'FROM Transactions T ORDER BY CreatedTime DESC LIMIT 10');
$txs = $stmt->fetchAll(\PDO::FETCH_OBJ);
$this->_jsonResponse(['success' => true, 'txs' => $txs]);
}
protected function _formatHashRate($value) {
if ($value === 'N/A') {
return $value;
}
/*if ($value > 1000000000000) {
return number_format( $value / 1000000000000, 2, '.', '' ) . ' TH';
}*/
if ($value > 1000000000) {
return number_format( $value / 1000000000, 2, '.', '' ) . ' GH/s';
}
if ($value > 1000000) {
return number_format( $value / 1000000, 2, '.', '' ) . ' MH/s';
}
if ($value > 1000) {
return number_format( $value / 1000, 2, '.', '' ) . ' KH/s';
}
return number_format($value) . ' H/s';
} }
public function find() { public function find() {
@ -340,38 +241,38 @@ class MainController extends AppController {
if (is_numeric($criteria)) { if (is_numeric($criteria)) {
$height = (int) $criteria; $height = (int) $criteria;
$block = $this->Blocks->find()->select(['Id'])->where(['Height' => $height])->first(); $block = $this->Blocks->find()->select(['id'])->where(['height' => $height])->first();
if ($block) { if ($block) {
return $this->redirect('/blocks/' . $height); return $this->redirect('/blocks/' . $height);
} }
} else if (strlen(trim($criteria)) === 34) { } else if (strlen(trim($criteria)) === 34) {
// Address // Address
$address = $this->Addresses->find()->select(['Id', 'Address'])->where(['Address' => $criteria])->first(); $address = $this->Addresses->find()->select(['id', 'address'])->where(['address' => $criteria])->first();
if ($address) { if ($address) {
return $this->redirect('/address/' . $address->Address); return $this->redirect('/address/' . $address->address);
} }
} else if (strlen(trim($criteria)) === 40) { } else if (strlen(trim($criteria)) === 40) {
// Claim ID // Claim ID
$claim = $this->Claims->find()->select(['ClaimId'])->where(['ClaimId' => $criteria])->first(); $claim = $this->Claims->find()->select(['claim_id'])->where(['claim_id' => $criteria])->first();
if ($claim) { if ($claim) {
return $this->redirect('/claims/' . $claim->ClaimId); return $this->redirect('/claims/' . $claim->claim_id);
} }
} else if (strlen(trim($criteria)) === 64) { // block or tx hash } else if (strlen(trim($criteria)) === 64) { // block or tx hash
// Try block hash first // Try block hash first
$block = $this->Blocks->find()->select(['Height'])->where(['Hash' => $criteria])->first(); $block = $this->Blocks->find()->select(['height'])->where(['hash' => $criteria])->first();
if ($block) { if ($block) {
return $this->redirect('/blocks/' . $block->Height); return $this->redirect('/blocks/' . $block->height);
} else { } else {
$tx = $this->Transactions->find()->select(['Hash'])->where(['Hash' => $criteria])->first(); $tx = $this->Transactions->find()->select(['hash'])->where(['hash' => $criteria])->first();
if ($tx) { if ($tx) {
return $this->redirect('/tx/' . $tx->Hash); return $this->redirect('/tx/' . $tx->hash);
} }
} }
} else { } else {
// finally, try exact claim name match // finally, try exact claim name match
$claims = $this->Claims->find()->distinct(['Claims.ClaimId'])->where(['Name' => $criteria])->order(['Claims.Created' => 'DESC'])->limit(10)->toArray(); $claims = $this->Claims->find()->distinct(['claim_id'])->where(['name' => $criteria])->order(["FIELD(bid_state, 'Controlling') DESC"])->limit(10)->toArray();
if (count($claims) == 1) { if (count($claims) == 1) {
return $this->redirect('/claims/' . $claims[0]->ClaimId); return $this->redirect('/claims/' . $claims[0]->claim_id);
} }
else { else {
$this->set('claims', $claims); $this->set('claims', $claims);
@ -381,6 +282,8 @@ class MainController extends AppController {
public function blocks($height = null) { public function blocks($height = null) {
$this->loadModel('Blocks'); $this->loadModel('Blocks');
$this->loadModel('Outputs');
$this->loadModel('Transactions');
if ($height === null) { if ($height === null) {
// paginate blocks // paginate blocks
@ -389,7 +292,7 @@ class MainController extends AppController {
$page = intval($this->request->query('page')); $page = intval($this->request->query('page'));
$conn = ConnectionManager::get('default'); $conn = ConnectionManager::get('default');
$stmt = $conn->execute('SELECT COUNT(Id) AS Total FROM Blocks'); $stmt = $conn->execute('SELECT COUNT(id) AS Total FROM block');
$count = $stmt->fetch(\PDO::FETCH_OBJ); $count = $stmt->fetch(\PDO::FETCH_OBJ);
$numBlocks = $count->Total; $numBlocks = $count->Total;
@ -402,10 +305,10 @@ class MainController extends AppController {
} }
$offset = ($page - 1) * $pageLimit; $offset = ($page - 1) * $pageLimit;
$currentBlock = $this->Blocks->find()->select(['Height'])->order(['Height' => 'DESC'])->first(); $currentBlock = $this->Blocks->find()->select(['height'])->order(['height' => 'DESC'])->first();
$blocks = $this->Blocks->find()->select( $blocks = $this->Blocks->find()->select(
['Height', 'Difficulty', 'TransactionHashes', 'BlockSize', 'Nonce', 'BlockTime'] ['height', 'difficulty', 'transaction_hashes', 'block_size', 'nonce', 'block_time']
)->offset($offset)->limit($pageLimit)->order(['Height' => 'DESC'])->toArray(); )->offset($offset)->limit($pageLimit)->order(['height' => 'DESC'])->toArray();
$this->set('currentBlock', $currentBlock); $this->set('currentBlock', $currentBlock);
$this->set('blocks', $blocks); $this->set('blocks', $blocks);
$this->set('pageLimit', $pageLimit); $this->set('pageLimit', $pageLimit);
@ -413,35 +316,18 @@ class MainController extends AppController {
$this->set('numRecords', $numBlocks); $this->set('numRecords', $numBlocks);
$this->set('currentPage', $page); $this->set('currentPage', $page);
} else { } else {
$this->loadModel('Transactions');
$height = intval($height); $height = intval($height);
if ($height < 0) { if ($height < 0) {
return $this->redirect('/'); return $this->redirect('/');
} }
$block = $this->Blocks->find()->where(['Height' => $height])->first(); $block = $this->Blocks->find()->where(['height' => $height])->first();
if (!$block) { if (!$block) {
return $this->redirect('/'); return $this->redirect('/');
} }
try {
// update the block confirmations
$req = ['method' => 'getblock', 'params' => [$block->Hash]];
$response = self::curl_json_post(self::$rpcurl, json_encode($req));
$json = json_decode($response);
$rpc_block = $json->result;
if (isset($rpc_block->confirmations)) {
$block->Confirmations = $rpc_block->confirmations;
$conn = ConnectionManager::get('default');
$conn->execute('UPDATE Blocks SET Confirmations = ? WHERE Id = ?', [$rpc_block->confirmations, $block->Id]);
}
} catch (\Exception $e) {
// try again next time
}
// Get the basic block transaction info // Get the basic block transaction info
$txs = $this->Transactions->find()->select(['InputCount', 'OutputCount', 'Hash', 'Value', 'Version'])->where(['BlockHash' => $block->Hash])->toArray(); $txs = $this->Transactions->find()->select(['Transactions.id', 'Transactions.value', 'Transactions.input_count', 'Transactions.output_count', 'Transactions.hash', 'Transactions.version'])->where(['Transactions.block_hash_id' => $block->hash])->toArray();
$this->set('block', $block); $this->set('block', $block);
$this->set('blockTxs', $txs); $this->set('blockTxs', $txs);
} }
@ -452,43 +338,48 @@ class MainController extends AppController {
$this->loadModel('Transactions'); $this->loadModel('Transactions');
$this->loadModel('Inputs'); $this->loadModel('Inputs');
$this->loadModel('Outputs'); $this->loadModel('Outputs');
$this->loadModel('Addresses');
$this->loadModel('Claims'); $this->loadModel('Claims');
$sourceAddress = $this->request->query('address'); $sourceAddress = $this->request->query('address');
$tx = $this->Transactions->find()->select( $tx = $this->Transactions->find()->where(['Transactions.hash' => $hash])->first();
['Id', 'BlockHash', 'InputCount', 'OutputCount', 'Hash', 'Value', 'TransactionTime', 'TransactionSize', 'Created', 'Version', 'LockTime', 'Raw'])->where(['Hash' => $hash])->first();
if (!$tx) { if (!$tx) {
return $this->redirect('/'); return $this->redirect('/');
} }
if ($tx->TransactionSize == 0) { $block = $this->Blocks->find()->select(['confirmations', 'height'])->where(['hash' => $tx->block_hash_id])->first();
$tx->TransactionSize = (strlen($tx->Raw) / 2); $confirmations = $block->confirmations;
$conn = ConnectionManager::get('default'); $inputs = $this->Inputs->find()->where(['transaction_id' => $tx->id])->order(['prevout_n' => 'asc'])->toArray();
$conn->execute('UPDATE Transactions SET TransactionSize = ? WHERE Id = ?', [$tx->TransactionSize, $tx->Id]); foreach($inputs as $input) {
$inputAddresses = $this->Addresses->find()->select(['id', 'address'])->where(['id' => $input->input_address_id])->toArray();
$input->input_addresses = $inputAddresses;
} }
$maxBlock = $this->Blocks->find()->select(['Height'])->order(['Height' => 'desc'])->first(); $outputs = $this->Outputs->find()->select($this->Outputs)->select(['spend_input_hash' => 'I.transaction_hash', 'spend_input_id' => 'I.id'])->where(['Outputs.transaction_id' => $tx->id])->leftJoin(['I' => 'input'], ['I.id = Outputs.spent_by_input_id'])->order(['Outputs.vout' => 'asc'])->toArray();
$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++) { for ($i = 0; $i < count($outputs); $i++) {
$outputs[$i]->IsClaim = (strpos($outputs[$i]->ScriptPubKeyAsm, 'CLAIM') > -1); $outputs[$i]->IsClaim = (strpos($outputs[$i]->script_pub_key_asm, 'CLAIM') > -1);
$outputs[$i]->IsSupportClaim = (strpos($outputs[$i]->ScriptPubKeyAsm, 'SUPPORT_CLAIM') > -1); $outputs[$i]->IsSupportClaim = (strpos($outputs[$i]->script_pub_key_asm, 'SUPPORT_CLAIM') > -1);
$outputs[$i]->IsUpdateClaim = (strpos($outputs[$i]->ScriptPubKeyAsm, 'UPDATE_CLAIM') > -1); $outputs[$i]->IsUpdateClaim = (strpos($outputs[$i]->script_pub_key_asm, 'UPDATE_CLAIM') > -1);
$claim = $this->Claims->find()->where(['TransactionHash' => $tx->Hash, 'Vout' => $outputs[$i]->Vout])->first(); $claim = $this->Claims->find()->select(['id', 'claim_id', 'claim_address', 'vout', 'transaction_hash_id'])->where(['transaction_hash_id' => $tx->hash, 'vout' => $outputs[$i]->vout])->first();
$outputs[$i]->Claim = $claim; $outputs[$i]->Claim = $claim;
$output_address = trim($outputs[$i]->address_list, '[""]');
if(!$output_address && $claim) {
$output_address = $claim->claim_address;
}
$address = $this->Addresses->find()->select(['address'])->where(['address' => $output_address])->first();
$outputs[$i]->output_addresses = [$address];
} }
$totalIn = 0; $totalIn = 0;
$totalOut = 0; $totalOut = 0;
$fee = 0; $fee = 0;
foreach ($inputs as $in) { foreach ($inputs as $in) {
$totalIn = bcadd($totalIn, $in->Value, 8); $totalIn = bcadd($totalIn, $in->value, 8);
} }
foreach ($outputs as $out) { foreach ($outputs as $out) {
$totalOut = bcadd($totalOut, $out->Value, 8); $totalOut = bcadd($totalOut, $out->value, 8);
} }
$fee = bcsub($totalIn, $totalOut, 8); $fee = bcsub($totalIn, $totalOut, 8);
@ -505,13 +396,14 @@ class MainController extends AppController {
$this->loadModel('Addresses'); $this->loadModel('Addresses');
// exclude bHW58d37s1hBjj3wPBkn5zpCX3F8ZW3uWf (genesis block) // exclude bHW58d37s1hBjj3wPBkn5zpCX3F8ZW3uWf (genesis block)
$richList = $this->Addresses->find()->where(['Address <>' => 'bHW58d37s1hBjj3wPBkn5zpCX3F8ZW3uWf'])->order(['Balance' => 'DESC'])->limit(500)->toArray(); $richList = $this->Addresses->find()->where(['address <>' => 'bHW58d37s1hBjj3wPBkn5zpCX3F8ZW3uWf'])->order(['balance' => 'DESC'])->limit(500)->toArray();
$priceRate = 0; $priceRate = 0;
//$priceInfo = json_decode($this->redis->get(self::lbcPriceKey)); if(isset($this->redis)) {
$priceInfo->price = 0.05; $priceInfo = json_decode($this->redis->get(self::lbcPriceKey));
if (isset($priceInfo->price)) { if (isset($priceInfo->price)) {
$priceRate = $priceInfo->price; $priceRate = $priceInfo->price;
}
} }
$lbryAddresses = ['rFLUohPG4tP3gZHYoyhvADCtrDMiaYb7Qd', 'r9PGXsejVJb9ZfMf3QVdDEJCzxkd9JLxzL', 'r9srwX7DEN7Mex3a8oR1mKSqQmLBizoJvi', 'bRo4FEeqqxY7nWFANsZsuKEWByEgkvz8Qt', 'bU2XUzckfpdEuQNemKvhPT1gexQ3GG3SC2', 'bay3VA6YTQBL4WLobbG7CthmoGeUKXuXkD', 'bLPbiXBp6Vr3NSnsHzDsLNzoy5o36re9Cz', 'bMvUBo1h5WS46ThHtmfmXftz3z33VHL7wc', 'bVUrbCK8hcZ5XWti7b9eNxKEBxzc1rr393', 'bZja2VyhAC84a9hMwT8dwTU6rDRXowrjxH', 'bMvUBo1h5WS46ThHtmfmXftz3z33VHL7wc', 'bMgqQqYfwzWWYBk5o5dBMXtCndVAoeqy6h', 'bMvUBo1h5WS46ThHtmfmXftz3z33VHL7wc']; $lbryAddresses = ['rFLUohPG4tP3gZHYoyhvADCtrDMiaYb7Qd', 'r9PGXsejVJb9ZfMf3QVdDEJCzxkd9JLxzL', 'r9srwX7DEN7Mex3a8oR1mKSqQmLBizoJvi', 'bRo4FEeqqxY7nWFANsZsuKEWByEgkvz8Qt', 'bU2XUzckfpdEuQNemKvhPT1gexQ3GG3SC2', 'bay3VA6YTQBL4WLobbG7CthmoGeUKXuXkD', 'bLPbiXBp6Vr3NSnsHzDsLNzoy5o36re9Cz', 'bMvUBo1h5WS46ThHtmfmXftz3z33VHL7wc', 'bVUrbCK8hcZ5XWti7b9eNxKEBxzc1rr393', 'bZja2VyhAC84a9hMwT8dwTU6rDRXowrjxH', 'bMvUBo1h5WS46ThHtmfmXftz3z33VHL7wc', 'bMgqQqYfwzWWYBk5o5dBMXtCndVAoeqy6h', 'bMvUBo1h5WS46ThHtmfmXftz3z33VHL7wc'];
@ -519,15 +411,15 @@ class MainController extends AppController {
$maxBalance = 0; $maxBalance = 0;
$minBalance = 0; $minBalance = 0;
foreach ($richList as $item) { foreach ($richList as $item) {
$totalBalance = bcadd($totalBalance, $item->Balance, 8); $totalBalance = bcadd($totalBalance, $item->balance, 8);
$minBalance = $minBalance == 0 ? $item->Balance : min($minBalance, $item->Balance); $minBalance = $minBalance == 0 ? $item->balance : min($minBalance, $item->balance);
$maxBalance = max($maxBalance, $item->Balance); $maxBalance = max($maxBalance, $item->balance);
} }
for ($i = 0; $i < count($richList); $i++) { for ($i = 0; $i < count($richList); $i++) {
$item = $richList[$i]; $item = $richList[$i];
$percentage = bcdiv($item->Balance, $totalBalance, 8) * 100; $percentage = bcdiv($item->balance, $totalBalance, 8) * 100;
$richList[$i]->Top500Percent = $percentage; $richList[$i]->Top500Percent = $percentage;
$richList[$i]->MinMaxPercent = bcdiv($item->Balance, $maxBalance, 8) * 100; $richList[$i]->MinMaxPercent = bcdiv($item->balance, $maxBalance, 8) * 100;
} }
$this->set('richList', $richList); $this->set('richList', $richList);
@ -543,6 +435,7 @@ class MainController extends AppController {
$this->loadModel('Transactions'); $this->loadModel('Transactions');
$this->loadModel('Inputs'); $this->loadModel('Inputs');
$this->loadModel('Outputs'); $this->loadModel('Outputs');
$this->loadModel('TransactionAddresses');
if (!$addr) { if (!$addr) {
return $this->redirect('/'); return $this->redirect('/');
@ -560,12 +453,11 @@ class MainController extends AppController {
$recentTxs = []; $recentTxs = [];
$tagRequestAmount = 0; $tagRequestAmount = 0;
$address = $this->Addresses->find()->where(['address' => $addr])->first();
$address = $this->Addresses->find()->where(['Address' => $addr])->first();
if (!$address) { if (!$address) {
if (strlen($addr) === 34) { if (strlen($addr) === 34) {
$address = new \stdClass(); $address = new \stdClass();
$address->Address = $addr; $address->address = $addr;
} else { } else {
return $this->redirect('/'); return $this->redirect('/');
} }
@ -573,11 +465,9 @@ class MainController extends AppController {
$conn = ConnectionManager::get('default'); $conn = ConnectionManager::get('default');
$canTag = true; $canTag = true;
$addressId = $address->Id; $transactionAddresses = $this->TransactionAddresses->find()->where(['address_id' => $address->id])->toArray();
$numTransactions = count($transactionAddresses);
$stmt = $conn->execute('SELECT COUNT(TransactionId) AS Total FROM TransactionsAddresses WHERE AddressId = ?', [$addressId]);
$count = $stmt->fetch(\PDO::FETCH_OBJ);
$numTransactions = $count->Total;
$all = $this->request->query('all'); $all = $this->request->query('all');
if ($all === 'true') { if ($all === 'true') {
$offset = 0; $offset = 0;
@ -596,26 +486,23 @@ class MainController extends AppController {
$offset = ($page - 1) * $pageLimit; $offset = ($page - 1) * $pageLimit;
} }
$stmt = $conn->execute('SELECT A.TotalReceived, A.TotalSent, A.Balance FROM Addresses A WHERE A.Id = ?', [$address->Id]);
$totals = $stmt->fetch(\PDO::FETCH_OBJ);
$currentBlock = $this->Blocks->find()->select(['Height'])->order(['Height' => 'desc'])->first();
$currentHeight = $currentBlock ? intval($currentBlock->Height) : 0;
$stmt = $conn->execute(sprintf( $stmt = $conn->execute(sprintf(
'SELECT T.Id, T.Hash, T.InputCount, T.OutputCount, T.Value, ' . 'SELECT T.id, T.hash, T.input_count, T.output_count, T.block_hash_id, ' .
' TA.DebitAmount, TA.CreditAmount, ' . ' TA.debit_amount, TA.credit_amount, ' .
' B.Height, (CASE WHEN B.Height IS NOT NULL THEN ((' . $currentHeight . ' - B.Height) + 1) ELSE NULL END) AS Confirmations, ' . ' B.height, B.confirmations, ' .
' IFNULL(T.TransactionTime, T.CreatedTime) AS TxTime ' . ' IFNULL(T.transaction_time, T.created_at) AS transaction_time ' .
'FROM Transactions T ' . 'FROM transaction T ' .
'LEFT JOIN Blocks B ON T.BlockHash = B.Hash ' . 'LEFT JOIN block B ON T.block_hash_id = B.hash ' .
'RIGHT JOIN (SELECT TransactionId, DebitAmount, CreditAmount FROM TransactionsAddresses ' . 'RIGHT JOIN (SELECT transaction_id, debit_amount, credit_amount FROM transaction_address ' .
' WHERE AddressId = ? ORDER BY TransactionTime DESC LIMIT %d, %d) TA ON TA.TransactionId = T.Id', $offset, $pageLimit), [$addressId]); ' WHERE address_id = ?) TA ON TA.transaction_id = T.id ' .
'ORDER BY transaction_time DESC LIMIT %d, %d', $offset, $pageLimit), [$address->id]);
$recentTxs = $stmt->fetchAll(\PDO::FETCH_OBJ); $recentTxs = $stmt->fetchAll(\PDO::FETCH_OBJ);
$totalRecvAmount = $totals->TotalReceived == 0 ? '0' : $totals->TotalReceived + 0; foreach($transactionAddresses as $ta) {
$totalSentAmount = $totals->TotalSent == 0 ? '0' : $totals->TotalSent + 0; $totalRecvAmount += $ta->credit_amount + 0;
$balanceAmount = $totals->Balance == 0 ? '0' : $totals->Balance + 0; $totalSentAmount += $ta->debit_amount + 0;
}
$balanceAmount = $totalRecvAmount - $totalSentAmount;
} }
$this->set('offset', $offset); $this->set('offset', $offset);
@ -645,51 +532,88 @@ class MainController extends AppController {
$qrCode->setWriterByName('png'); $qrCode->setWriterByName('png');
$qrCode->setMargin(10); $qrCode->setMargin(10);
$qrCode->setEncoding('UTF-8'); $qrCode->setEncoding('UTF-8');
$qrCode->setErrorCorrectionLevel(new ErrorCorrectionLevel(ErrorCorrectionLevel::LOW)); $qrCode->setErrorCorrectionLevel(new ErrorCorrectionLevel(ErrorCorrectionLevel::HIGH));
$qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]); $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
$qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]); $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
$qrCode->setLogoWidth(150); $qrCode->setLogoWidth(150);
$qrCode->setValidateResult(false); $qrCode->setValidateResult(false);
header('Content-Type: '.$qrCode->getContentType()); header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString(); echo $qrCode->writeString();
exit(0); exit(0);
} }
public static function curl_get($url) { public function apiblocksize($timePeriod = '24h') {
$ch = curl_init(); $this->autoRender = false;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch); if (!$this->request->is('get')) {
Log::debug('Request execution completed.'); return $this->_jsonError('Invalid HTTP request method.', 400);
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);
} }
return $response; $validPeriods = ['24h', '72h', '168h', '30d', '90d', '1y'];
if (!in_array($timePeriod, $validPeriods)) {
return $this->_jsonError('Invalid time period specified.', 400);
}
$isHourly = (strpos($timePeriod, 'h') !== false);
$now = new \DateTime('now', new \DateTimeZone('UTC'));
$dateFormat = $isHourly ? 'Y-m-d H:00:00' : 'Y-m-d';
$sqlDateFormat = $isHourly ? '%Y-%m-%d %H:00:00' : '%Y-%m-%d';
$intervalPrefix = $isHourly ? 'PT' : 'P';
$start = $now->sub(new \DateInterval($intervalPrefix . strtoupper($timePeriod)));
$resultSet = [];
// get avg prices
/*
$conn_local = ConnectionManager::get('localdb');
$stmt_price = $conn_local->execute("SELECT AVG(USD) AS AvgUSD, DATE_FORMAT(Created, '$sqlDateFormat') AS TimePeriod " .
"FROM PriceHistory WHERE DATE_FORMAT(Created, '$sqlDateFormat') >= ? GROUP BY TimePeriod ORDER BY TimePeriod ASC", [$start->format($dateFormat)]);
$avgPrices = $stmt_price->fetchAll(\PDO::FETCH_OBJ);
foreach ($avgPrices as $price) {
if (!isset($resultSet[$price->TimePeriod])) {
$resultSet[$price->TimePeriod] = [];
}
$resultSet[$price->TimePeriod]['AvgUSD'] = (float) $price->AvgUSD;
}
*/
$conn = ConnectionManager::get('default');
// get avg block sizes for the time period
$stmt = $conn->execute("SELECT AVG(block_size) AS AvgBlockSize, DATE_FORMAT(FROM_UNIXTIME(block_time), '$sqlDateFormat') AS TimePeriod " .
"FROM block WHERE DATE_FORMAT(FROM_UNIXTIME(block_time), '$sqlDateFormat') >= ? GROUP BY TimePeriod ORDER BY TimePeriod ASC", [$start->format($dateFormat)]);
$avgBlockSizes = $stmt->fetchAll(\PDO::FETCH_OBJ);
foreach ($avgBlockSizes as $size) {
if (!isset($resultSet[$size->TimePeriod])) {
$resultSet[$size->TimePeriod] = [];
}
$resultSet[$size->TimePeriod]['AvgBlockSize'] = (float) $size->AvgBlockSize;
}
return $this->_jsonResponse(['success' => true, 'data' => $resultSet]);
} }
private function _gethashrate() { public function apirealtimeblocks() {
$req = ['method' => 'getnetworkhashps', 'params' => []]; // Load 10 blocks
try { $this->autoRender = false;
$res = json_decode(self::curl_json_post(self::$rpcurl, json_encode($req))); $this->loadModel('Blocks');
if (!isset($res->result)) { $blocks = $this->Blocks->find()->select(['Height' => 'height', 'BlockTime' => 'block_time', 'transaction_hashes'])->order(['Height' => 'desc'])->limit(10)->toArray();
return 0; for ($i = 0; $i < count($blocks); $i++) {
} $tx_hashes = preg_split('#,#', $blocks[$i]->transaction_hashes);
return $res->result; $blocks[$i]->TransactionCount = count($tx_hashes);
} catch (\Exception $e) { unset($blocks[$i]->transaction_hashes);
return 'N/A';
} }
$this->_jsonResponse(['success' => true, 'blocks' => $blocks]);
}
public function apirealtimetx() {
// Load 10 transactions
$this->autoRender = false;
$this->loadModel('Transactions');
$txs = $this->Transactions->find()->select(['id', 'Value' => 'value', 'Hash' => 'hash', 'InputCount' => 'input_count', 'OutputCount' => 'output_count', 'TxTime' => 'transaction_time'])->order(['TxTime' => 'desc'])->limit(10);
$this->_jsonResponse(['success' => true, 'txs' => $txs]);
} }
protected function _gettxoutsetinfo() { protected function _gettxoutsetinfo() {
@ -742,9 +666,9 @@ class MainController extends AppController {
// Get the max height block // Get the max height block
$height = 0; $height = 0;
$difficulty = 0; $difficulty = 0;
$highestBlock = $this->Blocks->find()->select(['Height', 'Difficulty'])->order(['Height' => 'desc'])->first(); $highestBlock = $this->Blocks->find()->select(['height', 'difficulty'])->order(['height' => 'desc'])->first();
$height = $highestBlock->Height; $height = $highestBlock->height;
$difficulty = $highestBlock->Difficulty; $difficulty = $highestBlock->difficulty;
$lbcUsdPrice = $this->_getLatestPrice(); $lbcUsdPrice = $this->_getLatestPrice();
// Calculate hash rate // Calculate hash rate
@ -761,13 +685,12 @@ class MainController extends AppController {
public function apirecentblocks() { public function apirecentblocks() {
$this->autoRender = false; $this->autoRender = false;
$this->loadModel('Blocks'); $this->loadModel('Blocks');
$blocks = $this->Blocks->find()->select(['Difficulty', 'Hash', 'Height', 'TransactionHashes', 'BlockTime', 'BlockSize'])-> $blocks = $this->Blocks->find()->select(['Difficulty' => 'difficulty', 'Hash' => 'hash', 'Height' => 'height', 'transaction_hashes', 'BlockTime' => 'block_time', 'BlockSize' => 'block_size'])->order(['Height' => 'desc'])->limit(6)->toArray();
order(['Height' => 'desc'])->limit(6)->toArray();
for ($i = 0; $i < count($blocks); $i++) { for ($i = 0; $i < count($blocks); $i++) {
$tx_hashes = json_decode($blocks[$i]->TransactionHashes); $tx_hashes = preg_split('#,#', $blocks[$i]->transaction_hashes);
$blocks[$i]->TransactionCount = count($tx_hashes); $blocks[$i]->TransactionCount = count($tx_hashes);
$blocks[$i]->Difficulty = number_format($blocks[$i]->Difficulty, 2, '.', ''); $blocks[$i]->Difficulty = number_format($blocks[$i]->Difficulty, 2, '.', '');
unset($blocks[$i]->TransactionHashes); unset($blocks[$i]->transaction_hashes);
} }
return $this->_jsonResponse(['success' => true, 'blocks' => $blocks]); return $this->_jsonResponse(['success' => true, 'blocks' => $blocks]);
} }
@ -816,13 +739,13 @@ class MainController extends AppController {
} }
// check if the tag is taken // check if the tag is taken
$addrTag = $this->Addresses->find()->select(['Id'])->where(['LOWER(Tag)' => strtolower($entity->Tag)])->first(); $addrTag = $this->Addresses->find()->select(['id'])->where(['LOWER(Tag)' => strtolower($entity->Tag)])->first();
if ($addrTag) { if ($addrTag) {
return $this->_jsonError('Oops! The tag is already taken. Please specify a different tag.', 400); return $this->_jsonError('Oops! The tag is already taken. Please specify a different tag.', 400);
} }
// check for existing verification // check for existing verification
$exist = $this->TagAddressRequests->find()->select(['Id'])->where(['Address' => $base58address, 'IsVerified' => 0])->first(); $exist = $this->TagAddressRequests->find()->select(['id'])->where(['Address' => $base58address, 'IsVerified' => 0])->first();
if ($exist) { if ($exist) {
return $this->_jsonError('Oops! There is a pending tag verification for this address.', 400); return $this->_jsonError('Oops! There is a pending tag verification for this address.', 400);
} }
@ -843,15 +766,12 @@ class MainController extends AppController {
return $this->_jsonError('Base58 address not specified.', 400); return $this->_jsonError('Base58 address not specified.', 400);
} }
// TODO: Add unconfirmed_balance to response $address = $this->Addresses->find()->select(['id', 'balance'])->where(['address' => $base58address])->first();
$result = $this->Addresses->find()->select(['Balance'])->where(['Address' => $base58address])->first(); if (!$address) {
if (!$result) { return $this->_jsonError('Could not find address.', 400);
// Return 0 for address that does not exist?
$result = new \stdClass();
$result->Balance = 0;
} }
return $this->_jsonResponse(['success' => true, ['balance' => ['confirmed' => $result->Balance, 'unconfirmed' => 0]]]); return $this->_jsonResponse(['success' => true, ['balance' => ['confirmed' => $address->balance, 'unconfirmed' => 0]]]);
} }
public function apiaddrutxo($base58address = null) { public function apiaddrutxo($base58address = null) {
@ -863,7 +783,7 @@ class MainController extends AppController {
} }
$arr = explode(',', $base58address); $arr = explode(',', $base58address);
$addresses = $this->Addresses->find()->select(['Id'])->where(['Address IN' => $arr])->toArray(); $addresses = $this->Addresses->find()->select(['id'])->where(['address IN' => $arr])->toArray();
if (count($addresses) == 0) { if (count($addresses) == 0) {
return $this->_jsonError('No base58 address matching the specified parameter was found.', 404); return $this->_jsonError('No base58 address matching the specified parameter was found.', 404);
} }
@ -871,74 +791,128 @@ class MainController extends AppController {
$addressIds = []; $addressIds = [];
$params = []; $params = [];
foreach ($addresses as $address) { foreach ($addresses as $address) {
$addressIds[] = $address->Id; $addressIds[] = $address->id;
$params[] = '?'; $params[] = '?';
} }
// Get the unspent outputs for the address // Get the unspent outputs for the address
$conn = ConnectionManager::get('default'); $conn = ConnectionManager::get('default');
$stmt = $conn->execute(sprintf( $stmt = $conn->execute(sprintf(
'SELECT T.Hash AS TransactionHash, O.Vout, O.Value, O.Addresses, O.ScriptPubKeyAsm, O.ScriptPubKeyHex, O.Type, O.RequiredSignatures, B.Confirmations ' . 'SELECT T.hash AS transaction_hash, O.vout, O.value, O.address_list, O.script_pub_key_asm, O.script_pub_key_hex, O.type, O.required_signatures, B.confirmations ' .
'FROM Transactions T ' . 'FROM transaction T ' .
'JOIN Outputs O ON O.TransactionId = T.Id ' . 'JOIN output O ON O.transaction_id = T.id ' .
'JOIN Blocks B ON B.Hash = T.BlockHash ' . 'JOIN block B ON B.hash = T.block_hash_id ' .
'WHERE O.Id IN (SELECT OutputId FROM OutputsAddresses WHERE AddressId IN (%s)) AND O.IsSpent <> 1 ORDER BY T.TransactionTime ASC', implode(',', $params)), $addressIds); 'WHERE O.id IN (SELECT O2.id FROM output O2 WHERE address_id IN (%s)) AND O.is_spent <> 1 ORDER BY T.transaction_time ASC', implode(',', $params)), $addressIds);
$outputs = $stmt->fetchAll(\PDO::FETCH_OBJ); $outputs = $stmt->fetchAll(\PDO::FETCH_OBJ);
$utxo = []; $utxo = [];
foreach ($outputs as $out) { foreach ($outputs as $out) {
$utxo[] = [ $utxo[] = [
'transaction_hash' => $out->TransactionHash, 'transaction_hash' => $out->transaction_hash,
'output_index' => $out->Vout, 'output_index' => $out->vout,
'value' => (int) bcmul($out->Value, 100000000), 'value' => (int) bcmul($out->value, 100000000),
'addresses' => json_decode($out->Addresses), 'addresses' => json_decode($out->address_list),
'script' => $out->ScriptPubKeyAsm, 'script' => $out->script_pub_key_asm,
'script_hex' => $out->ScriptPubKeyHex, 'script_hex' => $out->script_pub_key_hex,
'script_type' => $out->Type, 'script_type' => $out->type,
'required_signatures' => (int) $out->RequiredSignatures, 'required_signatures' => (int) $out->required_signatures,
'spent' => false, 'spent' => false,
'confirmations' => (int) $out->Confirmations 'confirmations' => (int) $out->confirmations
]; ];
} }
return $this->_jsonResponse(['success' => true, 'utxo' => $utxo]); return $this->_jsonResponse(['success' => true, 'utxo' => $utxo]);
} }
public function apiutxosupply() { public function apiutxosupply() {
$this->autoRender = false; $this->autoRender = false;
$this->loadModel('Addresses'); $this->loadModel('Addresses');
$circulating = 0; $circulating = 0;
$reservedcommunity = 0;
$reservedoperational = 0;
$reservedinstitutional = 0;
$reservedtotal = 0;
$circulating = 0;
$txoutsetinfo = $this->_gettxoutsetinfo(); $txoutsetinfo = $this->_gettxoutsetinfo();
$reservedcommunity = $this->Addresses->find()->select(['Balance'])->where(['Address =' => 'rFLUohPG4tP3gZHYoyhvADCtrDMiaYb7Qd'])->first();
$reservedoperational = $this->Addresses->find()->select(['Balance'])->where(['Address =' => 'r9PGXsejVJb9ZfMf3QVdDEJCzxkd9JLxzL'])->first();
$reservedinstitutional = $this->Addresses->find()->select(['Balance'])->where(['Address =' => 'r9srwX7DEN7Mex3a8oR1mKSqQmLBizoJvi'])->first();
//aux is the address of hot wallets and where some of the LBRY operational fund are, but not sold on market.
$reservedaux = $this->Addresses->find()->select(['Balance'])->where(['Address =' => 'bRo4FEeqqxY7nWFANsZsuKEWByEgkvz8Qt'])->first() +
$this->Addresses->find()->select(['Balance'])->where(['Address =' => 'bU2XUzckfpdEuQNemKvhPT1gexQ3GG3SC2'])->first() +
$this->Addresses->find()->select(['Balance'])->where(['Address =' => 'bay3VA6YTQBL4WLobbG7CthmoGeUKXuXkD'])->first() +
$this->Addresses->find()->select(['Balance'])->where(['Address =' => 'bLPbiXBp6Vr3NSnsHzDsLNzoy5o36re9Cz'])->first() +
$this->Addresses->find()->select(['Balance'])->where(['Address =' => 'bMvUBo1h5WS46ThHtmfmXftz3z33VHL7wc'])->first() +
$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; $reservedcommunity = ['rFLUohPG4tP3gZHYoyhvADCtrDMiaYb7Qd'];
$reservedoperational = ['r9PGXsejVJb9ZfMf3QVdDEJCzxkd9JLxzL'];
$reservedinstitutional = ['r9srwX7DEN7Mex3a8oR1mKSqQmLBizoJvi'];
$reservedaux = ['bRo4FEeqqxY7nWFANsZsuKEWByEgkvz8Qt', 'bU2XUzckfpdEuQNemKvhPT1gexQ3GG3SC2', 'bay3VA6YTQBL4WLobbG7CthmoGeUKXuXkD', 'bLPbiXBp6Vr3NSnsHzDsLNzoy5o36re9Cz', 'bMvUBo1h5WS46ThHtmfmXftz3z33VHL7wc', 'bVUrbCK8hcZ5XWti7b9eNxKEBxzc1rr393', 'bZja2VyhAC84a9hMwT8dwTU6rDRXowrjxH', 'bCrboXVztuSbZzVToCWSsu1pEr2oxKHu9v', 'bMgqQqYfwzWWYBk5o5dBMXtCndVAoeqy6h'];
$allAddresses = array_merge($reservedcommunity, $reservedoperational, $reservedinstitutional, $reservedaux);
$reservedtotal = $this->Addresses->find()->select(['id', 'balance' => 'SUM(balance)'])->where(['Addresses.address IN' => $allAddresses])->first();
$circulating = $txoutsetinfo->total_amount - $reservedtotal; $circulating = $txoutsetinfo->total_amount - ($reservedtotal->balance);
return $this->_jsonResponse(['success' => true, 'utxosupply' => ['total' => $txoutsetinfo->total_amount, 'circulating' => $circulating]]); return $this->_jsonResponse(['success' => true, 'utxosupply' => ['total' => $txoutsetinfo->total_amount, 'circulating' => $circulating]]);
} }
protected function _formatHashRate($value) {
if ($value === 'N/A') {
return $value;
}
/*if ($value > 1000000000000) {
return number_format( $value / 1000000000000, 2, '.', '' ) . ' TH';
}*/
if ($value > 1000000000) {
return number_format( $value / 1000000000, 2, '.', '' ) . ' GH/s';
}
if ($value > 1000000) {
return number_format( $value / 1000000, 2, '.', '' ) . ' MH/s';
}
if ($value > 1000) {
return number_format( $value / 1000, 2, '.', '' ) . ' KH/s';
}
return number_format($value) . ' H/s';
}
public static function curl_get($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
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);
}
return $response;
}
private function _gethashrate() {
$req = ['method' => 'getnetworkhashps', 'params' => []];
try {
$res = json_decode(self::curl_json_post(self::$rpcurl, json_encode($req)));
if (!isset($res->result)) {
return 0;
}
return $res->result;
} catch (\Exception $e) {
return 'N/A';
}
}
// private function _gettxoutsetinfo() {
// $req = ['method' => 'gettxoutsetinfo', 'params' => []];
// try {
// $res = json_decode(self::curl_json_post(self::$rpcurl, json_encode($req)));
// if (!isset($res->result)) {
// return 0;
// }
// return $res->result;
// } catch (\Exception $e) {
// return 'N/A';
// }
// }
private static function curl_json_post($url, $data, $headers = []) { private static function curl_json_post($url, $data, $headers = []) {
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);

View file

@ -6,30 +6,30 @@ use Cake\ORM\Entity;
class Claim extends Entity { class Claim extends Entity {
function getLbryLink() { function getLbryLink() {
$link = $this->Name; $link = $this->name;
if (isset($this->Publisher->Name)) { if (isset($this->publisher)) {
$link = $this->Publisher->Name . '/' . $link; $link = $this->publisher . '/' . $link;
} }
$link = 'lbry://' . $link; $link = 'lbry://' . $link;
return $link; return $link;
} }
function getExplorerLink() { function getExplorerLink() {
$link = '/claims/' . $this->ClaimId; $link = '/claims/' . $this->claim_id;
return $link; return $link;
} }
function getContentTag() { function getContentTag() {
$ctTag = null; $ctTag = null;
if (substr($this->ContentType, 0, 5) === 'audio') { if (substr($this->content_type, 0, 5) === 'audio') {
$ctTag = 'audio'; $ctTag = 'audio';
} else if (substr($this->ContentType, 0, 5) === 'video') { } else if (substr($this->content_type, 0, 5) === 'video') {
$ctTag = 'video'; $ctTag = 'video';
} else if (substr($this->ContentType, 0, 5) === 'image') { } else if (substr($this->content_type, 0, 5) === 'image') {
$ctTag = 'image'; $ctTag = 'image';
} }
if (!$ctTag && $this->ClaimType == 1) { if (!$ctTag && $this->claim_type == 2) {
$ctTag = 'identity'; $ctTag = 'identity';
} }
return $ctTag; return $ctTag;
@ -37,11 +37,11 @@ class Claim extends Entity {
function getAutoThumbText() { function getAutoThumbText() {
$autoThumbText = ''; $autoThumbText = '';
if ($this->ClaimType == 1) { if ($this->claim_type == 2) {
$autoThumbText = strtoupper(substr($this->Name, 1, min( strlen($this->Name), 3 ))); $autoThumbText = strtoupper(substr($this->name, 1, min(strlen($this->name), 10)));
} else { } else {
$str = (strlen(trim($this->Title)) > 0) ? $this->Title : $this->Name; $str = (strlen(trim($this->title)) > 0) ? $this->title : $this->name;
$autoThumbText = strtoupper(substr($str, 0, min (strlen($str), 2 ))); $autoThumbText = strtoupper(substr($str, 0, min(strlen($str), 5)));
} }
return $autoThumbText; return $autoThumbText;
} }

View file

@ -5,7 +5,7 @@ namespace App\Model\Entity;
use Cake\ORM\Entity; use Cake\ORM\Entity;
class PriceHistory extends Entity { class PriceHistory extends Entity {
public $useDbConfig = 'localdb';
} }
?> ?>

View file

@ -3,9 +3,9 @@
namespace App\Model\Entity; namespace App\Model\Entity;
use Cake\ORM\Entity; use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;
class Transaction extends Entity { class Transaction extends Entity {
} }
?> ?>

View file

@ -4,8 +4,7 @@ namespace App\Model\Entity;
use Cake\ORM\Entity; use Cake\ORM\Entity;
class ClaimStream extends Entity { class TransactionAddress extends Entity {
} }
?> ?>

View file

@ -8,8 +8,8 @@ class AddressesTable extends Table {
public function initialize(array $config) { public function initialize(array $config) {
parent::initialize($config); parent::initialize($config);
$this->primaryKey('Id'); $this->setPrimaryKey('id');
$this->table('Addresses'); $this->setTable('address');
$this->addBehavior('SimpleAudit'); $this->addBehavior('SimpleAudit');
} }

View file

@ -8,8 +8,8 @@ class BlocksTable extends Table {
public function initialize(array $config) { public function initialize(array $config) {
parent::initialize($config); parent::initialize($config);
$this->primaryKey('Id'); $this->setPrimaryKey('id');
$this->table('Blocks'); $this->setTable('block');
$this->addBehavior('SimpleAudit'); $this->addBehavior('SimpleAudit');
} }

View file

@ -1,18 +0,0 @@
<?php
namespace App\Model\Table;
use Cake\ORM\Table;
class ClaimStreamsTable extends Table {
public function initialize(array $config) {
parent::initialize($config);
$this->primaryKey('Id');
$this->table('ClaimStreams');
//$this->addBehavior('SimpleAudit');
}
}
?>

View file

@ -8,29 +8,20 @@ class ClaimsTable extends Table {
public function initialize(array $config) { public function initialize(array $config) {
parent::initialize($config); parent::initialize($config);
$this->primaryKey('Id'); $this->setPrimaryKey('id');
$this->table('Claims'); $this->setTable('claim');
//$this->addBehavior('SimpleAudit'); //$this->addBehavior('SimpleAudit');
$this->addAssociations([ $this->addAssociations([
'belongsTo' => [ 'belongsTo' => [
'Publisher' => [ 'publisher' => [
'className' => 'App\Model\Table\ClaimsTable', 'className' => 'App\Model\Table\ClaimsTable',
'foreignKey' => 'PublisherId', 'foreignKey' => 'publisher_id',
'bindingKey' => 'ClaimId', 'bindingKey' => 'claim_id',
'propertyName' => 'Publisher' 'propertyName' => 'publisher'
]
],
'hasOne' => [
'Stream' => [
'className' => 'App\Model\Table\ClaimStreamsTable',
'foreignKey' => 'Id',
'bindingKey' => 'Id',
'propertyName' => 'Stream'
] ]
] ]
]); ]);
} }
} }
?> ?>

View file

@ -8,19 +8,19 @@ class InputsTable extends Table {
public function initialize(array $config) { public function initialize(array $config) {
parent::initialize($config); parent::initialize($config);
$this->primaryKey('Id'); $this->setPrimaryKey('id');
$this->table('Inputs'); $this->setTable('input');
$this->addBehavior('SimpleAudit'); $this->addBehavior('SimpleAudit');
$this->addAssociations([ $this->addAssociations([
'belongsToMany' => [ 'belongsToMany' => [
'InputAddresses' => [ 'input_addresses' => [
'className' => 'App\Model\Table\AddressesTable', 'className' => 'App\Model\Table\AddressesTable',
'joinTable' => 'InputsAddresses', 'joinTable' => 'input_addresses',
'foreignKey' => 'InputId', 'foreignKey' => 'input_id',
'targetForeignKey' => 'AddressId', 'targetForeignKey' => 'address_id',
'propertyName' => 'InputAddresses' 'propertyName' => 'input_addresses'
] ]
] ]
]); ]);

View file

@ -8,26 +8,26 @@ class OutputsTable extends Table {
public function initialize(array $config) { public function initialize(array $config) {
parent::initialize($config); parent::initialize($config);
$this->primaryKey('Id'); $this->setPrimaryKey('id');
$this->table('Outputs'); $this->setTable('output');
$this->addBehavior('SimpleAudit'); $this->addBehavior('SimpleAudit');
$this->addAssociations([ $this->addAssociations([
'belongsTo' => [ 'belongsTo' => [
'SpendInput' => [ 'spend_input' => [
'className' => 'App\Model\Table\InputsTable', 'className' => 'App\Model\Table\InputsTable',
'foreignKey' => 'SpentByInputId', 'foreignKey' => 'spent_by_input_id',
'propertyName' => 'SpendInput' 'propertyName' => 'spend_input'
] ]
], ],
'belongsToMany' => [ 'belongsToMany' => [
'OutputAddresses' => [ 'output_addresses' => [
'className' => 'App\Model\Table\AddressesTable', 'className' => 'App\Model\Table\AddressesTable',
'joinTable' => 'OutputsAddresses', 'joinTable' => 'output_addresses',
'foreignKey' => 'OutputId', 'foreignKey' => 'output_id',
'targetForeignKey' => 'AddressId', 'targetForeignKey' => 'address_id',
'propertyName' => 'OutputAddresses' 'propertyName' => 'output_addresses'
] ]
] ]
]); ]);

View file

@ -8,8 +8,8 @@ class PriceHistoryTable extends Table {
public function initialize(array $config) { public function initialize(array $config) {
parent::initialize($config); parent::initialize($config);
$this->primaryKey('Id'); $this->setPrimaryKey('Id');
$this->table('PriceHistory'); $this->setTable('PriceHistory');
} }
} }

View file

@ -8,8 +8,8 @@ class TagAddressRequestsTable extends Table {
public function initialize(array $config) { public function initialize(array $config) {
parent::initialize($config); parent::initialize($config);
$this->primaryKey('Id'); $this->setPrimaryKey('Id');
$this->table('TagAddressRequests'); $this->setTable('TagAddressRequests');
$this->addBehavior('SimpleAudit'); $this->addBehavior('SimpleAudit');
} }

View file

@ -0,0 +1,16 @@
<?php
namespace App\Model\Table;
use Cake\ORM\Table;
class TransactionAddressesTable extends Table {
public function initialize(array $config) {
parent::initialize($config);
$this->setTable('transaction_address');
$this->addBehavior('SimpleAudit');
}
}
?>

View file

@ -8,8 +8,8 @@ class TransactionsTable extends Table {
public function initialize(array $config) { public function initialize(array $config) {
parent::initialize($config); parent::initialize($config);
$this->primaryKey('Id'); $this->setPrimaryKey('id');
$this->table('Transactions'); $this->setTable('transaction');
$this->addBehavior('SimpleAudit'); $this->addBehavior('SimpleAudit');
} }

View file

@ -127,7 +127,7 @@ class AuxShell extends Shell {
public function pricehistory() { public function pricehistory() {
self::lock('pricehistory'); self::lock('pricehistory');
$conn = ConnectionManager::get('default'); $conn = ConnectionManager::get('localdb');
$redis = new \Predis\Client(Configure::read('Redis.Url')); $redis = new \Predis\Client(Configure::read('Redis.Url'));
try { try {

View file

@ -0,0 +1,76 @@
<?php
$autoThumbText = $claim->getAutoThumbText();
$cost = '';
if (isset($claim->price) && $claim->price > 0) {
$cost = $this->Amount->formatCurrency($claim->price) . ' LBC';
} else if (isset($claim->fee) && strtolower($claim->fee_currency) === 'lbc') {
$cost = $this->Amount->formatCurrency($claim->fee) . ' LBC';
}
$a = ['purple', 'orange', 'blue', 'teal', 'green', 'yellow'];
// content type
$ctTag = $claim->getContentTag();
?>
<div data-id="<?php echo $claim->claim_id ?>" class="claim-grid-item<?php if ($idx % 3 == 0): ?> last-item<?php endif; ?><?php if ($last_row): ?> last-row<?php endif; ?>">
<?php if (strlen(trim($cost)) > 0): ?>
<div class="price-tag"><?php echo $cost ?></div>
<?php endif; ?>
<div class="tags">
<?php if ($claim->bid_state == 'Controlling'): ?>
<div class="bid-state">Controlling</div>
<?php endif; ?>
<?php if ($ctTag): ?>
<div class="content-type"><?php echo strtoupper($ctTag) ?></div>
<?php endif; ?>
<?php if ($claim->is_nsfw): ?>
<div class="nsfw">NSFW</div>
<?php endif; ?>
</div>
<div data-autothumb="<?php echo $autoThumbText ?>" class="thumbnail <?php echo $a[mt_rand(0, count($a) - 1)] ?>">
<?php if (!$claim->is_nsfw && strlen(trim($claim->thumbnail_url)) > 0): ?>
<img src="<?php echo htmlspecialchars($claim->thumbnail_url) ?>" alt="" />
<?php else: ?>
<div class="autothumb"><?php echo $autoThumbText ?></div>
<?php endif; ?>
</div>
<div class="metadata">
<div class="title" title="<?php echo $claim->claim_type == 1 ? $claim->name : ((strlen(trim($claim->title)) > 0) ? $claim->title : '') ?>"><?php echo $claim->claim_type == 1 ? $claim->name : ((strlen(trim($claim->title)) > 0) ? $claim->title : '<em>No Title</em>') ?></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>
<div class="label half-width">Transaction</div>
<div class="label half-width">Created</div>
<div class="value half-width"><a href="/tx/<?php echo $claim->transaction_hash_id ?>#output-<?php echo $claim->vout ?>" title="<?php echo $claim->transaction_hash_id ?>"><?php echo $claim->transaction_hash_id ?></a></div>
<div class="value half-width" title="<?php echo $claim->created_at->format('j M Y H:i:s') ?> UTC">
<?php echo \Carbon\Carbon::createFromTimestamp($claim->created_at->format('U'))->diffForHumans(); ?>
</div>
<div class="clear spacer"></div>
<?php if ($claim->claim_type == 1): ?>
<div class="label half-width">Content Type</div>
<div class="label half-width">Language</div>
<div class="value half-width" title="<?php echo $claim->content_type ?>"><?php echo $claim->content_type ?></div>
<div class="value half-width" title="<?php echo $claim->language == 'en' ? 'English' : $claim->language ?>"><?php echo $claim->language == 'en' ? 'English' : $claim->language ?></div>
<div class="clear spacer"></div>
<!--<div class="label half-width">Author</div>
<div class="label half-width">License</div>-->
<!--<div class="value half-width" title="<?php echo strlen(trim($claim->author)) > 0 ? $claim->author : '<em>Unspecified</em>' ?>"><?php echo strlen(trim($claim->author)) > 0 ? $claim->author : '<em>Unspecified</em>' ?></div>
<div class="value half-width" title="<?php echo strlen(trim($claim->license)) > 0 ? $claim->license : '' ?>">
<?php if (strlen(trim($claim->LicenseUrl)) > 0): ?><a href="<?php echo $claim->LicenseUrl ?>" rel="nofollow" target="_blank"><?php endif; ?>
<?php echo strlen(trim($claim->License)) > 0 ? $claim->License : '<em>Unspecified</em>' ?>
<?php if (strlen(trim($claim->LicenseUrl))): ?></a><?php endif; ?>
</div>
-->
<?php endif; ?>
</div>
</div>

View file

@ -1,4 +1,4 @@
<?php $this->assign('title', 'Address ' . $address->Address) ?> <?php $this->assign('title', 'Address ' . $address->address) ?>
<?php $this->start('script') ?> <?php $this->start('script') ?>
<script type="text/javascript"> <script type="text/javascript">
@ -40,7 +40,7 @@
var btnClose = $('.btn-close'); var btnClose = $('.btn-close');
$.ajax({ $.ajax({
url: '/api/v1/address/<?php echo $address->Address ?>/tag', url: '/api/v1/address/<?php echo $address->address ?>/tag',
type: 'post', type: 'post',
dataType: 'json', dataType: 'json',
data: req, data: req,
@ -87,7 +87,7 @@
<div class="address-head"> <div class="address-head">
<h3>LBRY Address</h3> <h3>LBRY Address</h3>
<h4><?php echo $address->Address ?></h4> <h4><?php echo $address->address ?></h4>
<?php if (isset($address->Tag) && strlen(trim($address->Tag)) > 0): ?> <?php if (isset($address->Tag) && strlen(trim($address->Tag)) > 0): ?>
<?php if (strlen(trim($address->TagUrl)) > 0): ?><a href="<?php echo $address->TagUrl ?>" target="_blank" rel="nofollow"><?php echo $address->Tag ?></a><?php else: echo $address->Tag; endif; ?> <?php if (strlen(trim($address->TagUrl)) > 0): ?><a href="<?php echo $address->TagUrl ?>" target="_blank" rel="nofollow"><?php echo $address->Tag ?></a><?php else: echo $address->Tag; endif; ?>
<?php endif; ?> <?php endif; ?>
@ -95,7 +95,7 @@
<div class="address-subhead"> <div class="address-subhead">
<div class="address-qr"> <div class="address-qr">
<img src="/qr/lbry%3A<?php echo $address->Address ?>" alt="lbry:<?php echo $address->Address ?>" /> <img src="/qr/lbry%3A<?php echo $address->address ?>" alt="lbry:<?php echo $address->address ?>" />
</div> </div>
<div class="address-summary"> <div class="address-summary">
@ -152,14 +152,14 @@
<?php foreach ($recentTxs as $tx): ?> <?php foreach ($recentTxs as $tx): ?>
<tr> <tr>
<td class="w125"><?php if ($tx->Height === null): ?><em>Unconfirmed</em><?php else: ?><a href="/blocks/<?php echo $tx->Height ?>"><?php echo $tx->Height ?></a><?php endif; ?></td> <td class="w125"><?php if ($tx->height === null): ?><em>Unconfirmed</em><?php else: ?><a href="/blocks/<?php echo $tx->height ?>"><?php echo $tx->height ?></a><?php endif; ?></td>
<td class="w250"><div><a href="/tx/<?php echo $tx->Hash ?>?address=<?php echo $address->Address ?>#<?php echo $address->Address ?>"><?php echo $tx->Hash ?></a></div></td> <td class="w250"><div><a href="/tx/<?php echo $tx->hash ?>?address=<?php echo $address->address ?>#<?php echo $address->address ?>"><?php echo $tx->hash ?></a></div></td>
<td><?php echo \DateTime::createFromFormat('U', $tx->TxTime)->format('d M Y H:i:s') . ' UTC'; ?></td> <td><?php echo \DateTime::createFromFormat('U', $tx->transaction_time)->format('d M Y H:i:s') . ' UTC'; ?></td>
<td class="right"><?php echo number_format($tx->Confirmations, 0, '', ',') ?></td> <td class="right"><?php echo number_format($tx->confirmations, 0, '', ',') ?></td>
<td class="right"><?php echo $tx->InputCount ?></td> <td class="right"><?php echo $tx->input_count ?></td>
<td class="right"><?php echo $tx->OutputCount ?></td> <td class="right"><?php echo $tx->output_count ?></td>
<td class="right<?php echo ' ' . ($tx->DebitAmount > 0 && $tx->CreditAmount > 0 ? 'diff' : ($tx->DebitAmount > 0 ? 'debit' : 'credit')) ?>"> <td class="right<?php echo ' ' . ($tx->debit_amount > 0 && $tx->credit_amount > 0 ? 'diff' : ($tx->debit_amount > 0 ? 'debit' : 'credit')) ?>">
<?php echo number_format($tx->CreditAmount - $tx->DebitAmount, 8, '.', ',') ?> LBC <?php echo number_format($tx->credit_amount - $tx->debit_amount, 8, '.', ',') ?> LBC
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>

View file

@ -21,21 +21,19 @@
</script> </script>
<?php $this->end(); ?> <?php $this->end(); ?>
<?php $this->assign('title', 'Block Height ' . $block->Height) ?> <?php $this->assign('title', 'Block Height ' . $block->height) ?>
<div class="block-head"> <div class="block-head">
<h3>LBRY Block <?php echo $block->Height ?></h3> <h3>LBRY Block <?php echo $block->height ?></h3>
<h4><?php echo $block->Hash ?></h4> <h4><?php echo $block->hash ?></h4>
</div> </div>
<div class="block-nav"> <div class="block-nav">
<?php if (strlen(trim($block->PreviousBlockHash)) > 0): ?> <?php if ($block->height > 0): ?>
<a class="btn btn-prev" href="/blocks/<?php echo ($block->Height - 1); ?>">&laquo; Previous Block</a> <a class="btn btn-prev" href="/blocks/<?php echo ($block->height - 1); ?>">&laquo; Previous Block</a>
<?php endif; ?> <?php endif; ?>
<?php if (strlen(trim($block->NextBlockHash)) > 0): ?> <a class="btn btn-next" href="/blocks/<?php echo ($block->height + 1); ?>">Next Block &raquo;</a>
<a class="btn btn-next" href="/blocks/<?php echo ($block->Height + 1); ?>">Next Block &raquo;</a>
<?php endif; ?>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
@ -47,44 +45,46 @@
<div class="label half-width">Block Size (bytes)</div> <div class="label half-width">Block Size (bytes)</div>
<div class="label half-width">Block Time</div> <div class="label half-width">Block Time</div>
<div class="value half-width"><?php echo number_format($block->BlockSize, 0, '', ',') ?></div> <div class="value half-width"><?php echo number_format($block->block_size, 0, '', ',') ?></div>
<div class="value half-width"><?php echo \DateTime::createFromFormat('U', $block->BlockTime)->format('j M Y H:i:s') . ' UTC' ?></div> <div class="value half-width"><?php echo \DateTime::createFromFormat('U', $block->block_time)->format('j M Y H:i:s') . ' UTC' ?></div>
<div class="clear spacer"></div> <div class="clear spacer"></div>
<div class="label half-width">Bits</div> <div class="label half-width">Bits</div>
<div class="label half-width">Confirmations</div> <div class="label half-width">Confirmations</div>
<div class="value half-width"><?php echo $block->Bits ?></div> <div class="value half-width"><?php echo $block->bits ?></div>
<div class="value half-width"><?php echo number_format($block->Confirmations, 0, '', ',') ?></div> <div class="value half-width"><?php echo number_format($block->confirmations, 0, '', ',') ?></div>
<div class="clear spacer"></div> <div class="clear spacer"></div>
<div class="label half-width">Difficulty</div> <div class="label half-width">Difficulty</div>
<div class="label half-width">Nonce</div> <div class="label half-width">Nonce</div>
<div class="value half-width"><?php echo $this->Amount->format($block->Difficulty, '') ?></div> <div class="value half-width"><?php echo $this->Amount->format($block->difficulty, '') ?></div>
<div class="value half-width"><?php echo $block->Nonce ?></div> <div class="value half-width"><?php echo $block->nonce ?></div>
<div class="clear spacer"></div> <div class="clear spacer"></div>
<div class="label">Chainwork</div> <div class="value"><?php echo $block->Chainwork ?></div> <div class="label">Chainwork</div> <div class="value"><?php echo $block->chainwork ?></div>
<div class="spacer"></div> <div class="spacer"></div>
<div class="label">MerkleRoot</div> <div class="value"><?php echo $block->MerkleRoot ?></div> <div class="label">MerkleRoot</div> <div class="value"><?php echo $block->merkle_root ?></div>
<div class="spacer"></div> <div class="spacer"></div>
<div class="label">NameClaimRoot</div> <div class="value"><?php echo $block->NameClaimRoot ?></div> <div class="label">NameClaimRoot</div> <div class="value"><?php echo $block->name_claim_root ?></div>
<!--
<div class="spacer"></div> <div class="spacer"></div>
<div class="label">Target</div> <div class="value"><?php echo $block->Target ?></div> <div class="label">Target</div> <div class="value"><?php echo $block->Target ?></div>
-->
<div class="spacer"></div> <div class="spacer"></div>
<div class="label">Version</div> <div class="value"><?php echo $block->Version ?></div> <div class="label">Version</div> <div class="value"><?php echo $block->version ?></div>
</div> </div>
<div class="block-transactions"> <div class="block-transactions">
@ -109,10 +109,10 @@
<?php foreach ($blockTxs as $tx): ?> <?php foreach ($blockTxs as $tx): ?>
<tr> <tr>
<td class="w300"><div><a href="/tx/<?php echo $tx->Hash ?>"><?php echo $tx->Hash ?></a></div></td> <td class="w300"><div><a href="/tx/<?php echo $tx->hash ?>"><?php echo $tx->hash ?></a></div></td>
<td class="right"><?php echo $tx->InputCount ?></td> <td class="right"><?php echo $tx->input_count ?></td>
<td class="right"><?php echo $tx->OutputCount ?></td> <td class="right"><?php echo $tx->output_count ?></td>
<td class="right"><div title="<?php echo $tx->Value ?> LBC"><?php echo $this->Amount->formatCurrency($tx->Value) ?> LBC</div></td> <td class="right"><div title="<?php echo $tx->value ?> LBC"><?php echo $this->Amount->formatCurrency($tx->value) ?> LBC</div></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
@ -181,13 +181,13 @@
<tbody> <tbody>
<?php foreach ($blocks as $block): ?> <?php foreach ($blocks as $block): ?>
<tr> <tr>
<td class="right"><a href="/blocks/<?php echo $block->Height ?>"><?php echo $block->Height ?></a></td> <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="pad-left"><?php echo number_format($block->difficulty, 8, '.', '') ?></td>
<td class="right"><?php echo number_format((($currentBlock->Height - $block->Height) + 1), 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 count(preg_split('#,#', $block->transaction_hashes)) ?></td>
<td class="right"><?php echo round($block->BlockSize / 1024, 2) . 'KB' ?></td> <td class="right"><?php echo round($block->block_size / 1024, 2) . 'KB' ?></td>
<td class="right pad-left"><?php echo $block->Nonce ?></td> <td class="right pad-left"><?php echo $block->nonce ?></td>
<td class="pad-left"><?php echo \DateTime::createFromFormat('U', $block->BlockTime)->format('d M Y H:i:s') ?> UTC</td> <td class="pad-left"><?php echo \DateTime::createFromFormat('U', $block->block_time)->format('d M Y H:i:s') ?> UTC</td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>

View file

@ -41,13 +41,13 @@
$a = ['purple', 'orange', 'blue', 'teal', 'green', 'yellow']; $a = ['purple', 'orange', 'blue', 'teal', 'green', 'yellow'];
$autoThumbText = $claim->getAutoThumbText(); $autoThumbText = $claim->getAutoThumbText();
$cost = 'Free'; $cost = 'Free';
if (isset($claim->Price) && $claim->Price > 0) { if (isset($claim->price) && $claim->price > 0) {
$cost = $this->Amount->formatCurrency($claim->Price) . ' LBC'; $cost = $this->Amount->formatCurrency($claim->price) . ' LBC';
} else if (isset($claim->Fee) && strtolower($claim->FeeCurrency) === 'lbc') { } else if (isset($claim->fee) && strtolower($claim->fee_currency) === 'lbc') {
$cost = $this->Amount->formatCurrency($claim->Fee) . ' LBC'; $cost = $this->Amount->formatCurrency($claim->fee) . ' LBC';
} }
$desc = $claim->Description; $desc = $claim->description;
if (strlen(trim($desc)) == 0) { if (strlen(trim($desc)) == 0) {
$desc = '<em>No description available.</em>'; $desc = '<em>No description available.</em>';
} else { } else {
@ -57,29 +57,29 @@ if (strlen(trim($desc)) == 0) {
?> ?>
<?php $this->assign('title', 'Claim &bull; ' . $claim->Name) ?> <?php $this->assign('title', 'Claim &bull; ' . $claim->name) ?>
<div class="claims-head"> <div class="claims-head">
<h3><a href="/claims">LBRY Claims</a> &bull; <?php echo $claim->Name ?></h3> <h3><a href="/claims">LBRY Claims</a> &bull; <?php echo $claim->name ?></h3>
<h4><?php echo $claim->ClaimId ?></h4> <h4><?php echo $claim->claim_id ?></h4>
</div> </div>
<div class="claims-body"> <div class="claims-body">
<div class="claim-info"> <div class="claim-info">
<div data-autothumb="<?php echo $autoThumbText ?>" class="thumbnail <?php echo $a[mt_rand(0, count($a) - 1)] ?>"> <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): ?> <?php if (!$claim->is_nsfw && strlen(trim($claim->thumbnail_url)) > 0): ?>
<img src="<?php echo htmlspecialchars($claim->ThumbnailUrl) ?>" alt="" /> <img src="<?php echo htmlspecialchars($claim->thumbnail_url) ?>" alt="" />
<?php else: ?> <?php else: ?>
<div class="autothumb"><?php echo $autoThumbText ?></div> <div class="autothumb"><?php echo $autoThumbText ?></div>
<?php endif; ?> <?php endif; ?>
</div> </div>
<div class="content"> <div class="content">
<?php if ($claim->ClaimType == 2): ?> <?php if ($claim->claim_type == 1): ?>
<div class="label">Published By</div> <div class="label">Published By</div>
<div class="value"> <div class="value">
<?php if (isset($claim->Publisher)): ?> <?php if (isset($claim->publisher)): ?>
<a href="lbry://<?php echo $claim->Publisher->Name ?>"><?php echo $claim->Publisher->Name ?></a> <a href="lbry://<?php echo $claim->publisher ?>"><?php echo $claim->publisher ?></a>
<?php else: ?> <?php else: ?>
<em>Anonymous</em> <em>Anonymous</em>
<?php endif; ?> <?php endif; ?>
@ -87,17 +87,17 @@ if (strlen(trim($desc)) == 0) {
<?php endif; ?> <?php endif; ?>
<div class="label">Created On</div> <div class="label">Created On</div>
<div class="value"><?php echo \DateTime::createFromFormat('U', $claim->TransactionTime > 0 ? $claim->TransactionTime : $claim->Created->format('U'))->format('j M Y H:i:s') ?> UTC</div> <div class="value"><?php echo \DateTime::createFromFormat('U', $claim->transaction_time > 0 ? $claim->transaction_time : $claim->created_at->format('U'))->format('j M Y H:i:s') ?> UTC</div>
<div class="label">Transaction ID</div> <div class="label">Transaction ID</div>
<div class="value"><a href="/tx/<?php echo $claim->TransactionHash ?>#output-<?php echo $claim->Vout ?>"><?php echo $claim->TransactionHash ?></a></div> <div class="value"><a href="/tx/<?php echo $claim->transaction_hash_id ?>#output-<?php echo $claim->vout ?>"><?php echo $claim->transaction_hash_id ?></a></div>
<?php if ($claim->ClaimType == 2): ?> <?php if ($claim->claim_type == 1): ?>
<div class="label half-width">Cost</div> <div class="label half-width">Cost</div>
<div class="label half-width">Safe for Work</div> <div class="label half-width">Safe for Work</div>
<div class="value half-width"><?php echo $cost ?></div> <div class="value half-width"><?php echo $cost ?></div>
<div class="value half-width"><?php echo $claim->IsNSFW ? 'No' : 'Yes' ?></div> <div class="value half-width"><?php echo $claim->is_nsfw ? 'No' : 'Yes' ?></div>
<div class="clear"></div> <div class="clear"></div>
<?php endif; ?> <?php endif; ?>
@ -105,11 +105,11 @@ if (strlen(trim($desc)) == 0) {
</div> </div>
<div class="claim-metadata"> <div class="claim-metadata">
<?php if ($claim->ClaimType == 1): ?> <?php if ($claim->claim_type == 2): ?>
<div class="title">Identity Claim</div> <div class="title">Identity Claim</div>
<div class="desc">This is an identity claim.</div> <div class="desc">This is an identity claim.</div>
<?php else: ?> <?php else: ?>
<div class="title"><?php echo $claim->Title ?></div> <div class="title"><?php echo $claim->title ?></div>
<div class="desc"><?php echo str_replace("\n", '<br />', $desc) ?></div> <div class="desc"><?php echo str_replace("\n", '<br />', $desc) ?></div>
<div class="details"> <div class="details">
@ -117,18 +117,22 @@ if (strlen(trim($desc)) == 0) {
<div class="label half-width">Content Type</div> <div class="label half-width">Content Type</div>
<div class="value half-width"><?php echo strlen(trim($claim->Author)) > 0 ? $claim->Author : '<em>Unspecified</em>' ?></div> <div class="value half-width"><?php echo strlen(trim($claim->author)) > 0 ? $claim->author : '<em>Unspecified</em>' ?></div>
<div class="value half-width"><?php echo strlen(trim($claim->ContentType)) > 0 ? $claim->ContentType : '<em>Unspecified</em>' ?></div> <div class="value half-width"><?php echo strlen(trim($claim->content_type)) > 0 ? $claim->content_type : '<em>Unspecified</em>' ?></div>
<!--
<div class="label half-width">License</div> <div class="label half-width">License</div>
<div class="label half-width">Language</div> -->
<div class="label">Language</div>
<div class="value half-width"<?php if(strlen(trim($claim->License)) > 0): ?> title="<?php echo $claim->License ?>"<?php endif; ?>> <!--
<?php if (strlen(trim($claim->LicenseUrl)) > 0): ?><a href="<?php echo $claim->LicenseUrl ?>" rel="nofollow" target="_blank"><?php endif; ?> <div class="value half-width"<?php if(strlen(trim($claim->license)) > 0): ?> title="<?php echo $claim->license ?>"<?php endif; ?>>
<?php if (strlen(trim($claim->license_url)) > 0): ?><a href="<?php echo $claim->LicenseUrl ?>" rel="nofollow" target="_blank"><?php endif; ?>
<?php echo strlen(trim($claim->License)) > 0 ? $claim->License : '<em>Unspecified</em>' ?> <?php echo strlen(trim($claim->License)) > 0 ? $claim->License : '<em>Unspecified</em>' ?>
<?php if (strlen(trim($claim->LicenseUrl))): ?></a><?php endif; ?> <?php if (strlen(trim($claim->LicenseUrl))): ?></a><?php endif; ?>
</div> </div>
<div class="value half-width"><?php echo strlen(trim($claim->Language)) > 0 ? ($claim->Language == 'en' ? 'English' : '') : '<em>Unspecified</em>' ?></div> -->
<div class="value half-width"><?php echo strlen(trim($claim->language)) > 0 ? ($claim->language == 'en' ? 'English' : '') : '<em>Unspecified</em>' ?></div>
</div> </div>
<?php endif; ?> <?php endif; ?>
<a href="<?php echo $claim->getLbryLink() ?>" class="open-lbry-link">Open in LBRY</a> <a href="<?php echo $claim->getLbryLink() ?>" class="open-lbry-link">Open in LBRY</a>
@ -140,7 +144,7 @@ if (strlen(trim($desc)) == 0) {
<?php if (count($moreClaims) > 0): ?> <?php if (count($moreClaims) > 0): ?>
<div class="more-claims"> <div class="more-claims">
<h4><?php echo isset($claim->Publisher) ? 'More from the publisher' : 'Published by this identity' ?></h4> <h4><?php echo isset($claim->publisher) ? 'More from the publisher' : 'Published by this identity' ?></h4>
<div class="claims-grid"> <div class="claims-grid">
<?php $idx = 1; $row = 1; $rowCount = ceil(count($moreClaims) / 3); <?php $idx = 1; $row = 1; $rowCount = ceil(count($moreClaims) / 3);
@ -150,80 +154,9 @@ if (strlen(trim($desc)) == 0) {
if ($idx % 3 == 0) { if ($idx % 3 == 0) {
$row++; $row++;
} }
echo $this->element('claimbox', array('claim' => $claim, 'idx' => $idx, 'last_row' => $last_row));
$autoThumbText = $claim->getAutoThumbText(); $idx++;
$cost = ''; endforeach; ?>
if (isset($claim->Price) && $claim->Price > 0) {
$cost = $this->Amount->formatCurrency($claim->Price) . ' LBC';
} else if (isset($claim->Fee) && strtolower($claim->FeeCurrency) === 'lbc') {
$cost = $this->Amount->formatCurrency($claim->Fee) . ' LBC';
}
// content type
$ctTag = $claim->getContentTag();
?>
<div data-id="<?php echo $claim->ClaimId ?>" class="claim-grid-item<?php if ($idx % 3 == 0): ?> last-item<?php endif; ?><?php if ($last_row): ?> last-row<?php endif; ?>">
<?php if (strlen(trim($cost)) > 0): ?>
<div class="price-tag"><?php echo $cost ?></div>
<?php endif; ?>
<div class="tags">
<?php if ($ctTag): ?>
<div class="content-type"><?php echo strtoupper($ctTag) ?></div>
<?php endif; ?>
<?php if ($claim->IsNSFW): ?>
<div class="nsfw">NSFW</div>
<?php endif; ?>
</div>
<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 htmlspecialchars($claim->ThumbnailUrl) ?>" alt="" />
<?php else: ?>
<div class="autothumb"><?php echo $autoThumbText ?></div>
<?php endif; ?>
</div>
<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 $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>
<div class="label half-width">Transaction</div>
<div class="label half-width">Created</div>
<div class="value half-width"><a href="/tx/<?php echo $claim->TransactionHash ?>#output-<?php echo $claim->Vout ?>" title="<?php echo $claim->TransactionHash ?>"><?php echo $claim->TransactionHash ?></a></div>
<div class="value half-width" title="<?php echo $claim->Created->format('j M Y H:i:s') ?> UTC">
<?php echo \Carbon\Carbon::createFromTimestamp($claim->Created->format('U'))->diffForHumans(); ?>
</div>
<div class="clear spacer"></div>
<?php if ($claim->ClaimType == 2): ?>
<div class="label half-width">Content Type</div>
<div class="label half-width">Language</div>
<div class="value half-width" title="<?php echo $claim->ContentType ?>"><?php echo $claim->ContentType ?></div>
<div class="value half-width" title="<?php echo $claim->Language == 'en' ? 'English' : $claim->Language ?>"><?php echo $claim->Language == 'en' ? 'English' : $claim->Language ?></div>
<div class="clear spacer"></div>
<div class="label half-width">Author</div>
<div class="label half-width">License</div>
<div class="value half-width" title="<?php echo strlen(trim($claim->Author)) > 0 ? $claim->Author : '<em>Unspecified</em>' ?>"><?php echo strlen(trim($claim->Author)) > 0 ? $claim->Author : '<em>Unspecified</em>' ?></div>
<div class="value half-width" title="<?php echo strlen(trim($claim->License)) > 0 ? $claim->License : '' ?>">
<?php if (strlen(trim($claim->LicenseUrl)) > 0): ?><a href="<?php echo $claim->LicenseUrl ?>" rel="nofollow" target="_blank"><?php endif; ?>
<?php echo strlen(trim($claim->License)) > 0 ? $claim->License : '<em>Unspecified</em>' ?>
<?php if (strlen(trim($claim->LicenseUrl))): ?></a><?php endif; ?>
</div>
<?php endif; ?>
</div>
</div>
<?php $idx++; endforeach; ?>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
</div> </div>
@ -252,78 +185,9 @@ if (strlen(trim($desc)) == 0) {
if ($idx % 3 == 0) { if ($idx % 3 == 0) {
$row++; $row++;
} }
$autoThumbText = $claim->getAutoThumbText(); echo $this->element('claimbox', array('claim' => $claim, 'idx' => $idx, 'last_row' => $last_row));
$cost = ''; $idx++;
if (isset($claim->Price) && $claim->Price > 0) { endforeach; ?>
$cost = $this->Amount->formatCurrency($claim->Price) . ' LBC';
} else if (isset($claim->Fee) && strtolower($claim->FeeCurrency) === 'lbc') {
$cost = $this->Amount->formatCurrency($claim->Fee) . ' LBC';
}
// content type
$ctTag = $claim->getContentTag();
?>
<div data-id="<?php echo $claim->ClaimId ?>" class="claim-grid-item<?php if ($idx % 3 == 0): ?> last-item<?php endif; ?><?php if ($last_row): ?> last-row<?php endif; ?>">
<?php if (strlen(trim($cost)) > 0): ?>
<div class="price-tag"><?php echo $cost ?></div>
<?php endif; ?>
<div class="tags">
<?php if ($ctTag): ?>
<div class="content-type"><?php echo strtoupper($ctTag) ?></div>
<?php endif; ?>
<?php if ($claim->IsNSFW): ?>
<div class="nsfw">NSFW</div>
<?php endif; ?>
</div>
<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 htmlspecialchars($claim->ThumbnailUrl) ?>" alt="" />
<?php else: ?>
<div class="autothumb"><?php echo $autoThumbText ?></div>
<?php endif; ?>
</div>
<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 $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>
<div class="label half-width">Transaction</div>
<div class="label half-width">Created</div>
<div class="value half-width"><a href="/tx/<?php echo $claim->TransactionHash ?>#output-<?php echo $claim->Vout ?>" title="<?php echo $claim->TransactionHash ?>"><?php echo $claim->TransactionHash ?></a></div>
<div class="value half-width" title="<?php echo $claim->Created->format('j M Y H:i:s') ?> UTC">
<?php echo \Carbon\Carbon::createFromTimestamp($claim->TransactionTime > 0 ? $claim->TransactionTime : $claim->Created->format('U'))->diffForHumans(); ?>
</div>
<div class="clear spacer"></div>
<?php if ($claim->ClaimType == 2): ?>
<div class="label half-width">Content Type</div>
<div class="label half-width">Language</div>
<div class="value half-width" title="<?php echo $claim->ContentType ?>"><?php echo $claim->ContentType ?></div>
<div class="value half-width" title="<?php echo $claim->Language == 'en' ? 'English' : $claim->Language ?>"><?php echo $claim->Language == 'en' ? 'English' : $claim->Language ?></div>
<div class="clear spacer"></div>
<div class="label half-width">Author</div>
<div class="label half-width">License</div>
<div class="value half-width" title="<?php echo strlen(trim($claim->Author)) > 0 ? $claim->Author : '<em>Unspecified</em>' ?>"><?php echo strlen(trim($claim->Author)) > 0 ? $claim->Author : '<em>Unspecified</em>' ?></div>
<div class="value half-width" title="<?php echo strlen(trim($claim->License)) > 0 ? $claim->License : '' ?>">
<?php if (strlen(trim($claim->LicenseUrl)) > 0): ?><a href="<?php echo $claim->LicenseUrl ?>" rel="nofollow" target="_blank"><?php endif; ?>
<?php echo strlen(trim($claim->License)) > 0 ? $claim->License : '<em>Unspecified</em>' ?>
<?php if (strlen(trim($claim->LicenseUrl))): ?></a><?php endif; ?>
</div>
<?php endif; ?>
</div>
</div>
<?php $idx++; endforeach; ?>
<div class="clear"></div> <div class="clear"></div>
</div> </div>

View file

@ -54,77 +54,9 @@
if ($idx % 3 == 0) { if ($idx % 3 == 0) {
$row++; $row++;
} }
$autoThumbText = $claim->getAutoThumbText(); echo $this->element('claimbox', array('claim' => $claim, 'idx' => $idx, 'last_row' => $last_row));
$cost = ''; $idx++;
if (isset($claim->Price) && $claim->Price > 0) { endforeach; ?>
$cost = $this->Amount->formatCurrency($claim->Price) . ' LBC';
} else if (isset($claim->Fee) && strtolower($claim->FeeCurrency) === 'lbc') {
$cost = $this->Amount->formatCurrency($claim->Fee) . ' LBC';
}
// content type
$ctTag = $claim->getContentTag();
?>
<div data-id="<?php echo $claim->ClaimId ?>" class="claim-grid-item<?php if ($idx % 3 == 0): ?> last-item<?php endif; ?><?php if ($last_row): ?> last-row<?php endif; ?>">
<?php if (strlen(trim($cost)) > 0): ?>
<div class="price-tag"><?php echo $cost ?></div>
<?php endif; ?>
<div class="tags">
<?php if ($ctTag): ?>
<div class="content-type"><?php echo strtoupper($ctTag) ?></div>
<?php endif; ?>
<?php if ($claim->IsNSFW): ?>
<div class="nsfw">NSFW</div>
<?php endif; ?>
</div>
<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 htmlspecialchars($claim->ThumbnailUrl) ?>" alt="" />
<?php else: ?>
<div class="autothumb"><?php echo $autoThumbText ?></div>
<?php endif; ?>
</div>
<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 $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>
<div class="label half-width">Transaction</div>
<div class="label half-width">Created</div>
<div class="value half-width"><a href="/tx/<?php echo $claim->TransactionHash ?>#output-<?php echo $claim->Vout ?>" title="<?php echo $claim->TransactionHash ?>"><?php echo $claim->TransactionHash ?></a></div>
<div class="value half-width" title="<?php echo $claim->Created->format('j M Y H:i:s') ?> UTC">
<?php echo \Carbon\Carbon::createFromTimestamp($claim->Created->format('U'))->diffForHumans(); ?>
</div>
<div class="clear spacer"></div>
<?php if ($claim->ClaimType == 2): ?>
<div class="label half-width">Content Type</div>
<div class="label half-width">Language</div>
<div class="value half-width" title="<?php echo $claim->ContentType ?>"><?php echo $claim->ContentType ?></div>
<div class="value half-width" title="<?php echo $claim->Language == 'en' ? 'English' : $claim->Language ?>"><?php echo $claim->Language == 'en' ? 'English' : $claim->Language ?></div>
<div class="clear spacer"></div>
<div class="label half-width">Author</div>
<div class="label half-width">License</div>
<div class="value half-width" title="<?php echo strlen(trim($claim->Author)) > 0 ? $claim->Author : '<em>Unspecified</em>' ?>"><?php echo strlen(trim($claim->Author)) > 0 ? $claim->Author : '<em>Unspecified</em>' ?></div>
<div class="value half-width" title="<?php echo strlen(trim($claim->License)) > 0 ? $claim->License : '' ?>">
<?php if (strlen(trim($claim->LicenseUrl)) > 0): ?><a href="<?php echo $claim->LicenseUrl ?>" rel="nofollow" target="_blank"><?php endif; ?>
<?php echo strlen(trim($claim->License)) > 0 ? $claim->License : '<em>Unspecified</em>' ?>
<?php if (strlen(trim($claim->LicenseUrl))): ?></a><?php endif; ?>
</div>
<?php endif; ?>
</div>
</div>
<?php $idx++; endforeach; ?>
<?php else: ?> <?php else: ?>
<div class="no-results">No results were found.</div> <div class="no-results">No results were found.</div>
<?php endif; ?> <?php endif; ?>

View file

@ -129,12 +129,12 @@
<div class="stats"> <div class="stats">
<div class="box box-20"> <div class="box box-20">
<div class="title">Block Height</div> <div class="title">Block Height</div>
<div class="value"><?php echo $recentBlocks[0]->Height ?></div> <div class="value"><?php echo $recentBlocks[0]->height ?></div>
</div> </div>
<div class="box box-30"> <div class="box box-30">
<div class="title">Difficulty</div> <div class="title">Difficulty</div>
<div class="value" title="<?php echo $recentBlocks[0]->Difficulty ?>"><?php echo number_format($recentBlocks[0]->Difficulty, 2, '.', '') ?></div> <div class="value" title="<?php echo $recentBlocks[0]->difficulty ?>"><?php echo number_format($recentBlocks[0]->difficulty, 2, '.', '') ?></div>
</div> </div>
<div class="box box-30"> <div class="box box-30">
@ -167,13 +167,13 @@
<tbody> <tbody>
<?php foreach ($recentBlocks as $block): ?> <?php foreach ($recentBlocks as $block): ?>
<tr data-height="<?php echo $block->Height ?>" data-time="<?php echo $block->BlockTime ?>"> <tr data-height="<?php echo $block->height ?>" data-time="<?php echo $block->block_time ?>">
<td><a href="/blocks/<?php echo $block->Height ?>"><?php echo $block->Height ?></a></td> <td><a href="/blocks/<?php echo $block->height ?>"><?php echo $block->height ?></a></td>
<td><?php echo \Carbon\Carbon::createFromTimestamp($block->BlockTime)->diffForHumans(); ?></td> <td><?php echo \Carbon\Carbon::createFromTimestamp($block->block_time)->diffForHumans(); ?></td>
<td class="right"><?php echo round($block->BlockSize / 1024, 2) . 'KB' ?></td> <td class="right"><?php echo round($block->block_size / 1024, 2) . 'KB' ?></td>
<td class="right"><?php echo $block->TransactionCount ?></td> <td class="right"><?php echo $block->transaction_count ?></td>
<td class="right"><?php echo number_format($block->Difficulty, 2, '.', '') ?></td> <td class="right"><?php echo number_format($block->difficulty, 2, '.', '') ?></td>
<td class="last-cell"><?php echo DateTime::createFromFormat('U', $block->BlockTime)->format('d M Y H:i:s') . ' UTC' ?></td> <td class="last-cell"><?php echo DateTime::createFromFormat('U', $block->block_time)->format('d M Y H:i:s') . ' UTC' ?></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
@ -183,14 +183,15 @@
<div class="recent-claims"> <div class="recent-claims">
<h3>Recent Claims</h3> <h3>Recent Claims</h3>
<a class="claim-explorer-link" href="/claims">Claims Explorer</a> <a class="claim-explorer-link" href="/claims">Claims Explorer</a>
<?php $idx = 0; $a = ['purple', 'orange', 'blue', 'teal', 'green', 'yellow']; foreach ($recentClaims as $claim): <?php $idx = 0; $a = ['purple', 'orange', 'blue', 'teal', 'green', 'yellow'];
foreach ($recentClaims as $claim):
$idx++; $idx++;
$autoThumbText = $claim->getAutoThumbText(); $autoThumbText = $claim->getAutoThumbText();
$link = $claim->Name; $link = $claim->name;
$rawLink = $claim->Name; $rawLink = $claim->name;
if (isset($claim->Publisher->Name)) { if (isset($claim->publisher)) {
$link = urlencode($claim->Publisher->Name) . '/' . $link; $link = urlencode($claim->publisher) . '/' . $link;
$rawLink = $claim->Publisher->Name . '/' . $link; $rawLink = $claim->publisher . '/' . $link;
} }
$link = 'lbry://' . $link; $link = 'lbry://' . $link;
$rawLink = 'lbry://' . $rawLink; $rawLink = 'lbry://' . $rawLink;
@ -198,35 +199,35 @@
// content type // content type
$ctTag = $claim->getContentTag(); $ctTag = $claim->getContentTag();
?> ?>
<div data-id="<?php echo $claim->ClaimId ?>" class="claim-box<?php if ($idx == 5): ?> last<?php endif; ?>"> <div data-id="<?php echo $claim->claim_id ?>" class="claim-box<?php if ($idx == 5): ?> last<?php endif; ?>">
<div class="tags"> <div class="tags">
<?php if ($ctTag): ?> <?php if ($ctTag): ?>
<div class="content-type"><?php echo strtoupper($ctTag) ?></div> <div class="content-type"><?php echo strtoupper($ctTag) ?></div>
<?php endif; ?> <?php endif; ?>
<?php if ($claim->IsNSFW): ?> <?php if ($claim->is_nsfw): ?>
<div class="nsfw">NSFW</div> <div class="nsfw">NSFW</div>
<?php endif; ?> <?php endif; ?>
</div> </div>
<div data-autothumb="<?php echo $autoThumbText ?>" class="thumbnail <?php echo $a[mt_rand(0, count($a) - 1)] ?>"> <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): ?> <?php if (!$claim->is_nsfw && strlen(trim($claim->thumbnail_url)) > 0): ?>
<img src="<?php echo strip_tags($claim->ThumbnailUrl) ?>" alt="" /> <img src="<?php echo strip_tags($claim->thumbnail_url) ?>" alt="" />
<?php else: ?> <?php else: ?>
<div class="autothumb"><?php echo $autoThumbText ?></div> <div class="autothumb"><?php echo $autoThumbText ?></div>
<?php endif; ?> <?php endif; ?>
</div> </div>
<div class="metadata"> <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="title" title="<?php echo $claim->claim_type == 1 ? $claim->name : ((strlen(trim($claim->title)) > 0) ? $claim->title : ''); ?>"><?php echo $claim->claim_type == 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 ?>"><?php echo $rawLink ?></a></div> <div class="link" title="<?php echo $rawLink ?>"><a href="<?php echo $link ?>"><?php echo $rawLink ?></a></div>
<div class="clear"></div> <div class="clear"></div>
<?php if ($claim->ClaimType == 2 && strlen(trim($claim->Description)) > 0): ?> <?php if ($claim->claim_type == 2 && strlen(trim($claim->description)) > 0): ?>
<div class="desc"><?php echo $claim->Description ?></div> <div class="desc"><?php echo $claim->description ?></div>
<?php endif; ?> <?php endif; ?>
</div> </div>
<a class="tx-link" href="/tx/<?php echo $claim->TransactionHash ?>#output-<?php echo $claim->Vout ?>" target="_blank">Transaction</a> <a class="tx-link" href="/tx/<?php echo $claim->transaction_hash_id ?>#output-<?php echo $claim->vout ?>" target="_blank">Transaction</a>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>

View file

@ -128,10 +128,10 @@
<tbody> <tbody>
<?php foreach ($blocks as $block): ?> <?php foreach ($blocks as $block): ?>
<tr data-height="<?php echo $block->Height ?>" data-time="<?php echo $block->BlockTime ?>"> <tr data-height="<?php echo $block->height ?>" data-time="<?php echo $block->block_time ?>">
<td><a href="/blocks/<?php echo $block->Height ?>" target="_blank"><?php echo $block->Height ?></a></td> <td><a href="/blocks/<?php echo $block->height ?>" target="_blank"><?php echo $block->height ?></a></td>
<td><?php echo \Carbon\Carbon::createFromTimestamp($block->BlockTime)->diffForHumans(); ?></td> <td><?php echo \Carbon\Carbon::createFromTimestamp($block->block_time)->diffForHumans(); ?></td>
<td class="right"><?php echo $block->TransactionCount ?></td> <td class="right"><?php echo $block->transaction_count ?></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
@ -153,12 +153,12 @@
<tbody> <tbody>
<?php foreach ($txs as $tx): ?> <?php foreach ($txs as $tx): ?>
<tr data-hash="<?php echo $tx->Hash ?>" data-time="<?php echo $tx->TxTime ?>"> <tr data-hash="<?php echo $tx->hash ?>" data-time="<?php echo $tx->transaction_time ?>">
<td class="w200"><div><a href="/tx/<?php echo $tx->Hash ?>" target="_blank"><?php echo $tx->Hash ?></a></div></td> <td class="w200"><div><a href="/tx/<?php echo $tx->hash ?>" target="_blank"><?php echo $tx->hash ?></a></div></td>
<td><?php echo \Carbon\Carbon::createFromTimestamp($tx->TxTime)->diffForHumans(); ?></td> <td><?php echo $tx->created_at->diffForHumans(); ?></td>
<td class="right"><?php echo $tx->InputCount ?></td> <td class="right"><?php echo $tx->input_count ?></td>
<td class="right"><?php echo $tx->OutputCount ?></td> <td class="right"><?php echo $tx->output_count ?></td>
<td class="right"><?php echo number_format($tx->Value, 8, '.', '') ?> LBC</td> <td class="right"><?php echo number_format($tx->value, 8, '.', '') ?> LBC</td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>

View file

@ -47,8 +47,8 @@
<?php $rank = 0; foreach ($richList as $item): $rank++; ?> <?php $rank = 0; foreach ($richList as $item): $rank++; ?>
<tr> <tr>
<td class="right topvalign"><?php echo $rank ?></td> <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> <td class="topvalign"><a href="/address/<?php echo $item->address ?>" target="_blank"><?php echo $item->address ?></a>
<?php if(in_array($item->Address, $lbryAddresses)): ?> <?php if(in_array($item->address, $lbryAddresses)): ?>
<span class="lbry-address"> <span class="lbry-address">
<img src="/img/lbry.png" height="18px" width="18px" title="Address owned by LBRY Inc."/> <img src="/img/lbry.png" height="18px" width="18px" title="Address owned by LBRY Inc."/>
</span> </span>
@ -58,16 +58,14 @@
<?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; ?> <?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; ?>
</div> </div>
<?php endif; ?></td> <?php endif; ?></td>
<td class="right topvalign"><?php echo number_format($item->Balance, 8, '.', ',') ?></td> <td class="right topvalign"><?php echo number_format($item->balance, 8, '.', ',') ?></td>
<td class="right topvalign">$<?php echo number_format(bcmul($item->Balance, $rate, 8), 2, '.', ',') ?></td> <td class="right topvalign">$<?php echo number_format(bcmul($item->balance, $rate, 8), 2, '.', ',') ?></td>
<td class="med-pad-left topvalign"><?php echo $item->FirstSeen->format('d M Y H:i:s') . ' UTC'; ?></td> <td class="med-pad-left topvalign"><?php echo $item->first_seen->format('d M Y H:i:s') . ' UTC'; ?></td>
<td class="w150 center top500-percent-cell"><div class="top500-percent" style="width: <?php echo $item->MinMaxPercent ?>%"></div><div class="text"><?php echo number_format($item->Top500Percent, 5, '.', '') ?>%</div></td> <td class="w150 center top500-percent-cell"><div class="top500-percent" style="width: <?php echo $item->MinMaxPercent ?>%"></div><div class="text"><?php echo number_format($item->Top500Percent, 5, '.', '') ?>%</div></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>

View file

@ -14,22 +14,22 @@
<div class="tx-head"> <div class="tx-head">
<h3>LBRY Transaction</h3> <h3>LBRY Transaction</h3>
<h4><?php echo $tx->Hash ?></h4> <h4><?php echo $tx->hash ?></h4>
</div> </div>
<div class="tx-time"> <div class="tx-time">
<div class="created-time"> <div class="created-time">
<h3 title="Represents the time this transaction was created on the explorer">Time Created</h3> <h3 title="Represents the time this transaction was created on the explorer">Time Created</h3>
<div><?php echo $tx->Created->format('j M Y H:i:s') . ' UTC '; ?></div> <div><?php echo $tx->created_at->format('j M Y H:i:s') . ' UTC '; ?></div>
</div> </div>
<div class="conf-time"> <div class="conf-time">
<h3 title="The time the first confirmation of this transaction happened on the blockchain">Block Time</h3> <h3 title="The time the first confirmation of this transaction happened on the blockchain">Block Time</h3>
<div><?php echo ($tx->TransactionTime == null || strlen(trim($tx->TransactionTime)) == 0) ? '<em>Not yet confirmed</em>' : <div><?php echo ($tx->transaction_time == null || strlen(trim($tx->transaction_time)) == 0) ? '<em>Not yet confirmed</em>' :
\DateTime::createFromFormat('U', $tx->TransactionTime)->format('j M Y H:i:s') . ' UTC' ?> \DateTime::createFromFormat('U', $tx->transaction_time)->format('j M Y H:i:s') . ' UTC' ?>
<?php if ($tx->TransactionTime > $tx->Created->getTimestamp()): <?php if ($tx->transaction_time > $tx->created_at->getTimestamp()):
$diffSeconds = $tx->TransactionTime - $tx->Created->getTimestamp(); $diffSeconds = $tx->transaction_time - $tx->created_at->getTimestamp();
if ($diffSeconds <= 60) { if ($diffSeconds <= 60) {
echo sprintf(' (+%s second%s)', $diffSeconds, $diffSeconds == 1 ? '' : 's'); echo sprintf(' (+%s second%s)', $diffSeconds, $diffSeconds == 1 ? '' : 's');
} else { } else {
@ -47,15 +47,15 @@
<div class="tx-summary"> <div class="tx-summary">
<div class="box p25"> <div class="box p25">
<div class="title">Amount (LBC)</div> <div class="title">Amount (LBC)</div>
<div class="value"><?php echo $this->Amount->format($tx->Value) ?></div> <div class="value"><?php echo $this->Amount->format($tx->value) ?></div>
</div> </div>
<div class="box p15"> <div class="box p15">
<div class="title">Block Height</div> <div class="title">Block Height</div>
<?php if (!isset($tx->BlockHash) || strlen(trim($tx->BlockHash)) === 0): ?> <?php if (!isset($tx->block_hash_id) || strlen(trim($tx->block_hash_id)) === 0): ?>
<div class="value" title="Unconfirmed">Unconf.</div> <div class="value" title="Unconfirmed">Unconf.</div>
<?php else: ?> <?php else: ?>
<div class="value" title="<?php echo $tx->BlockHash ?>"><a href="/blocks/<?php echo $block->Height ?>"><?php echo $block->Height ?></a></div> <div class="value" title="<?php echo $tx->block_hash_id ?>"><a href="/blocks/<?php echo $block->height ?>"><?php echo $block->height ?></a></div>
<?php endif; ?> <?php endif; ?>
</div> </div>
@ -66,17 +66,17 @@
<div class="box p15"> <div class="box p15">
<div class="title">Size (bytes)</div> <div class="title">Size (bytes)</div>
<div class="value"><?php echo number_format($tx->TransactionSize, 0, '', ',') ?></div> <div class="value"><?php echo number_format($tx->transaction_size, 0, '', ',') ?></div>
</div> </div>
<div class="box p15"> <div class="box p15">
<div class="title">Inputs</div> <div class="title">Inputs</div>
<div class="value"><?php echo $tx->InputCount ?></div> <div class="value"><?php echo $tx->input_count ?></div>
</div> </div>
<div class="box p15 last"> <div class="box p15 last">
<div class="title">Outputs</div> <div class="title">Outputs</div>
<div class="value"><?php echo $tx->OutputCount ?></div> <div class="value"><?php echo $tx->output_count ?></div>
</div> </div>
<div class="clear"></div> <div class="clear"></div>
@ -86,28 +86,29 @@
<h3>Details</h3> <h3>Details</h3>
<div class="tx-details-layout"> <div class="tx-details-layout">
<div class="inputs"> <div class="inputs">
<div class="subtitle"><?php echo $tx->InputCount ?> input<?php echo $tx->InputCount === 1 ? '' : 's'; ?></div> <div class="subtitle"><?php echo $tx->input_count ?> input<?php echo $tx->input_count === 1 ? '' : 's'; ?></div>
<?php <?php
$setAddressIds = []; $setAddressIds = [];
foreach ($inputs as $in): foreach ($inputs as $in):
?> ?>
<div id="input-<?php echo $in->Id ?>" class="input <?php if (isset($in['InputAddresses']) && count($in['InputAddresses']) > 0 && $in['InputAddresses'][0]->Address == $sourceAddress): ?>is-source<?php endif; ?>"> <div id="input-<?php echo $in->id ?>" class="input <?php if (isset($in->input_addresses) && count($in->input_addresses) > 0 && $in->input_addresses[0]->address == $sourceAddress): ?>is-source<?php endif; ?>">
<?php if ($in['IsCoinbase']): ?> <?php if ($in->is_coinbase): ?>
<div>Block Reward (New Coins)</div> <div>Block Reward (New Coins)</div>
<?php else: ?> <?php else: ?>
<?php if (strlen(trim($in->Value)) == 0): ?> <?php if (strlen(trim($in->value)) == 0): ?>
<div>Incomplete data</div> <div>Incomplete data</div>
<?php else: <?php else:
$addr = $in['InputAddresses'][0]; $addr = $in->input_addresses[0];
if (!isset($setAddressIds[$addr->Address])): if (!isset($setAddressIds[$addr->address])):
$setAddressIds[$addr->Address] = 1; ?> $setAddressIds[$addr->address] = 1; ?>
<a id="<?php echo $addr->Address ?>"></a> <a id="<?php echo $addr->address ?>"></a>
<?php endif; ?> <?php endif; ?>
<div><span class="value"><?php echo $this->Amount->format($in['Value']) ?> LBC</span> from</div> <div><span class="value"><?php echo $this->Amount->format($in->value) ?> LBC</span> from</div>
<div class="address"><a href="/address/<?php echo $addr->Address ?>"><?php echo $addr->Address ?></a> <div class="address"><a href="/address/<?php echo $addr->address ?>"><?php echo $addr->address ?></a>
(<a class="output-link" href="/tx/<?php echo $in->PrevoutHash ?>#output-<?php echo $in->PrevoutN ?>">output</a>) (<a class="output-link" href="/tx/<?php echo $in->prevout_hash ?>#output-<?php echo $in->prevout_n ?>">output</a>)
<?php if (isset($addr->Tag) && strlen(trim($addr->Tag)) > 0): ?> <?php if (isset($addr->Tag) && strlen(trim($addr->Tag)) > 0): ?>
<div class="tag"> <div class="tag">
<?php if (strlen(trim($addr->TagUrl)) > 0): ?><a href="<?php echo $addr->TagUrl ?>" target="_blank" rel="nofollow"><?php echo $addr->Tag ?></a><?php else: echo $addr->Tag; endif; ?> <?php if (strlen(trim($addr->TagUrl)) > 0): ?><a href="<?php echo $addr->TagUrl ?>" target="_blank" rel="nofollow"><?php echo $addr->Tag ?></a><?php else: echo $addr->Tag; endif; ?>
@ -125,7 +126,7 @@
</div> </div>
<div class="outputs"> <div class="outputs">
<div class="subtitle"><?php echo $tx->OutputCount ?> output<?php echo $tx->OutputCount === 1 ? '' : 's'; ?> <div class="subtitle"><?php echo $tx->output_count ?> output<?php echo $tx->output_count === 1 ? '' : 's'; ?>
<?php if ($fee > 0): ?> <?php if ($fee > 0): ?>
<span class="fee"><span class="label">Fee</span> <span class="value"><?php echo $this->Amount->format($fee) ?> LBC</span></span> <span class="fee"><span class="label">Fee</span> <span class="value"><?php echo $this->Amount->format($fee) ?> LBC</span></span>
@ -134,7 +135,7 @@
<?php <?php
foreach ($outputs as $out): ?> 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 id="output-<?php echo $out->vout ?>" class="output <?php if (isset($out->output_addresses) && count($out->output_addresses) > 0 && $out->output_addresses[0]->address == $sourceAddress): ?>is-source<?php endif; ?>">
<div class="labels"> <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->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->IsSupportClaim): ?><div class="support">SUPPORT</div><?php endif; ?>
@ -142,19 +143,19 @@
<?php if($out->IsClaim): ?><div class="claim">CLAIM</div><?php endif; ?> <?php if($out->IsClaim): ?><div class="claim">CLAIM</div><?php endif; ?>
</div> </div>
<?php if (strlen(trim($out['Value'])) == 0): ?> <?php if (strlen(trim($out->value)) == 0): ?>
<div>Incomplete data</div> <div>Incomplete data</div>
<?php else: <?php else:
$addr = $out['OutputAddresses'][0]; $addr = $out->output_addresses[0];
if (!isset($setAddressIds[$addr->Address])): if (!isset($setAddressIds[$addr->address])):
$setAddressIds[$addr->Address] = 1; ?> $setAddressIds[$addr->address] = 1; ?>
<a id="<?php echo $addr->Address ?>"></a> <a id="<?php echo $addr->address ?>"></a>
<?php endif; ?> <?php endif; ?>
<div><span class="value"><?php echo $this->Amount->format($out['Value']) ?> LBC</span> to</div> <div><span class="value"><?php echo $this->Amount->format($out->value) ?> LBC</span> to</div>
<div class="address"><a href="/address/<?php echo $addr->Address ?>"><?php echo $addr->Address ?></a> <div class="address"><a href="/address/<?php echo $addr->address ?>"><?php echo $addr->address ?></a>
<?php if ($out->IsSpent): ?>(<a href="/tx/<?php echo $out->SpendInput->TransactionHash ?>#input-<?php echo $out->SpendInput->Id ?>">spent</a>)<?php else: ?>(unspent)<?php endif; ?> <?php if ($out->is_spent): ?>(<a href="/tx/<?php if(isset($out->spend_input_id)) { echo $out->spend_input_hash; } ?>#input-<?php if(isset($out->spend_input_id)) {echo $out->spend_input_id; } ?>">spent</a>)<?php else: ?>(unspent)<?php endif; ?>
<?php if (isset($addr->Tag) && strlen(trim($addr->Tag)) > 0): ?> <?php if (isset($addr->Tag) && strlen(trim($addr->Tag)) > 0): ?>
<div class="tag"> <div class="tag">

View file

@ -15,7 +15,7 @@
namespace App\View; namespace App\View;
use Cake\Event\EventManager; use Cake\Event\EventManager;
use Cake\Network\Request; use Cake\Http\ServerRequest;
use Cake\Network\Response; use Cake\Network\Response;
/** /**

View file

@ -0,0 +1,8 @@
.bids-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 }
.bids-chart-container .load-progress { position: absolute; top: 0; left: 0; width: 100%; height: 3px; background: #1e88e5; animation: indeterminate 4s linear infinite; }
.bids-chart-container .chart { height: 414px }
.bids-chart-container .btn-chart-export { position: absolute; right: 40px; bottom: 36px }
@keyframes indeterminate {
from { left: -70%; }
to { left: 100% }
}

View file

@ -81,6 +81,7 @@ border-radius: 0 8px 8px 0 }
.claims-grid .claim-grid-item .thumbnail .autothumb { display: block; margin: 73px auto 0 auto; text-align: center; font-size: 240%; color: #fff; line-height: 54px } .claims-grid .claim-grid-item .thumbnail .autothumb { display: block; margin: 73px auto 0 auto; text-align: center; font-size: 240%; color: #fff; line-height: 54px }
.claims-grid .claim-grid-item .tags > div { display: inline-block; padding: 4px 12px; margin-left: 2px } .claims-grid .claim-grid-item .tags > div { display: inline-block; padding: 4px 12px; margin-left: 2px }
.claims-grid .claim-grid-item .tags .nsfw { background: #e53935; text-align: center; color: #fff; position: relative; left: 1px } .claims-grid .claim-grid-item .tags .nsfw { background: #e53935; text-align: center; color: #fff; position: relative; left: 1px }
.claims-grid .claim-grid-item .tags .bid-state { background: #551CA1; text-align: center; color: #fff; }
.claims-grid .claim-grid-item .tags .content-type { background: #880e4f; text-align: center; color: #fff; } .claims-grid .claim-grid-item .tags .content-type { background: #880e4f; text-align: center; color: #fff; }
.claims-grid .claim-grid-item .metadata { padding: 24px; font-size: 90% } .claims-grid .claim-grid-item .metadata { padding: 24px; font-size: 90% }
.claims-grid .claim-grid-item .title { font-size: 120%; height: 25px; line-height: 25px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap } .claims-grid .claim-grid-item .title { font-size: 120%; height: 25px; line-height: 25px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }

170
webroot/js/bids-chart.js Normal file
View file

@ -0,0 +1,170 @@
function buildChartData(claimsData) {
var chartData = [];
var lastDate = 0;
var nbClaimsDay = 0;
var nbClaimsTotal = 0;
var bidClaimsDay = 0;
var bidClaimsTotal = 0;
var nbChannelsDay = 0;
var nbChannelsTotal = 0;
for(var i = 0; i < claimsData.length; i++) {
if(claimsData[i].transaction_time == 0) {
continue;
}
var transactionDate = new Date(claimsData[i].transaction_time * 1000);
transactionDate.setHours(0,0,0,0)
if(lastDate == 0) {
lastDate = transactionDate;
}
if(transactionDate.toString() != lastDate.toString()) {
nbClaimsTotal += nbClaimsDay;
bidClaimsTotal += bidClaimsDay;
var dateData = {
date: lastDate,
NumberClaims: nbClaimsTotal,
BidsClaims: bidClaimsTotal,
};
chartData.push(dateData);
nbClaimsDay = 0;
bidClaimsDay = 0;
lastDate = transactionDate;
}
if(claimsData[i].claim_type == 1) {
nbClaimsDay += 1;
bidClaimsDay += claimsData[i].effective_amount/100000000;
}
}
return chartData;
}
function loadChartData() {
var api_url = "https://chainquery.lbry.io/api/sql?query=";
var query = "SELECT c1.claim_type, c1.bid_state, c1.effective_amount, c1.transaction_time, o.transaction_time AS 'spent_time' FROM claim c1 LEFT JOIN (SELECT output.claim_id, tx.transaction_time FROM output INNER JOIN input ON input.prevout_hash = output.transaction_hash AND input.prevout_n = output.vout INNER JOIN transaction tx ON tx.id = input.transaction_id) o ON o.claim_id=c1.claim_id AND c1.bid_state='Spent' ORDER BY c1.transaction_time ASC";
var url = api_url + query;
var loadProgress = $('.bids-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('bids-chart', {
type: 'serial',
theme: 'light',
mouseWheelZoomEnabled: true,
height: '100%',
categoryField: 'date',
synchronizeGrid: true,
dataProvider: chartData,
responsive: {
enabled: true,
},
valueAxes: [
{
id: 'v-number-claims',
axisColor: '#1e88e5',
axisThickness: 2,
position: 'left',
},
{
id: 'v-bids-claims',
axisColor: '#0b7a06',
axisThickness: 2,
position: 'left',
offset: 75,
},
],
categoryAxis: {
parseDates: true,
autoGridCount: false,
minorGridEnabled: true,
minorGridAlpha: 0.04,
axisColor: '#dadada',
twoLineMode: true
},
graphs: [
{
id: 'g-number-claims',
valueAxis: 'v-number-claims',
title: 'Number of claims',
valueField: 'NumberClaims',
bullet: 'round',
bulletBorderThickness: 1,
bulletBorderAlpha: 1,
bulletColor: '#ffffff',
bulletSize: 5,
useLineColorForBulletBorder: true,
lineColor: '#1e88e5',
hideBulletsCount: 101,
balloonText: '[[NumberClaims]]',
},
{
id: 'g-bids-claims',
valueAxis: 'v-bids-claims',
title: 'Bids for claims (LBC)',
valueField: 'BidsClaims',
bullet: 'round',
bulletBorderThickness: 1,
bulletBorderAlpha: 1,
bulletColor: '#ffffff',
bulletSize: 5,
useLineColorForBulletBorder: true,
lineColor: '#0b7a06',
balloonText: '[[BidsClaims]] LBC',
hideBulletsCount: 101
},
],
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-bids-chart',
position: 'bottom-right',
divId: 'chart-export'
}
});
loadChartData();
});