Tx and index page

This commit is contained in:
marcdeb1 2018-12-17 00:49:26 +01:00
parent 3eab838967
commit 6e8a651980
18 changed files with 341 additions and 203 deletions

View file

@ -222,16 +222,16 @@ return [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
'host' => 'chainquery.lbry.io:3600',
/**
* 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' => 'non_standard_port_number',
'username' => 'my_app',
'password' => 'secret',
'database' => 'my_app',
'username' => 'marcdeb',
'password' => '3885fc6d0b71befe72a327f47f36c0911057',
'database' => 'lbry',
'encoding' => 'utf8',
'timezone' => 'UTC',
'flags' => [],
@ -257,7 +257,7 @@ return [
*/
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
'url' => env('DATABASE_URL', null),
'url' => env('DATABASE_URL', 'chainquery.lbry.io:3600'),
],
/**

View file

@ -14,6 +14,7 @@ use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\LabelAlignment;
use Endroid\QrCode\QrCode;
class MainController extends AppController {
public static $rpcurl;
@ -92,21 +93,23 @@ class MainController extends AppController {
$lbcUsdPrice = $this->_getLatestPrice();
$this->set('lbcUsdPrice', $lbcUsdPrice);
$blocks = $this->Blocks->find()->select(['Chainwork', 'Confirmations', 'Difficulty', 'Hash', 'Height', 'TransactionHashes', 'BlockTime', 'BlockSize'])->
order(['Height' => 'desc'])->limit(6)->toArray();
$blocks = $this->Blocks->find()->select(['chainwork', 'confirmations', 'difficulty', 'hash', 'height', 'transaction_hashes', 'block_time', 'block_size'])->order(['height' => 'desc'])->limit(6)->toArray();
for ($i = 0; $i < count($blocks); $i++) {
$tx_hashes = json_decode($blocks[$i]->TransactionHashes);
$blocks[$i]->TransactionCount = count($tx_hashes);
$tx_hashes = json_decode($blocks[$i]->transaction_hashes, true);
$blocks[$i]->transaction_count = count($tx_hashes);
}
// hash rate
$hashRate = $this->_formatHashRate($this->_gethashrate());
// recent claims
$claims = $this->Claims->find()->select(['TransactionHash', 'Name', 'Vout', 'ClaimId', 'ClaimType', 'Author', 'Title', 'Description', 'ContentType',
'IsNSFW', 'Language', 'ThumbnailUrl', 'Created'])->
distinct(['Claims.ClaimId'])->
contain(['Publisher' => ['fields' => ['Name']]])->order(['Claims.Created' => 'DESC'])->limit(5)->toArray();
$claims = $this->Claims->find()->select(['transaction_hash_id', 'name', 'vout', 'claim_id', 'claim_type', 'author', 'title', 'description', 'content_type', 'is_nsfw', 'language', 'thumbnail_url', 'created_at'])->
distinct(['Claims.claim_id'])->order(['Claims.created_at' => 'DESC'])->limit(5)->toArray();
foreach($claims as $claim) {
$publisher = $this->Claims->find()->select(['name'])->where(['claim_id' => $claim->publisher_id])->first();
$claim->publisher = $publisher;
}
$this->set('recentBlocks', $blocks);
$this->set('recentClaims', $claims);
@ -399,10 +402,10 @@ class MainController extends AppController {
}
$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(
['Height', 'Difficulty', 'TransactionHashes', 'BlockSize', 'Nonce', 'BlockTime']
)->offset($offset)->limit($pageLimit)->order(['Height' => 'DESC'])->toArray();
['height', 'difficulty', 'transaction_hashes', 'block_size', 'nonce', 'block_time']
)->offset($offset)->limit($pageLimit)->order(['height' => 'DESC'])->toArray();
$this->set('currentBlock', $currentBlock);
$this->set('blocks', $blocks);
$this->set('pageLimit', $pageLimit);
@ -416,28 +419,13 @@ class MainController extends AppController {
return $this->redirect('/');
}
$block = $this->Blocks->find()->where(['Height' => $height])->first();
$block = $this->Blocks->find()->where(['height' => $height])->first();
if (!$block) {
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
$txs = $this->Transactions->find()->select(['InputCount', 'OutputCount', 'Hash', 'Value', 'Version'])->where(['BlockHash' => $block->Hash])->toArray();
$txs = $this->Transactions->find()->select(['input_count', 'output_count', 'hash', 'version'])->where(['block_hash_id' => $block->hash])->toArray();
$this->set('block', $block);
$this->set('blockTxs', $txs);
@ -449,32 +437,27 @@ class MainController extends AppController {
$this->loadModel('Transactions');
$this->loadModel('Inputs');
$this->loadModel('Outputs');
$this->loadModel('Addresses');
$this->loadModel('Claims');
$sourceAddress = $this->request->query('address');
$tx = $this->Transactions->find()->select(
['Id', 'BlockHash', 'InputCount', 'OutputCount', 'Hash', 'Value', 'TransactionTime', 'TransactionSize', 'Created', 'Version', 'LockTime', 'Raw'])->where(['Hash' => $hash])->first();
['id', 'block_hash_id', 'input_count', 'output_count', 'hash', 'transaction_time', 'transaction_size', 'created_at', 'version', 'lock_time', 'raw'])->where(['hash' => $hash])->first();
if (!$tx) {
return $this->redirect('/');
}
if ($tx->TransactionSize == 0) {
$tx->TransactionSize = (strlen($tx->Raw) / 2);
$conn = ConnectionManager::get('default');
$conn->execute('UPDATE Transactions SET TransactionSize = ? WHERE Id = ?', [$tx->TransactionSize, $tx->Id]);
}
$maxBlock = $this->Blocks->find()->select(['Height'])->order(['Height' => 'desc'])->first();
$block = $this->Blocks->find()->select(['Confirmations', 'Height'])->where(['Hash' => $tx->BlockHash])->first();
$confirmations = $block ? (($maxBlock->Height - $block->Height) + 1) : '0';
$inputs = $this->Inputs->find()->contain(['InputAddresses'])->where(['TransactionId' => $tx->Id])->order(['PrevoutN' => 'asc'])->toArray();
$outputs = $this->Outputs->find()->contain(['OutputAddresses', 'SpendInput' => ['fields' => ['Id', 'TransactionHash', 'PrevoutN', 'PrevoutHash']]])->where(['Outputs.TransactionId' => $tx->Id])->order(['Vout' => 'asc'])->toArray();
$block = $this->Blocks->find()->select(['confirmations', 'height'])->where(['hash' => $tx->block_hash_id])->first();
$confirmations = $block->confirmations;
$inputs = $this->Inputs->find()->where(['transaction_id' => $tx->id])->order(['prevout_n' => 'asc'])->toArray();
$inputAddresses = $this->Addresses->find()->where(['input_address_id'])->toArray();
$outputs = $this->Outputs->find()->where(['transaction_id' => $tx->id])->order(['vout' => 'asc'])->toArray();
for ($i = 0; $i < count($outputs); $i++) {
$outputs[$i]->IsClaim = (strpos($outputs[$i]->ScriptPubKeyAsm, 'CLAIM') > -1);
$outputs[$i]->IsSupportClaim = (strpos($outputs[$i]->ScriptPubKeyAsm, 'SUPPORT_CLAIM') > -1);
$outputs[$i]->IsUpdateClaim = (strpos($outputs[$i]->ScriptPubKeyAsm, 'UPDATE_CLAIM') > -1);
$claim = $this->Claims->find()->where(['TransactionHash' => $tx->Hash, 'Vout' => $outputs[$i]->Vout])->first();
$outputs[$i]->IsClaim = (strpos($outputs[$i]->script_pub_key_asm, 'CLAIM') > -1);
$outputs[$i]->IsSupportClaim = (strpos($outputs[$i]->script_pub_key_asm, 'SUPPORT_CLAIM') > -1);
$outputs[$i]->IsUpdateClaim = (strpos($outputs[$i]->script_pub_key_asm, 'UPDATE_CLAIM') > -1);
$claim = $this->Claims->find()->where(['transaction_hash_id' => $tx->hash, 'vout' => $outputs[$i]->vout])->first();
$outputs[$i]->Claim = $claim;
}
@ -482,10 +465,10 @@ class MainController extends AppController {
$totalOut = 0;
$fee = 0;
foreach ($inputs as $in) {
$totalIn = bcadd($totalIn, $in->Value, 8);
$totalIn = bcadd($totalIn, $in->value, 8);
}
foreach ($outputs as $out) {
$totalOut = bcadd($totalOut, $out->Value, 8);
$totalOut = bcadd($totalOut, $out->value, 8);
}
$fee = bcsub($totalIn, $totalOut, 8);

View file

@ -5,6 +5,9 @@ namespace App\Model\Entity;
use Cake\ORM\Entity;
class Block extends Entity {
public function target() {
}
}

View file

@ -6,7 +6,7 @@ use Cake\ORM\Entity;
class Claim extends Entity {
function getLbryLink() {
$link = $this->Name;
$link = $this->name;
if (isset($this->Publisher->Name)) {
$link = $this->Publisher->Name . '/' . $link;
}
@ -15,21 +15,21 @@ class Claim extends Entity {
}
function getExplorerLink() {
$link = '/claims/' . $this->ClaimId;
$link = '/claims/' . $this->claim_id;
return $link;
}
function getContentTag() {
$ctTag = null;
if (substr($this->ContentType, 0, 5) === 'audio') {
if (substr($this->content_type, 0, 5) === 'audio') {
$ctTag = 'audio';
} else if (substr($this->ContentType, 0, 5) === 'video') {
} else if (substr($this->content_type, 0, 5) === 'video') {
$ctTag = 'video';
} else if (substr($this->ContentType, 0, 5) === 'image') {
} else if (substr($this->content_type, 0, 5) === 'image') {
$ctTag = 'image';
}
if (!$ctTag && $this->ClaimType == 1) {
if (!$ctTag && $this->claim_type == 1) {
$ctTag = 'identity';
}
return $ctTag;
@ -37,10 +37,10 @@ class Claim extends Entity {
function getAutoThumbText() {
$autoThumbText = '';
if ($this->ClaimType == 1) {
$autoThumbText = strtoupper(substr($this->Name, 1, min( strlen($this->Name), 3 )));
if ($this->claim_type == 1) {
$autoThumbText = strtoupper(substr($this->name, 1, min( strlen($this->name), 3 )));
} 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 )));
}
return $autoThumbText;

View file

@ -1,11 +0,0 @@
<?php
namespace App\Model\Entity;
use Cake\ORM\Entity;
class ClaimStream extends Entity {
}
?>

View file

@ -3,8 +3,19 @@
namespace App\Model\Entity;
use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;
class Transaction extends Entity {
public function value() {
$OutputModel = TableRegistry::get('Outputs');
$outputs = $OutputModel->find()->select(['value'])->where(['transaction_id' => $this->id])->toArray();
$value = 0;
foreach($outputs as $o) {
$value += $o->value;
}
return $value;
}
}

View file

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

View file

@ -8,8 +8,8 @@ class BlocksTable extends Table {
public function initialize(array $config) {
parent::initialize($config);
$this->primaryKey('Id');
$this->table('Blocks');
$this->primaryKey('id');
$this->table('block');
$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,25 +8,17 @@ class ClaimsTable extends Table {
public function initialize(array $config) {
parent::initialize($config);
$this->primaryKey('Id');
$this->table('Claims');
$this->primaryKey('id');
$this->table('claim');
//$this->addBehavior('SimpleAudit');
$this->addAssociations([
'belongsTo' => [
'Publisher' => [
'publisher' => [
'className' => 'App\Model\Table\ClaimsTable',
'foreignKey' => 'PublisherId',
'bindingKey' => 'ClaimId',
'propertyName' => 'Publisher'
]
],
'hasOne' => [
'Stream' => [
'className' => 'App\Model\Table\ClaimStreamsTable',
'foreignKey' => 'Id',
'bindingKey' => 'Id',
'propertyName' => 'Stream'
'foreignKey' => 'publisher_id',
'bindingKey' => 'claim_id',
'propertyName' => 'publisher'
]
]
]);

View file

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

View file

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

View file

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

View file

@ -21,20 +21,20 @@
</script>
<?php $this->end(); ?>
<?php $this->assign('title', 'Block Height ' . $block->Height) ?>
<?php $this->assign('title', 'Block Height ' . $block->height) ?>
<div class="block-head">
<h3>LBRY Block <?php echo $block->Height ?></h3>
<h4><?php echo $block->Hash ?></h4>
<h3>LBRY Block <?php echo $block->height ?></h3>
<h4><?php echo $block->hash ?></h4>
</div>
<div class="block-nav">
<?php if (strlen(trim($block->PreviousBlockHash)) > 0): ?>
<a class="btn btn-prev" href="/blocks/<?php echo ($block->Height - 1); ?>">&laquo; Previous Block</a>
<?php if (strlen(trim($block->previous_block_hash)) > 0): ?>
<a class="btn btn-prev" href="/blocks/<?php echo ($block->height - 1); ?>">&laquo; Previous Block</a>
<?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>
<?php if (strlen(trim($block->next_block_hash)) > 0): ?>
<a class="btn btn-next" href="/blocks/<?php echo ($block->height + 1); ?>">Next Block &raquo;</a>
<?php endif; ?>
<div class="clear"></div>
@ -47,44 +47,44 @@
<div class="label half-width">Block Size (bytes)</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 \DateTime::createFromFormat('U', $block->BlockTime)->format('j M Y H:i:s') . ' UTC' ?></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->block_time)->format('j M Y H:i:s') . ' UTC' ?></div>
<div class="clear spacer"></div>
<div class="label half-width">Bits</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 number_format($block->Confirmations, 0, '', ',') ?></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="clear spacer"></div>
<div class="label half-width">Difficulty</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 $block->Nonce ?></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="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="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="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="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="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 class="block-transactions">
@ -109,10 +109,10 @@
<?php foreach ($blockTxs as $tx): ?>
<tr>
<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->OutputCount ?></td>
<td class="right"><div title="<?php echo $tx->Value ?> LBC"><?php echo $this->Amount->formatCurrency($tx->Value) ?> LBC</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->input_count ?></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>
</tr>
<?php endforeach; ?>
</tbody>
@ -181,13 +181,13 @@
<tbody>
<?php foreach ($blocks as $block): ?>
<tr>
<td class="right"><a href="/blocks/<?php echo $block->Height ?>"><?php echo $block->Height ?></a></td>
<td class="pad-left"><?php echo number_format($block->Difficulty, 8, '.', '') ?></td>
<td class="right"><?php echo number_format((($currentBlock->Height - $block->Height) + 1), 0, '', ',') ?></td>
<td class="right"><?php echo count(json_decode($block->TransactionHashes)) ?></td>
<td class="right"><?php echo round($block->BlockSize / 1024, 2) . 'KB' ?></td>
<td class="right pad-left"><?php echo $block->Nonce ?></td>
<td class="pad-left"><?php echo \DateTime::createFromFormat('U', $block->BlockTime)->format('d M Y H:i:s') ?> UTC</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->d0ifficulty, 8, '.', '') ?></td>
<td class="right"><?php echo number_format((($currentBlock->height - $block->height) + 1), 0, '', ',') ?></td>
<td class="right"><?php echo count(json_decode($block->transaction_hashes)) ?></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="pad-left"><?php echo \DateTime::createFromFormat('U', $block->block_time)->format('d M Y H:i:s') ?> UTC</td>
</tr>
<?php endforeach; ?>
</tbody>

View file

@ -129,12 +129,12 @@
<div class="stats">
<div class="box box-20">
<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 class="box box-30">
<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 class="box box-30">
@ -167,13 +167,13 @@
<tbody>
<?php foreach ($recentBlocks as $block): ?>
<tr data-height="<?php echo $block->Height ?>" data-time="<?php echo $block->BlockTime ?>">
<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 class="right"><?php echo round($block->BlockSize / 1024, 2) . 'KB' ?></td>
<td class="right"><?php echo $block->TransactionCount ?></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>
<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><?php echo \Carbon\Carbon::createFromTimestamp($block->block_time)->diffForHumans(); ?></td>
<td class="right"><?php echo round($block->block_size / 1024, 2) . 'KB' ?></td>
<td class="right"><?php echo $block->transaction_count ?></td>
<td class="right"><?php echo number_format($block->difficulty, 2, '.', '') ?></td>
<td class="last-cell"><?php echo DateTime::createFromFormat('U', $block->block_time)->format('d M Y H:i:s') . ' UTC' ?></td>
</tr>
<?php endforeach; ?>
</tbody>
@ -186,11 +186,11 @@
<?php $idx = 0; $a = ['purple', 'orange', 'blue', 'teal', 'green', 'yellow']; foreach ($recentClaims as $claim):
$idx++;
$autoThumbText = $claim->getAutoThumbText();
$link = $claim->Name;
$rawLink = $claim->Name;
if (isset($claim->Publisher->Name)) {
$link = urlencode($claim->Publisher->Name) . '/' . $link;
$rawLink = $claim->Publisher->Name . '/' . $link;
$link = $claim->name;
$rawLink = $claim->name;
if (isset($claim->publisher->name)) {
$link = urlencode($claim->publisher->name) . '/' . $link;
$rawLink = $claim->publisher->name . '/' . $link;
}
$link = 'lbry://' . $link;
$rawLink = 'lbry://' . $rawLink;
@ -198,35 +198,35 @@
// content type
$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">
<?php if ($ctTag): ?>
<div class="content-type"><?php echo strtoupper($ctTag) ?></div>
<?php endif; ?>
<?php if ($claim->IsNSFW): ?>
<?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->IsNSFW && strlen(trim($claim->ThumbnailUrl)) > 0): ?>
<img src="<?php echo strip_tags($claim->ThumbnailUrl) ?>" alt="" />
<?php if (!$claim->is_nsfw && strlen(trim($claim->thumbnail_url)) > 0): ?>
<img src="<?php echo strip_tags($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->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="clear"></div>
<?php if ($claim->ClaimType == 2 && strlen(trim($claim->Description)) > 0): ?>
<div class="desc"><?php echo $claim->Description ?></div>
<?php if ($claim->claim_type == 2 && strlen(trim($claim->description)) > 0): ?>
<div class="desc"><?php echo $claim->description ?></div>
<?php endif; ?>
</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 ?>#output-<?php echo $claim->vout ?>" target="_blank">Transaction</a>
</div>
<?php endforeach; ?>

View file

@ -14,22 +14,22 @@
<div class="tx-head">
<h3>LBRY Transaction</h3>
<h4><?php echo $tx->Hash ?></h4>
<h4><?php echo $tx->hash ?></h4>
</div>
<div class="tx-time">
<div class="created-time">
<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 class="conf-time">
<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>' :
\DateTime::createFromFormat('U', $tx->TransactionTime)->format('j M Y H:i:s') . ' UTC' ?>
<div><?php echo ($tx->transaction_time == null || strlen(trim($tx->transaction_time)) == 0) ? '<em>Not yet confirmed</em>' :
\DateTime::createFromFormat('U', $tx->transaction_time)->format('j M Y H:i:s') . ' UTC' ?>
<?php if ($tx->TransactionTime > $tx->Created->getTimestamp()):
$diffSeconds = $tx->TransactionTime - $tx->Created->getTimestamp();
<?php if ($tx->transaction_time > $tx->created_at->getTimestamp()):
$diffSeconds = $tx->transaction_time - $tx->created_at->getTimestamp();
if ($diffSeconds <= 60) {
echo sprintf(' (+%s second%s)', $diffSeconds, $diffSeconds == 1 ? '' : 's');
} else {
@ -47,15 +47,15 @@
<div class="tx-summary">
<div class="box p25">
<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 class="box p15">
<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>
<?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; ?>
</div>
@ -66,17 +66,17 @@
<div class="box p15">
<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 class="box p15">
<div class="title">Inputs</div>
<div class="value"><?php echo $tx->InputCount ?></div>
<div class="value"><?php echo $tx->input_count ?></div>
</div>
<div class="box p15 last">
<div class="title">Outputs</div>
<div class="value"><?php echo $tx->OutputCount ?></div>
<div class="value"><?php echo $tx->output_count ?></div>
</div>
<div class="clear"></div>
@ -86,28 +86,28 @@
<h3>Details</h3>
<div class="tx-details-layout">
<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
$setAddressIds = [];
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; ?>">
<?php if ($in['IsCoinbase']): ?>
<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; ?>">
<?php if ($in->is_coinbase): ?>
<div>Block Reward (New Coins)</div>
<?php else: ?>
<?php if (strlen(trim($in->Value)) == 0): ?>
<?php if (strlen(trim($in->value)) == 0): ?>
<div>Incomplete data</div>
<?php else:
$addr = $in['InputAddresses'][0];
if (!isset($setAddressIds[$addr->Address])):
$setAddressIds[$addr->Address] = 1; ?>
<a id="<?php echo $addr->Address ?>"></a>
if (!isset($setAddressIds[$addr->address])):
$setAddressIds[$addr->address] = 1; ?>
<a id="<?php echo $addr->address ?>"></a>
<?php endif; ?>
<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>
(<a class="output-link" href="/tx/<?php echo $in->PrevoutHash ?>#output-<?php echo $in->PrevoutN ?>">output</a>)
<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>
(<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): ?>
<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; ?>
@ -125,7 +125,7 @@
</div>
<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): ?>
<span class="fee"><span class="label">Fee</span> <span class="value"><?php echo $this->Amount->format($fee) ?> LBC</span></span>
@ -134,7 +134,7 @@
<?php
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['OutputAddresses']) && count($out['OutputAddresses']) > 0 && $out['OutputAddresses'][0]->address == $sourceAddress): ?>is-source<?php endif; ?>">
<div class="labels">
<?php if($out->Claim && ($out->IsClaim or $out->IsSupportClaim or $out->IsUpdateClaim)): ?><a class="view-claim" href="<?php echo $out->Claim->getExplorerLink() ?>">View</a><?php endif; ?>
<?php if($out->IsSupportClaim): ?><div class="support">SUPPORT</div><?php endif; ?>
@ -152,9 +152,9 @@
<a id="<?php echo $addr->Address ?>"></a>
<?php endif; ?>
<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 echo $out->spend_input->transaction_hash_id ?>#input-<?php echo $out->spend_input->id ?>">spent</a>)<?php else: ?>(unspent)<?php endif; ?>
<?php if (isset($addr->Tag) && strlen(trim($addr->Tag)) > 0): ?>
<div class="tag">

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% }
}

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();
});