Commit bdb433cf authored by Kalinka's avatar Kalinka
Browse files

Update

parent 9f391389
......@@ -19,9 +19,9 @@ class AccountController extends AbstractController
a.creation_height AS first_block,
a.height AS last_block,
FORMAT(a.forged_balance/ 100000000, 2) as forged_balance,
FORMAT(( SELECT SUM(b.total_fee) FROM block b WHERE generator_id = a.id)/ 100000000, 2) AS pool_balance_fee,
(( SELECT SUM(b.total_fee) FROM block b WHERE generator_id = a.id)/ 100000000) AS pool_balance_fee,
( SELECT SUM(FLOOR(pow(0.95,FLOOR(b.height/10800))*10000)) FROM block b WHERE b.generator_id = a.id) AS pool_balance_forged,
( SELECT rid.recipient_id
( SELECT CAST(rid.recipient_id AS UNSIGNED)
FROM transaction rid
WHERE rid.type = 20 AND rid.height <= ? -3 AND rid.sender_id = a.id
ORDER BY rid.height DESC
......@@ -50,7 +50,6 @@ class AccountController extends AbstractController
) as moss ) AS mos_recieved
FROM account a
WHERE CAST(a.id AS UNSIGNED) = ? AND a.latest = 1';
// input: max-height, max-height, account-id
private $entityManager;
......
......@@ -2,6 +2,7 @@
namespace App\Controller;
use Doctrine\DBAL\ParameterType;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
......@@ -10,6 +11,8 @@ use Exception;
class TransactionController extends AbstractController
{
const TxPerPage = 50;
const TransactionsByHeight = " SELECT CAST(t.id AS UNSIGNED) AS id,
CAST(t.sender_id AS UNSIGNED) AS sender_id,
s.name AS sender_name,
......@@ -18,73 +21,14 @@ class TransactionController extends AbstractController
FORMAT(t.fee / 100000000, 2) AS fee,
FORMAT(t.amount / 100000000, 2) AS amount,
t.timestamp + 1407722400 AS unixtime,
CASE
WHEN t.type = 0 THEN
-- Type: Payment
CASE
WHEN t.subtype = 0 THEN 'Ordinary Payment'
WHEN t.subtype = 1 THEN 'MultiOut Payment'
WHEN t.subtype = 2 THEN 'MultiOut-Same Payment'
END
WHEN t.type = 1 THEN
-- Type: Messaging
CASE
WHEN t.subtype = 0 THEN 'Arbritrary Message'
WHEN t.subtype = 1 THEN 'Alias Assignment'
WHEN t.subtype = 5 THEN 'Account Info'
WHEN t.subtype = 6 THEN 'Alias Sell'
WHEN t.subtype = 7 THEN 'Alias Buy'
END
WHEN t.type = 2 THEN
CASE
WHEN t.subtype = 0 THEN 'Asset Issued'
WHEN t.subtype = 1 THEN 'Asset Transfer'
WHEN t.subtype = 2 THEN 'Ask Order Placement'
WHEN t.subtype = 3 THEN 'Bid Order Placement'
WHEN t.subtype = 4 THEN 'Ask Order Cancellation'
WHEN t.subtype = 5 THEN 'Bid Order Cancellation'
END
WHEN t.type = 3 THEN
CASE
WHEN t.subtype = 0 THEN 'Marketplace Listing'
WHEN t.subtype = 1 THEN 'Marketplace Delisting'
WHEN t.subtype = 2 THEN 'Marketplace Price Change'
WHEN t.subtype = 3 THEN 'Marketplace Quantity Change'
WHEN t.subtype = 4 THEN 'Marketplace Purchase'
WHEN t.subtype = 5 THEN 'Marketplace Delivery'
WHEN t.subtype = 6 THEN 'Marketplace Feedback'
WHEN t.subtype = 7 THEN 'Marketplace Refund'
END
WHEN t.type = 4 THEN
CASE
WHEN t.subtype = 0 THEN 'Effective Balance Leasing'
END
WHEN t.type = 20 THEN
CASE
WHEN t.subtype = 0 THEN 'Reward Recipient'
END
WHEN t.type = 21 THEN
CASE
WHEN t.subtype = 0 THEN 'Escrow Creation'
WHEN t.subtype = 1 THEN 'Escrow Signing'
WHEN t.subtype = 2 THEN 'Escrow Result'
WHEN t.subtype = 3 THEN 'Subscription Subscribe'
WHEN t.subtype = 4 THEN 'Subscription Cancel'
WHEN t.subtype = 5 THEN 'Subscription Payment'
END
WHEN t.type = 22 THEN
CASE
WHEN t.subtype = 0 THEN 'AT Creation'
WHEN t.subtype = 1 THEN 'AT Payment'
END
ELSE 'unkown transaction type'
END as transaction_type,
(SELECT count(mo.db_id) FROM mo WHERE mo.db_id = t.db_id) AS mo_count,
(SELECT count(mosr.db_id) FROM mosr WHERE mosr.db_id = t.db_id) AS mosr_count
getTransactionType(t.type, t.subtype) as transaction_type -- ,
-- (SELECT count(mo.db_id) FROM mo WHERE mo.db_id = t.db_id) AS mo_count,
-- (SELECT count(mosr.db_id) FROM mosr WHERE mosr.db_id = t.db_id) AS mosr_count
FROM transaction t
LEFT JOIN account s ON (t.sender_id = s.id AND s.latest = 1)
LEFT JOIN account r ON (t.recipient_id = r.id AND r.latest = 1)
WHERE t.height = ?";
WHERE t.height = ?
LIMIT ?,?";
const TransactionsByBlockId = " SELECT CAST(t.id AS UNSIGNED) AS id,
......@@ -95,74 +39,53 @@ class TransactionController extends AbstractController
FORMAT(t.fee / 100000000, 2) AS fee,
FORMAT(t.amount / 100000000, 2) AS amount,
t.timestamp + 1407722400 AS unixtime,
CASE
WHEN t.type = 0 THEN
-- Type: Payment
CASE
WHEN t.subtype = 0 THEN 'Ordinary Payment'
WHEN t.subtype = 1 THEN 'MultiOut Payment'
WHEN t.subtype = 2 THEN 'MultiOut-Same Payment'
END
WHEN t.type = 1 THEN
-- Type: Messaging
CASE
WHEN t.subtype = 0 THEN 'Arbritrary Message'
WHEN t.subtype = 1 THEN 'Alias Assignment'
WHEN t.subtype = 5 THEN 'Account Info'
WHEN t.subtype = 6 THEN 'Alias Sell'
WHEN t.subtype = 7 THEN 'Alias Buy'
END
WHEN t.type = 2 THEN
CASE
WHEN t.subtype = 0 THEN 'Asset Issued'
WHEN t.subtype = 1 THEN 'Asset Transfer'
WHEN t.subtype = 2 THEN 'Ask Order Placement'
WHEN t.subtype = 3 THEN 'Bid Order Placement'
WHEN t.subtype = 4 THEN 'Ask Order Cancellation'
WHEN t.subtype = 5 THEN 'Bid Order Cancellation'
END
WHEN t.type = 3 THEN
CASE
WHEN t.subtype = 0 THEN 'Marketplace Listing'
WHEN t.subtype = 1 THEN 'Marketplace Delisting'
WHEN t.subtype = 2 THEN 'Marketplace Price Change'
WHEN t.subtype = 3 THEN 'Marketplace Quantity Change'
WHEN t.subtype = 4 THEN 'Marketplace Purchase'
WHEN t.subtype = 5 THEN 'Marketplace Delivery'
WHEN t.subtype = 6 THEN 'Marketplace Feedback'
WHEN t.subtype = 7 THEN 'Marketplace Refund'
END
WHEN t.type = 4 THEN
CASE
WHEN t.subtype = 0 THEN 'Effective Balance Leasing'
END
WHEN t.type = 20 THEN
CASE
WHEN t.subtype = 0 THEN 'Reward Recipient'
END
WHEN t.type = 21 THEN
CASE
WHEN t.subtype = 0 THEN 'Escrow Creation'
WHEN t.subtype = 1 THEN 'Escrow Signing'
WHEN t.subtype = 2 THEN 'Escrow Result'
WHEN t.subtype = 3 THEN 'Subscription Subscribe'
WHEN t.subtype = 4 THEN 'Subscription Cancel'
WHEN t.subtype = 5 THEN 'Subscription Payment'
END
WHEN t.type = 22 THEN
CASE
WHEN t.subtype = 0 THEN 'AT Creation'
WHEN t.subtype = 1 THEN 'AT Payment'
END
ELSE 'unkown transaction type'
END as transaction_type,
(SELECT count(mo.db_id) FROM mo WHERE mo.db_id = t.db_id) AS mo_count,
(SELECT count(mosr.db_id) FROM mosr WHERE mosr.db_id = t.db_id) AS mosr_count
getTransactionType(t.type, t.subtype) as transaction_type -- ,
-- (SELECT count(mo.db_id) FROM mo WHERE mo.db_id = t.db_id) AS mo_count,
-- (SELECT count(mosr.db_id) FROM mosr WHERE mosr.db_id = t.db_id) AS mosr_count
FROM transaction t
LEFT JOIN account s ON (t.sender_id = s.id AND s.latest = 1)
LEFT JOIN account r ON (t.recipient_id = r.id AND r.latest = 1)
JOIN block b ON (t.height = b.height)
WHERE b.id = ?";
WHERE b.id = ?
LIMIT ?,?";
const TransactionCountByAccountId = "SELECT SUM(TXcount) AS TXs FROM (
SELECT count(t.id) AS TXcount
FROM transaction t
WHERE CAST(t.sender_id AS UNSIGNED) = ? OR CAST(t.recipient_id AS UNSIGNED) = ?
UNION
SELECT count(mosr.recipient_id) AS TXcount
FROM mosr
WHERE CAST(mosr.recipient_id AS UNSIGNED) = ?
UNION
SELECT count(mo.recipient_id) AS TXcount
FROM mo
WHERE CAST(mo.recipient_id AS UNSIGNED) = ?
) as x
";
const TransactionByAccountId = " SELECT
CAST(t.id AS UNSIGNED) AS id,
CAST(t.sender_id AS UNSIGNED) AS sender_id,
s.name AS sender_name,
CAST(t.recipient_id AS UNSIGNED) AS recipient_id,
r.name AS recipient_name,
FORMAT(t.fee / 100000000, 2) AS fee,
FORMAT(t.amount / 100000000, 2) AS amount,
t.timestamp + 1407722400 AS unixtime,
getTransactionType(t.type, t.subtype) as transaction_type -- ,
-- (SELECT count(mo.db_id) FROM mo WHERE mo.db_id = t.db_id) AS mo_count,
-- (SELECT count(mosr.db_id) FROM mosr WHERE mosr.db_id = t.db_id) AS mosr_count
FROM transaction t
LEFT JOIN account s ON (t.sender_id = s.id AND s.latest = 1)
LEFT JOIN account r ON (t.recipient_id = r.id AND r.latest = 1)
WHERE CAST(t.sender_id AS UNSIGNED) = ? OR CAST(t.recipient_id AS UNSIGNED) = ?
ORDER BY t.timestamp DESC
LIMIT ?,?";
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
......@@ -171,29 +94,114 @@ class TransactionController extends AbstractController
}
/**
* @param $height
* @Route("/transactions/byHeight/{height}", name="transactions_by_height")
* @param $id
* @param $page
* @Route("/transactions/byHeight/{id}/{page}", name="transactions_by_height", defaults={"page"=0})
* @throws Exception
* @return Response
*/
public function getBlockTransactionsByHeight($height) {
public function getBlockTransactionsByHeight($id, $page) {
// Height is called ID here to use a unified transactionlist template
$start = $page * self::TxPerPage;
$con = $this->entityManager->getConnection();
$stmt = $con->prepare(self::TransactionsByHeight);
$stmt->bindValue(1, $height);
$stmt->bindValue(1, $id);
$stmt->bindValue(2, $start, ParameterType::INTEGER);
$stmt->bindValue(3, self::TxPerPage, ParameterType::INTEGER);
$stmt->execute();
$transactions = $stmt->fetchAll();
$Data = $this->paginationCalculator(count($transactions), $page);
$Data['transactions'] = $transactions;
$Data['route'] = 'transactions_by_height';
$Data['id'] = $id;
return $this->render('transaction.list.html.twig', $Data);
}
/**
* @param $blockId
* @param $page
* @Route("/transactions/byBlockId/{id}/{page}", name="transactions_by_blockId", defaults={"page"=0})
* @throws Exception
* @return Response
*/
public function getBlockTransactionsByBlockId($id, $page) {
$start = $page * self::TxPerPage;
$con = $this->entityManager->getConnection();
$stmt = $con->prepare(self::TransactionsByBlockId);
$stmt->bindValue(1, $id);
$stmt->bindValue(2, $start, ParameterType::INTEGER);
$stmt->bindValue(3, self::TxPerPage, ParameterType::INTEGER);
$stmt->execute();
$transactions = $stmt->fetchAll();
return $this->render('transaction.list.html.twig', [
'transactions' => $transactions
]);
$Data = $this->paginationCalculator(count($transactions), $page);
$Data['transactions'] = $transactions;
$Data['route'] = 'transactions_by_blockId';
$Data['id'] = $id;
return $this->render('transaction.list.html.twig', $Data);
}
public function getBlockTransactionsByBlockId($blockId) {
/**
* @param $accountId
* @param $page
* @return Response
* @throws Exception
* @Route("/transactions/byAccountId/{id}/{page}", name="transactions_by_accountId", defaults={"page"=0})
*/
public function getAccountTransactionsByAccountId($id, $page) {
$start = $page * self::TxPerPage;
$con = $this->entityManager->getConnection();
$stmt = $con->prepare(self::TransactionByAccountId);
$stmt->bindValue(1, $id);
$stmt->bindValue(2, $id);
$stmt->bindValue(3, $start, ParameterType::INTEGER);
$stmt->bindValue(4, self::TxPerPage, ParameterType::INTEGER);
$stmt->execute();
$transactions = $stmt->fetchAll();
$Data = $this->paginationCalculator(count($transactions), $page);
$Data['transactions'] = $transactions;
$Data['route'] = 'transactions_by_accountId';
$Data['id'] = $id;
return $this->render('transaction.list.html.twig', $Data);
}
public function getAccountTransactionsByAccountId($accountId) {
/**
* Returns Pagination Information in an array
*
* @param $txCount
* @param $currentPage
* @return array
*/
private function paginationCalculator($txCount, $currentPage) {
$lastPage = floor($txCount / self::TxPerPage);
$pageLinks = [];
for($i=$currentPage; $i >= 0 && $i >= $currentPage - 3 && $i <= $lastPage; $i--) {
$pageLinks[] = $i;
}
for($i=$currentPage; $i >= $currentPage && $i <= $currentPage + 3 && $i <= $lastPage; $i++) {
$pageLinks[] = $i;
}
$pageLinks = array_unique($pageLinks);
sort($pageLinks);
return [
'page' => $currentPage,
'lastPage' => $lastPage,
'pageLinks' => $pageLinks,
];
}
......
......@@ -36,5 +36,24 @@
</div>
<div class="col-md-3"></div>
</div>
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<ul class="nav nav-tabs" id="accountTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="tx-tab" data-toggle="tab" href="#tx" role="tab" aria-controls="tx" aria-selected="true">Transactions ({{ (account.count_sent + account.tx_count + account.mo_count + account.mos_count) }})</a>
</li>
<li class="nav-item">
<a class="nav-link" id="asset-tab" data-toggle="tab" href="#asset" role="tab" aria-controls="asset" aria-selected="false">Asset Transfers</a>
</li>
</ul>
<div class="tab-content" id="accountTabContent">
<div class="tab-pane fade show active" id="tx" role="tabpanel" aria-labelledby="tx-tab">
<div class="include-html" id="tx-list" include-html="{{ url('transactions_by_accountId', {'id': account.id }) }}">Loading....</div>
</div>
<div class="tab-pane fade" id="asset" role="tabpanel" aria-labelledby="asset-tab">Asset, to be done</div>
</div>
</div>
<div class="col-md-2"></div>
</div>
{% endblock %}
\ No newline at end of file
......@@ -61,7 +61,7 @@
</ul>
<div class="tab-content" id="blockTabContent">
<div class="tab-pane fade show active" id="tx" role="tabpanel" aria-labelledby="tx-tab">
{{ render_hinclude(url('transactions_by_height', {'height': block.height }), {'default': 'Loading....'}) }}
{{ render_hinclude(url('transactions_by_blockId', {'id': block.id }), {'default': 'Loading....'}) }}
</div>
<div class="tab-pane fade" id="asset" role="tabpanel" aria-labelledby="asset-tab">Asset, to be done</div>
</div>
......
<script src="{{ asset('dev/jquery-3.4.1.min.js') }}"></script>
<script src="{{ asset('dev/bootstrap.bundle.js') }}"></script>
<script src="{{ asset('dev/hinclude.js') }}"></script>
\ No newline at end of file
<script src="{{ asset('dev/hinclude.js') }}"></script>
<script>
function includeHTML() {
var z, i, elmnt, file, xhttp;
/* Loop through a collection of all HTML elements: */
z = document.getElementsByClassName("include-html");
for (i = 0; i < z.length; i++) {
elmnt = z[i];
/*search for elements with a certain atrribute:*/
file = elmnt.getAttribute("include-html");
if (file) {
/* Make an HTTP request using the attribute value as the file name: */
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {elmnt.innerHTML = this.responseText;}
if (this.status == 404) {elmnt.innerHTML = "Page not found.";}
/* Remove the attribute, and call this function once more: */
elmnt.removeAttribute("include-html");
includeHTML();
}
}
xhttp.open("GET", file, true);
xhttp.send();
/* Exit the function: */
return;
}
}
}
// without jQuery (doesn't work in older IEs)
document.addEventListener('DOMContentLoaded', function(){
includeHTML();
}, false);
function nextPage(element_id, url) {
elem = document.getElementById(element_id);
elem.setAttribute('include-html', url);
elem.innerText = 'Loading....';
includeHTML();
}
</script>
\ No newline at end of file
<ul class="pagination">
{% if 0 not in pageLinks %}
<li class="page-item">
<a class="page-link" href="#" onclick="nextPage('tx-list', '{{ path(route, {'id': id, 'page': 0 }) }}')">
1
</a>
</li>
<li class="page-item"><span class="page-link">&nbsp;</span></li>
{% endif %}
{% if page != 0 %}
<li class="page-item">
<a class="page-link" href="#" onclick="nextPage('tx-list', '{{ path(route, {'id': id, 'page': page - 1 }) }}')">
&laquo;
</a>
</li>
{% endif %}
{% for pageLink in pageLinks %}
{% if pageLink != page %}
<li class="page-item">
<a class="page-link" href="#" onclick="nextPage('tx-list', '{{ path(route, {'id': id, 'page': pageLink }) }}')">
{{ pageLink + 1 }}</a>
</li>
{% else %}
<li class="page-item active"><span class="page-link">{{ pageLink + 1 }}</span></li>
{% endif %}
{% endfor %}
{% if page != lastPage %}
<li class="page-item">
<a class="page-link" href="#" onclick="nextPage('tx-list', '{{ path(route, {'id': id, 'page': page + 1 }) }}')">
&raquo;
</a>
</li>
<li class="page-item"><span class="page-link">&nbsp;</span></li>
<li class="page-item">
<a class="page-link" href="#" onclick="nextPage('tx-list', '{{ path(route, {'id': id, 'page': lastPage, }) }}')">
{{ lastPage + 1 }}
</a>
</li>
{% endif %}
</ul>
<table class="table table-striped table-bordered table-hover table-sm">
<thead>
<th>ID</th>
......@@ -23,10 +63,8 @@
<a href="{{ path('account_details', {id: transaction.recipient_id | toAccountId }) }}">
{{ transaction.recipient_id | toRSAddress }}<br />{{ transaction.recipient_name }}
</a>
{% elseif transaction.mo_count is not null %}
{{ transaction.mo_count }} Recipients, <a href="#">Details</a>
{% elseif transaction.mosr_count is not null %}
{{ transaction.mosr_count }} Recipients, <a href="#">Details</a>
{% else%}
Multiple Recipients, <a href="#">Details</a>
{% endif %}
</td>
<td>{{ transaction.amount }}</td>
......
......@@ -64,10 +64,69 @@ BEGIN
WHERE bi.height = in_height;
END$$
DELIMITER ;
-- run "php bin/console explorer:import:blockinfo" afterwards
DELIMITER $$
CREATE FUNCTION getTransactionType(type tinyint(4), subtype tinyint(4))
RETURNS char(100) DETERMINISTIC
BEGIN
IF type = 0 THEN
IF subtype = 0 THEN RETURN 'Ordinary Payment';
ELSEIF subtype = 1 THEN RETURN 'MultiOut Payment';
ELSEIF subtype = 2 THEN RETURN 'MultiOut-Same Payment';
END IF;
ELSEIF type = 1 THEN
IF subtype = 0 THEN RETURN 'Arbritrary Message';
ELSEIF subtype = 1 THEN RETURN 'Alias Assignment';
ELSEIF subtype = 5 THEN RETURN 'Account Info';
ELSEIF subtype = 6 THEN RETURN 'Alias Sell';
ELSEIF subtype = 7 THEN RETURN 'Alias Buy';
END IF;
ELSEIF type = 2 THEN
IF subtype = 0 THEN RETURN 'Asset Issued';
ELSEIF subtype = 1 THEN RETURN 'Asset Transfer';
ELSEIF subtype = 2 THEN RETURN 'Ask Order Placement';
ELSEIF subtype = 3 THEN RETURN 'Bid Order Placement';
ELSEIF subtype = 4 THEN RETURN 'Ask Order Cancellation';
ELSEIF subtype = 5 THEN RETURN 'Bid Order Cancellation';
END IF;
ELSEIF type = 3 THEN
IF subtype = 0 THEN RETURN 'Marketplace Listing';
ELSEIF subtype = 1 THEN RETURN 'Marketplace Delisting';
ELSEIF subtype = 2 THEN RETURN 'Marketplace Price Change';
ELSEIF subtype = 3 THEN RETURN 'Marketplace Quantity Change';
ELSEIF subtype = 4 THEN RETURN 'Marketplace Purchase';
ELSEIF subtype = 5 THEN RETURN 'Marketplace Delivery';
ELSEIF subtype = 6 THEN RETURN 'Marketplace Feedback';
ELSEIF subtype = 7 THEN RETURN 'Marketplace Refund';
END IF;
ELSEIF type = 4 THEN
IF subtype = 0 THEN RETURN 'Effective Balance Leasing';
END IF;
ELSEIF type = 20 THEN
IF subtype = 0 THEN RETURN 'Reward Recipient';
END IF;
ELSEIF type = 21 THEN
IF subtype = 0 THEN RETURN 'Escrow Creation';
ELSEIF subtype = 1 THEN RETURN 'Escrow Signing';
ELSEIF subtype = 2 THEN RETURN 'Escrow Result';
ELSEIF subtype = 3 THEN RETURN 'Subscription Subscribe';
ELSEIF subtype = 4 THEN RETURN 'Subscription Cancel';
ELSEIF subtype = 5 THEN RETURN 'Subscription Payment';
END IF;
ELSEIF type = 22 THEN
IF subtype = 0 THEN RETURN 'AT Creation';
ELSEIF subtype = 1 THEN RETURN 'AT Payment';
END IF;
ELSE
RETURN 'unkown transaction type';
END IF;
END $$
DELIMITER ;
CREATE TABLE `mo` (
`db_id` bigint(20) NOT NULL,
`recipient_id` bigint(20) NOT NULL,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment