Chainquery integration #49

Merged
marcdeb1 merged 44 commits from chainquery into master 2019-02-13 19:01:13 +01:00
4 changed files with 111 additions and 42 deletions
Showing only changes of commit af39804ce7 - Show all commits

View file

@ -228,7 +228,7 @@ return [
* 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' => '3000', //'port' => '3000',
'username' => 'username', 'username' => 'username',
'password' => 'secret', 'password' => 'secret',
'database' => 'my_db', 'database' => 'my_db',
@ -271,8 +271,8 @@ return [
* the following line and set the port accordingly * the following line and set the port accordingly
*/ */
//'port' => '3306', //'port' => '3306',
'username' => 'root', 'username' => 'username',
//'password' => 'secret', 'password' => 'secret',
'database' => 'lbry', 'database' => 'lbry',
'encoding' => 'utf8', 'encoding' => 'utf8',
'timezone' => 'UTC', 'timezone' => 'UTC',

View file

@ -134,7 +134,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 claim'); $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;
@ -156,7 +156,7 @@ class MainController extends AppController {
} }
for ($i = 0; $i < count($claims); $i++) { for ($i = 0; $i < count($claims); $i++) {
if ($canConvert && $claims[$i]->Fee > 0 && $claims[$i]->fee_currency == '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;
} }
@ -477,11 +477,11 @@ class MainController extends AppController {
$tagRequestAmount = '25.' . rand(11111111, 99999999); $tagRequestAmount = '25.' . rand(11111111, 99999999);
} }
$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('/');
} }
@ -489,11 +489,11 @@ class MainController extends AppController {
$conn = ConnectionManager::get('default'); $conn = ConnectionManager::get('default');
$canTag = true; $canTag = true;
$addressId = $address->Id; $addressId = $address->id;
$stmt = $conn->execute('SELECT COUNT(TransactionId) AS Total FROM TransactionsAddresses WHERE AddressId = ?', [$addressId]); $stmt = $conn->execute('SELECT * FROM transaction_address WHERE address_id = ?', [$addressId]);
$count = $stmt->fetch(\PDO::FETCH_OBJ); $transactionAddresses = $stmt->fetch(\PDO::FETCH_OBJ);
$numTransactions = $count->Total; $numTransactions = count($transactionAddresses);
$all = $this->request->query('all'); $all = $this->request->query('all');
if ($all === 'true') { if ($all === 'true') {
$offset = 0; $offset = 0;
@ -512,26 +512,25 @@ 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]); $currentBlock = $this->Blocks->find()->select(['height'])->order(['height' => 'desc'])->first();
$totals = $stmt->fetch(\PDO::FETCH_OBJ); $currentHeight = $currentBlock ? intval($currentBlock->height) : 0;
$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' .
' 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 = ? ORDER BY transaction_time DESC LIMIT %d, %d) TA ON TA.transaction_id = T.id', $offset, $pageLimit), [$addressId]);
$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 = $totalSentAmount - $totalRecvAmount;
} }
$this->set('offset', $offset); $this->set('offset', $offset);

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

@ -183,8 +183,78 @@ if (strlen(trim($desc)) == 0) {
if ($idx % 3 == 0) { if ($idx % 3 == 0) {
$row++; $row++;
} }
echo $this->element('claimbox', array('claim' => $claim)); $autoThumbText = $claim->getAutoThumbText();
$idx++; $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';
}
// 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 ($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 ?>#output-<?php echo $claim->vout ?>" title="<?php echo $claim->transaction_hash ?>"><?php echo $claim->transaction_hash ?></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 == 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->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><?php
$idx++;
endforeach; ?> endforeach; ?>
<div class="clear"></div> <div class="clear"></div>
</div> </div>