Commit 1d75812a authored by Kalinka's avatar Kalinka
Browse files

update SQL-Functions

parent c11610c7
...@@ -2,10 +2,49 @@ ...@@ -2,10 +2,49 @@
Functions Functions
*/ */
DROP FUNCTION IF EXISTS getTransactionCountByAccountId;
DELIMITER $$
CREATE FUNCTION getTransactionCountByAccountId(in_id bigint(20))
RETURNS INT(11) DETERMINISTIC
BEGIN
DECLARE tx_count INT(11);
SET tx_count = getIncomingTransactionCountByAccountId(in_id) + getOutgoingTransactionCountByAccountId(in_id);
RETURN tx_count;
END$$
DELIMITER ;
DROP FUNCTION IF EXISTS getIncomingTransactionCountByAccountId;
DELIMITER $$
CREATE FUNCTION getIncomingTransactionCountByAccountId(in_id bigint(20))
RETURNS INT(11) DETERMINISTIC
BEGIN
DECLARE tx_count INT(11);
SET tx_count = (
(SELECT count(t.id) FROM transaction t WHERE t.recipient_id = in_id) +
(SELECT count(mo.db_id) FROM mo WHERE mo.recipient_id = in_id) +
(SELECT count(mosr.db_id) FROM mosr WHERE mosr.recipient_id = in_id)
);
RETURN tx_count;
END$$
DELIMITER ;
DROP FUNCTION IF EXISTS getOutgoingTransactionCountByAccountId;
DELIMITER $$
CREATE FUNCTION getOutgoingTransactionCountByAccountId(in_id bigint(20))
RETURNS INT(11) DETERMINISTIC
BEGIN
DECLARE tx_count INT(11);
SET tx_count = (
SELECT count(t.id) FROM transaction t WHERE t.sender_id = in_id
);
RETURN tx_count;
END$$
DELIMITER ;
DROP FUNCTION IF EXISTS getRewardByHeight; DROP FUNCTION IF EXISTS getRewardByHeight;
DELIMITER $$ DELIMITER $$
CREATE FUNCTION getRewardByHeight(in_height bigint(20)) CREATE FUNCTION getRewardByHeight(in_height bigint(20))
RETURNS INT(5) DETERMINISTIC RETURNS INT(5) DETERMINISTIC
BEGIN BEGIN
DECLARE counter, ratio, reward BIGINT(20); DECLARE counter, ratio, reward BIGINT(20);
SET counter = (525000 - 55500); SET counter = (525000 - 55500);
...@@ -28,7 +67,7 @@ DELIMITER ; ...@@ -28,7 +67,7 @@ DELIMITER ;
DROP FUNCTION IF EXISTS getTransactionType; DROP FUNCTION IF EXISTS getTransactionType;
DELIMITER $$ DELIMITER $$
CREATE FUNCTION getTransactionType(type tinyint(4), subtype tinyint(4)) CREATE FUNCTION getTransactionType(type tinyint(4), subtype tinyint(4))
RETURNS char(100) DETERMINISTIC RETURNS char(100) DETERMINISTIC
BEGIN BEGIN
-- Transaction Types: https://github.com/burst-apps-team/burstcoin/blob/develop/src/brs/TransactionType.java#L34 -- Transaction Types: https://github.com/burst-apps-team/burstcoin/blob/develop/src/brs/TransactionType.java#L34
IF type = 0 THEN IF type = 0 THEN
......
...@@ -2,10 +2,49 @@ ...@@ -2,10 +2,49 @@
Functions Functions
*/ */
DROP FUNCTION IF EXISTS getTransactionCountByAccountId;
DELIMITER $$
CREATE FUNCTION getTransactionCountByAccountId(in_id bigint(20))
RETURNS INT(11) DETERMINISTIC
BEGIN
DECLARE tx_count INT(11);
SET tx_count = getIncomingTransactionCountByAccountId(in_id) + getOutgoingTransactionCountByAccountId(in_id);
RETURN tx_count;
END$$
DELIMITER ;
DROP FUNCTION IF EXISTS getIncomingTransactionCountByAccountId;
DELIMITER $$
CREATE FUNCTION getIncomingTransactionCountByAccountId(in_id bigint(20))
RETURNS INT(11) DETERMINISTIC
BEGIN
DECLARE tx_count INT(11);
SET tx_count = (
(SELECT count(t.id) FROM transaction t WHERE t.recipient_id = in_id) +
(SELECT count(mo.db_id) FROM mo WHERE mo.recipient_id = in_id) +
(SELECT count(mosr.db_id) FROM mosr WHERE mosr.recipient_id = in_id)
);
RETURN tx_count;
END$$
DELIMITER ;
DROP FUNCTION IF EXISTS getOutgoingTransactionCountByAccountId;
DELIMITER $$
CREATE FUNCTION getOutgoingTransactionCountByAccountId(in_id bigint(20))
RETURNS INT(11) DETERMINISTIC
BEGIN
DECLARE tx_count INT(11);
SET tx_count = (
SELECT count(t.id) FROM transaction t WHERE t.sender_id = in_id
);
RETURN tx_count;
END$$
DELIMITER ;
DROP FUNCTION IF EXISTS getRewardByHeight; DROP FUNCTION IF EXISTS getRewardByHeight;
DELIMITER $$ DELIMITER $$
CREATE FUNCTION getRewardByHeight(in_height bigint(20)) CREATE FUNCTION getRewardByHeight(in_height bigint(20))
RETURNS INT(5) DETERMINISTIC RETURNS INT(5) DETERMINISTIC
BEGIN BEGIN
RETURN FLOOR(POW(0.95,FLOOR(in_height/10800))*10000); RETURN FLOOR(POW(0.95,FLOOR(in_height/10800))*10000);
END$$ END$$
...@@ -13,7 +52,7 @@ END$$ ...@@ -13,7 +52,7 @@ END$$
DROP FUNCTION IF EXISTS getTransactionType; DROP FUNCTION IF EXISTS getTransactionType;
DELIMITER $$ DELIMITER $$
CREATE FUNCTION getTransactionType(type tinyint(4), subtype tinyint(4)) CREATE FUNCTION getTransactionType(type tinyint(4), subtype tinyint(4))
RETURNS char(100) DETERMINISTIC RETURNS char(100) DETERMINISTIC
BEGIN BEGIN
-- Transaction Types: https://github.com/burst-apps-team/burstcoin/blob/develop/src/brs/TransactionType.java#L34 -- Transaction Types: https://github.com/burst-apps-team/burstcoin/blob/develop/src/brs/TransactionType.java#L34
IF type = 0 THEN IF type = 0 THEN
......
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