Commit e74df80f authored by Kalinka's avatar Kalinka

SQL/:

  - Add Functions to retrive infos about Accounts
src/Controller/AccountController.php:
  - Update SQL Queries, for less performance but more readable.
templates/account.details.html.twig:
  - Update to new Variable Names
parent 1d75812a
......@@ -2,6 +2,45 @@
Functions
*/
DROP FUNCTION IF EXISTS getPoolMinedAmount;
DELIMITER $$
CREATE FUNCTION getPoolMinedAmount(in_id bigint(20))
RETURNS BIGINT(20) DETERMINISTIC
BEGIN
RETURN (
SELECT SUM(getRewardByHeight(bi.height)*100000000 + b.total_fee)
FROM block_info bi
JOIN block b ON (b.height = bi.height)
WHERE bi.generator_id = in_id AND bi.recipient_id <> in_id
);
END$$
DELIMITER ;
DROP FUNCTION IF EXISTS getRewardedAmount;
DELIMITER $$
CREATE FUNCTION getRewardedAmount(in_id bigint(20))
RETURNS BIGINT(20) DETERMINISTIC
BEGIN
RETURN (
SELECT SUM(getRewardByHeight(bi.height)*100000000 + b.total_fee)
FROM block_info bi
JOIN block b ON (b.height = bi.height)
WHERE bi.recipient_id = in_id AND bi.generator_id <> in_id
);
END$$
DELIMITER ;
DROP FUNCTION IF EXISTS isPool;
DELIMITER $$
CREATE FUNCTION isPool(in_id bigint(20))
RETURNS BOOL DETERMINISTIC
BEGIN
IF (SELECT COUNT(*) from reward_recip_assign WHERE recip_id = in_id AND latest = 1) > 1 THEN RETURN TRUE;
ELSE RETURN FALSE;
END IF;
END$$
DELIMITER ;
DROP FUNCTION IF EXISTS getTransactionCountByAccountId;
DELIMITER $$
CREATE FUNCTION getTransactionCountByAccountId(in_id bigint(20))
......
......@@ -2,6 +2,46 @@
Functions
*/
DROP FUNCTION IF EXISTS getPoolMinedAmount;
DELIMITER $$
CREATE FUNCTION getPoolMinedAmount(in_id bigint(20))
RETURNS BIGINT(20) DETERMINISTIC
BEGIN
RETURN (
SELECT SUM(getRewardByHeight(bi.height)*100000000 + b.total_fee)
FROM block_info bi
JOIN block b ON (b.height = bi.height)
WHERE bi.generator_id = in_id AND bi.recipient_id <> in_id
);
END$$
DELIMITER ;
DROP FUNCTION IF EXISTS getRewardedAmount;
DELIMITER $$
CREATE FUNCTION getRewardedAmount(in_id bigint(20))
RETURNS BIGINT(20) DETERMINISTIC
BEGIN
RETURN (
SELECT SUM(getRewardByHeight(bi.height)*100000000 + b.total_fee)
FROM block_info bi
JOIN block b ON (b.height = bi.height)
WHERE bi.recipient_id = in_id AND bi.generator_id <> in_id
);
END$$
DELIMITER ;
DROP FUNCTION IF EXISTS isPool;
DELIMITER $$
CREATE FUNCTION isPool(in_id bigint(20))
RETURNS BOOL DETERMINISTIC
BEGIN
IF (SELECT COUNT(*) from reward_recip_assign WHERE recip_id = in_id AND latest = 1) > 1 THEN RETURN TRUE;
ELSE RETURN FALSE;
END IF;
END$$
DELIMITER ;
DROP FUNCTION IF EXISTS getTransactionCountByAccountId;
DELIMITER $$
CREATE FUNCTION getTransactionCountByAccountId(in_id bigint(20))
......
......@@ -10,8 +10,6 @@ use Doctrine\ORM\EntityManagerInterface;
class AccountController extends AbstractController
{
const LatestHeight = ' SELECT MAX(height) as height FROM block';
const AccountDetails = 'SELECT CAST(a.id AS UNSIGNED) as id,
FORMAT(a.balance/ 100000000, 2) as balance,
a.public_key,
......@@ -21,23 +19,19 @@ class AccountController extends AbstractController
getTransactionCountByAccountId(a.id) AS tx_total_count,
getIncomingTransactionCountByAccountId(a.id) AS tx_in_count,
getOutgoingTransactionCountByAccountId(a.id) AS tx_out_count,
FORMAT(a.forged_balance/ 100000000, 2) as forged_balance,
(( 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 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
LIMIT 1) AS pool_id,
isPool(a.id) AS is_pool,
getPoolMinedAmount(a.id) / 100000000 AS pool_mined_amount,
getRewardedAmount(a.id) / 100000000 AS rewarded_amount,
a.forged_balance / 100000000 as solo_mined_amount,
( SELECT CAST(rra.recip_id AS UNSIGNED)
FROM reward_recip_assign rra
WHERE rra.account_id = a.id AND rra.latest = 1) AS pool_id,
( SELECT pa.name
FROM transaction rname
LEFT JOIN account pa ON (pa.id = rname.recipient_id AND pa.latest = 1)
WHERE rname.type = 20 AND rname.height <= ? -3 AND rname.sender_id = a.id
ORDER BY rname.height DESC
LIMIT 1) AS pool_name,
FROM reward_recip_assign rra
LEFT JOIN account pa ON (rra.recip_id = pa.id AND pa.latest = 1)
WHERE rra.account_id = a.id AND rra.latest = 1) AS pool_name,
FORMAT(( SELECT SUM(t.fee) FROM transaction t WHERE t.sender_id = a.id)/ 100000000, 2) AS fees_paid,
FORMAT(( SELECT SUM(t.amount) FROM transaction t WHERE t.sender_id = a.id)/ 100000000, 2) AS burst_sent,
( SELECT COUNT(t.amount) FROM transaction t WHERE t.sender_id = a.id) AS count_sent,
( SELECT SUM(t.amount) FROM transaction t WHERE t.recipient_id = a.id) AS burst_recieved,
( SELECT SUM(mo.amount) FROM mo WHERE mo.recipient_id = a.id) AS mo_recieved,
( SELECT SUM(moss.amount)
......@@ -64,16 +58,11 @@ class AccountController extends AbstractController
*/
public function accountDetails($id) {
$con = $this->entityManager->getConnection();
$stmt = $con->prepare(self::LatestHeight);
$stmt->execute();
$Latest = $stmt->fetch();
$stmt = $con->prepare(self::AccountDetails);
$stmt->bindValue(1, $Latest['height']);
$stmt->bindValue(2, $Latest['height']);
$stmt->bindValue(3, $id);
$stmt->bindValue(4, $id);
$stmt->bindValue(1, $id);
$stmt->bindValue(2, $id);
$stmt->execute();
$account = $stmt->fetch();
......
......@@ -18,8 +18,13 @@
</tr>
<tr><th>Sent</th><td>{{ account.burst_sent }} {{ getEnv('RS_PREFIX') }} in {{ account.tx_out_count }} transactions</td></tr>
<tr><th>Transaction Fees</th><td>{{ account.fees_paid }} {{ getEnv('RS_PREFIX') }} paid</td></tr>
<tr><th>Potential pool reward</th><td>{{ (account.pool_balance_fee + account.pool_balance_forged) | number_format(2, '.', ',') }} {{ getEnv('RS_PREFIX') }}</td></tr>
<tr><th>Solo mined balance</th><td>{{ account.forged_balance }} {{ getEnv('RS_PREFIX') }}</td></tr>
<tr><th>Pool Mined</th><td>{{ account.pool_mined_amount | number_format(2, '.', ',') }} {{ getEnv('RS_PREFIX') }}</td></tr>
{% if account.is_pool %} }
<tr><th>Solo Mined</th><td>{{ (account.solo_mined_amount - account.rewarded_amount) | number_format(2, '.', ',') }} {{ getEnv('RS_PREFIX') }}</td></tr>
<tr><th>Rewarded</th><td>{{ account.rewarded_amount | number_format(2, '.', ',') }} {{ getEnv('RS_PREFIX') }}</td></tr>
{% else %}
<tr><th>Solo Mined</th><td>{{ account.solo_mined_amount | number_format(2, '.', ',') }} {{ getEnv('RS_PREFIX') }}</td></tr>
{% endif %}
{% if account.pool_id is not null and account.pool_id != account.id %}
<tr><th>Pool</th>
<td>
......
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