diff --git a/config/app.default.php b/config/app.default.php index c06599e..7fbc837 100644 --- a/config/app.default.php +++ b/config/app.default.php @@ -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'), ], /** diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index cc5d715..f144f0c 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -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); diff --git a/src/Model/Entity/Block.php b/src/Model/Entity/Block.php index 7858813..8f66eac 100644 --- a/src/Model/Entity/Block.php +++ b/src/Model/Entity/Block.php @@ -5,6 +5,9 @@ namespace App\Model\Entity; use Cake\ORM\Entity; class Block extends Entity { + public function target() { + + } } diff --git a/src/Model/Entity/Claim.php b/src/Model/Entity/Claim.php index 18a5734..d12c480 100644 --- a/src/Model/Entity/Claim.php +++ b/src/Model/Entity/Claim.php @@ -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; diff --git a/src/Model/Entity/ClaimStream.php b/src/Model/Entity/ClaimStream.php deleted file mode 100644 index 6a51882..0000000 --- a/src/Model/Entity/ClaimStream.php +++ /dev/null @@ -1,11 +0,0 @@ - \ No newline at end of file diff --git a/src/Model/Entity/Transaction.php b/src/Model/Entity/Transaction.php index 631f08c..b491ed7 100644 --- a/src/Model/Entity/Transaction.php +++ b/src/Model/Entity/Transaction.php @@ -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; + } } diff --git a/src/Model/Table/AddressesTable.php b/src/Model/Table/AddressesTable.php index 1876136..daa47f2 100644 --- a/src/Model/Table/AddressesTable.php +++ b/src/Model/Table/AddressesTable.php @@ -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'); } diff --git a/src/Model/Table/BlocksTable.php b/src/Model/Table/BlocksTable.php index 0b2a8ed..bc58288 100644 --- a/src/Model/Table/BlocksTable.php +++ b/src/Model/Table/BlocksTable.php @@ -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'); } diff --git a/src/Model/Table/ClaimStreamsTable.php b/src/Model/Table/ClaimStreamsTable.php deleted file mode 100644 index eb77edf..0000000 --- a/src/Model/Table/ClaimStreamsTable.php +++ /dev/null @@ -1,18 +0,0 @@ -primaryKey('Id'); - $this->table('ClaimStreams'); - - //$this->addBehavior('SimpleAudit'); - } -} - -?> \ No newline at end of file diff --git a/src/Model/Table/ClaimsTable.php b/src/Model/Table/ClaimsTable.php index 4177faa..9f826da 100644 --- a/src/Model/Table/ClaimsTable.php +++ b/src/Model/Table/ClaimsTable.php @@ -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' ] ] ]); diff --git a/src/Model/Table/InputsTable.php b/src/Model/Table/InputsTable.php index c1c06e7..58776b6 100644 --- a/src/Model/Table/InputsTable.php +++ b/src/Model/Table/InputsTable.php @@ -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' ] ] ]); diff --git a/src/Model/Table/OutputsTable.php b/src/Model/Table/OutputsTable.php index 1840aa7..dbb58fc 100644 --- a/src/Model/Table/OutputsTable.php +++ b/src/Model/Table/OutputsTable.php @@ -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' ] ] ]); diff --git a/src/Model/Table/TransactionsTable.php b/src/Model/Table/TransactionsTable.php index 613512d..7d1a180 100644 --- a/src/Model/Table/TransactionsTable.php +++ b/src/Model/Table/TransactionsTable.php @@ -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'); } diff --git a/src/Template/Main/blocks.ctp b/src/Template/Main/blocks.ctp index 38b8543..3c1512f 100644 --- a/src/Template/Main/blocks.ctp +++ b/src/Template/Main/blocks.ctp @@ -21,20 +21,20 @@ end(); ?> - assign('title', 'Block Height ' . $block->Height) ?> + assign('title', 'Block Height ' . $block->height) ?>
-

LBRY Block Height ?>

-

Hash ?>

+

LBRY Block height ?>

+

hash ?>

- PreviousBlockHash)) > 0): ?> - « Previous Block + previous_block_hash)) > 0): ?> + « Previous Block - NextBlockHash)) > 0): ?> - Next Block » + next_block_hash)) > 0): ?> + Next Block »
@@ -47,44 +47,44 @@
Block Size (bytes)
Block Time
-
BlockSize, 0, '', ',') ?>
-
BlockTime)->format('j M Y H:i:s') . ' UTC' ?>
+
block_size, 0, '', ',') ?>
+
block_time)->format('j M Y H:i:s') . ' UTC' ?>
Bits
Confirmations
-
Bits ?>
-
Confirmations, 0, '', ',') ?>
+
bits ?>
+
confirmations, 0, '', ',') ?>
Difficulty
Nonce
-
Amount->format($block->Difficulty, '') ?>
-
Nonce ?>
+
Amount->format($block->difficulty, '') ?>
+
nonce ?>
-
Chainwork
Chainwork ?>
+
Chainwork
chainwork ?>
-
MerkleRoot
MerkleRoot ?>
+
MerkleRoot
merkle_root ?>
-
NameClaimRoot
NameClaimRoot ?>
+
NameClaimRoot
name_claim_root ?>
-
Target
Target ?>
+
Target
Target' ?>
-
Version
Version ?>
+
Version
version ?>
@@ -109,10 +109,10 @@ -
Hash ?>
- InputCount ?> - OutputCount ?> -
Amount->formatCurrency($tx->Value) ?> LBC
+
hash ?>
+ input_count ?> + output_count ?> +
Amount->formatCurrency($tx->value()) ?> LBC
@@ -181,13 +181,13 @@ - Height ?> - Difficulty, 8, '.', '') ?> - Height - $block->Height) + 1), 0, '', ',') ?> - TransactionHashes)) ?> - BlockSize / 1024, 2) . 'KB' ?> - Nonce ?> - BlockTime)->format('d M Y H:i:s') ?> UTC + Height ?> + d0ifficulty, 8, '.', '') ?> + height - $block->height) + 1), 0, '', ',') ?> + transaction_hashes)) ?> + block_size / 1024, 2) . 'KB' ?> + nonce ?> + block_time)->format('d M Y H:i:s') ?> UTC diff --git a/src/Template/Main/index.ctp b/src/Template/Main/index.ctp index 8b0ecf3..5866da6 100644 --- a/src/Template/Main/index.ctp +++ b/src/Template/Main/index.ctp @@ -129,12 +129,12 @@
Block Height
-
Height ?>
+
height ?>
Difficulty
-
Difficulty, 2, '.', '') ?>
+
difficulty, 2, '.', '') ?>
@@ -167,13 +167,13 @@ - - Height ?> - BlockTime)->diffForHumans(); ?> - BlockSize / 1024, 2) . 'KB' ?> - TransactionCount ?> - Difficulty, 2, '.', '') ?> - BlockTime)->format('d M Y H:i:s') . ' UTC' ?> + + height ?> + block_time)->diffForHumans(); ?> + block_size / 1024, 2) . 'KB' ?> + transaction_count ?> + difficulty, 2, '.', '') ?> + block_time)->format('d M Y H:i:s') . ' UTC' ?> @@ -186,11 +186,11 @@ 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(); ?> -
+
- IsNSFW): ?> + is_nsfw): ?>
NSFW
- IsNSFW && strlen(trim($claim->ThumbnailUrl)) > 0): ?> - + is_nsfw && strlen(trim($claim->thumbnail_url)) > 0): ?> +
- Transaction + Transaction
diff --git a/src/Template/Main/tx.ctp b/src/Template/Main/tx.ctp index f4f4523..7372812 100644 --- a/src/Template/Main/tx.ctp +++ b/src/Template/Main/tx.ctp @@ -14,22 +14,22 @@

LBRY Transaction

-

Hash ?>

+

hash ?>

Time Created

-
Created->format('j M Y H:i:s') . ' UTC '; ?>
+
created_at->format('j M Y H:i:s') . ' UTC '; ?>

Block Time

-
TransactionTime == null || strlen(trim($tx->TransactionTime)) == 0) ? 'Not yet confirmed' : - \DateTime::createFromFormat('U', $tx->TransactionTime)->format('j M Y H:i:s') . ' UTC' ?> +
transaction_time == null || strlen(trim($tx->transaction_time)) == 0) ? 'Not yet confirmed' : + \DateTime::createFromFormat('U', $tx->transaction_time)->format('j M Y H:i:s') . ' UTC' ?> - TransactionTime > $tx->Created->getTimestamp()): - $diffSeconds = $tx->TransactionTime - $tx->Created->getTimestamp(); + 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 @@
Amount (LBC)
-
Amount->format($tx->Value) ?>
+
Amount->format($tx->value()) ?>
Block Height
- BlockHash) || strlen(trim($tx->BlockHash)) === 0): ?> + block_hash_id) || strlen(trim($tx->block_hash_id)) === 0): ?>
Unconf.
- +
@@ -66,17 +66,17 @@
Size (bytes)
-
TransactionSize, 0, '', ',') ?>
+
transaction_size, 0, '', ',') ?>
Inputs
-
InputCount ?>
+
input_count ?>
Outputs
-
OutputCount ?>
+
output_count ?>
@@ -86,28 +86,28 @@

Details

-
InputCount ?> inputInputCount === 1 ? '' : 's'; ?>
+
input_count ?> inputinput_count === 1 ? '' : 's'; ?>
-
- +
+ is_coinbase): ?>
Block Reward (New Coins)
- Value)) == 0): ?> + value)) == 0): ?>
Incomplete data
Address])): - $setAddressIds[$addr->Address] = 1; ?> - + if (!isset($setAddressIds[$addr->address])): + $setAddressIds[$addr->address] = 1; ?> + -
Amount->format($in['Value']) ?> LBC from
-
Address ?> - (output) +
Amount->format($in->value) ?> LBC from
+
address ?> + (output) Tag) && strlen(trim($addr->Tag)) > 0): ?>
TagUrl)) > 0): ?>Tag ?>Tag; endif; ?> @@ -125,7 +125,7 @@
-
OutputCount ?> outputOutputCount === 1 ? '' : 's'; ?> +
output_count ?> outputoutput_count === 1 ? '' : 's'; ?> 0): ?> Fee Amount->format($fee) ?> LBC @@ -134,7 +134,7 @@ -
+
Claim && ($out->IsClaim or $out->IsSupportClaim or $out->IsUpdateClaim)): ?>View IsSupportClaim): ?>
SUPPORT
@@ -152,9 +152,9 @@
Amount->format($out['Value']) ?> LBC to
-
Address ?> +
address ?> - IsSpent): ?>(spent)(unspent) + is_spent): ?>(spent)(unspent) Tag) && strlen(trim($addr->Tag)) > 0): ?>
diff --git a/webroot/css/bids-chart.css b/webroot/css/bids-chart.css new file mode 100644 index 0000000..48a41f4 --- /dev/null +++ b/webroot/css/bids-chart.css @@ -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% } +} \ No newline at end of file diff --git a/webroot/js/bids-chart.js b/webroot/js/bids-chart.js new file mode 100644 index 0000000..d025d04 --- /dev/null +++ b/webroot/js/bids-chart.js @@ -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(); +}); \ No newline at end of file