diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index 72ca7240..8f7a08d7 100755 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -45,7 +45,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { } $aAccountShares = $share->getSharesForAccounts($share->getLastUpstreamId(), $iCurrentUpstreamId); $iRoundShares = $share->getRoundShares($share->getLastUpstreamId(), $iCurrentUpstreamId); - verbose("ID\tHeight\tTime\t\tShares\tFinder\t\tShare ID\tPrev Share\tStatus\n"); + verbose("ID\tHeight\tTime\t\tShares\tFinder\t\tShare ID\tPrev Share\t\tStatus\n"); verbose($aBlock['id'] . "\t" . $aBlock['height'] . "\t" . $aBlock['time'] . "\t" . $iRoundShares . "\t" . $share->getUpstreamFinder() . "\t" . $share->getUpstreamId() . "\t\t" . $share->getLastUpstreamId()); if (empty($aAccountShares)) { verbose("\nNo shares found for this block\n\n"); @@ -58,24 +58,37 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { if (!$block->setShares($aBlock['id'], $iRoundShares)) $strStatus = "Shares Failed"; verbose("\t\t$strStatus\n\n"); - verbose("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tStatus\n"); + verbose("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tDonation\t\tStatus\n"); foreach ($aAccountShares as $key => $aData) { + // Payout based on shares, PPS system $aData['percentage'] = number_format(round(( 100 / $iRoundShares ) * $aData['valid'], 8), 8); $aData['payout'] = number_format(round(( $aData['percentage'] / 100 ) * $config['reward'], 8), 8); + + // Calculate donation amount for Donation transaction + $aData['donation'] = $user->getDonatePercent($user->getUserId($aData['username'])) / 100 * $aData['payout']; + + // Verbose output of this users calculations verbose($aData['id'] . "\t" . $aData['username'] . "\t" . $aData['valid'] . "\t" . $aData['invalid'] . "\t" . $aData['percentage'] . "\t" . - $aData['payout'] . "\t"); + $aData['payout'] . "\t" . + $aData['donation'] . "\t"); - // Do all database updates for block, statistics and payouts $strStatus = "OK"; + // Update user share statistics if (!$statistics->updateShareStatistics($aData, $aBlock['id'])) $strStatus = "Stats Failed"; + // Add new credit transaction if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit', $aBlock['id'])) $strStatus = "Transaction Failed"; - verbose("$strStatus\n"); + // Add new donation debit + if ($aData['donation'] > 0) { + if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id'])) + $strStatus = "Donation Failed"; + } + verbose("\t\t$strStatus\n"); } verbose("------------------------------------------------------------------------\n\n"); diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index 4f443acb..465e9a0f 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -9,10 +9,11 @@ class Transaction { private $table = 'transactions'; private $tableBlocks = 'blocks'; - public function __construct($debug, $mysqli, $config) { + public function __construct($debug, $mysqli, $config, $block) { $this->debug = $debug; $this->mysqli = $mysqli; $this->config = $config; + $this->block = $block; $this->debug->append("Instantiated Transaction class", 2); } @@ -75,23 +76,33 @@ class Transaction { public function getBalance($account_id) { $stmt = $this->mysqli->prepare(" - SELECT IFNULL(c.credit, 0) - IFNULL(d.debit,0) AS balance - FROM ( - SELECT t.account_id, sum(t.amount) AS credit + SELECT IFNULL(t1.credit, 0) - IFNULL(t2.debit, 0) - IFNULL(t3.other, 0) AS balance + FROM + ( + SELECT sum(t.amount) AS credit FROM $this->table AS t - LEFT JOIN $this->tableBlocks AS b ON t.block_id = b.id - WHERE type = 'Credit' - AND b.confirmations > ? - AND t.account_id = ? ) AS c - LEFT JOIN ( - SELECT t.account_id, sum(amount) AS debit + LEFT JOIN " . $this->block->getTableName() . " AS b ON t.block_id = b.id + WHERE t.type = 'Credit' + AND b.confirmations >= ? + AND t.account_id = ? + ) AS t1, + ( + SELECT sum(t.amount) AS debit FROM $this->table AS t - WHERE type IN ('Debit_MP','Debit_AP') - AND t.account_id = ? ) AS d - ON c.account_id = d.account_id + WHERE t.type IN ('Debit_MP', 'Debit_AP') + AND t.account_id = ? + ) AS t2, + ( + SELECT sum(t.amount) AS other + FROM $this->table AS t + LEFT JOIN " . $this->block->getTableName() . " AS b ON t.block_id = b.id + WHERE t.type IN ('Donation') + AND b.confirmations >= ? + AND t.account_id = ? + ) AS t3 "); if ($this->checkStmt($stmt)) { - $stmt->bind_param("iii", $this->config['confirmations'], $account_id, $account_id); + $stmt->bind_param("iiiii", $this->config['confirmations'], $account_id, $account_id, $this->config['confirmations'], $account_id); if (!$stmt->execute()) { $this->debug->append("Unable to execute statement: " . $stmt->error); $this->setErrorMessage("Fetching balance failed"); @@ -104,4 +115,4 @@ class Transaction { } } -$transaction = new Transaction($debug, $mysqli, $config); +$transaction = new Transaction($debug, $mysqli, $config, $block); diff --git a/public/include/classes/user.class.php b/public/include/classes/user.class.php index cb7ff1c7..a2b7c07e 100644 --- a/public/include/classes/user.class.php +++ b/public/include/classes/user.class.php @@ -115,7 +115,19 @@ class User { * @return data string Coin Address **/ public function getCoinAddress($userID) { - return $this->getSingle($userID, 'coin_address', 'id', 's'); + return $this->getSingle($userID, 'coin_address', 'id'); + } + + /** + * Fetch users donation value + * @param userID int UserID + * @return data string Coin Address + **/ + public function getDonatePercent($userID) { + $dPercent = $this->getSingle($userID, 'donate_percent', 'id'); + if ($dPercent > 100) $dPercent = 100; + if ($dPercent < 0) $dPercent = 0; + return $dPercent; } /** diff --git a/public/templates/mmcFE/account/transactions/default.tpl b/public/templates/mmcFE/account/transactions/default.tpl index 9ec3aad6..3615a3dc 100644 --- a/public/templates/mmcFE/account/transactions/default.tpl +++ b/public/templates/mmcFE/account/transactions/default.tpl @@ -1,11 +1,6 @@ {include file="global/block_header.tpl" BLOCK_HEADER="Transaction Log" BUTTONS=array(Confirmed,Unconfirmed)}
-

- - ATP = Auto Threshold Payment, MP = Manual Payment, Don_Fee = donation amount + pool fees (if applicable) - -

@@ -19,7 +14,12 @@ {section transaction $TRANSACTIONS} - {if (($TRANSACTIONS[transaction].type == 'Credit' and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) or $TRANSACTIONS[transaction].type != 'Credit')} + {if ( + ($TRANSACTIONS[transaction].type == 'Credit' and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) + or ($TRANSACTIONS[transaction].type == 'Donation' and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) + or $TRANSACTIONS[transaction].type == 'Debit_AP' + or $TRANSACTIONS[transaction].type == 'Debit_MP' + )} @@ -32,11 +32,15 @@ {/section}
{$TRANSACTIONS[transaction].id} {$TRANSACTIONS[transaction].timestamp}
+

+ + Credit_AP = Auto Threshold Payment, Credit_MP = Manual Payment, Donation = Donation, Fee = Pool Fees (if applicable) + +

-

Listed below are your estimated rewards and donations/fees for all blocks awaiting 120 confirmations.

@@ -50,7 +54,10 @@ {section transaction $TRANSACTIONS} - {if $TRANSACTIONS[transaction].type == 'Credit' && $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations} + {if ( + $TRANSACTIONS[transaction].type == 'Credit' && $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations + or ($TRANSACTIONS[transaction].type == 'Donation' and $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations) + )} @@ -59,15 +66,20 @@ - {assign var="sum" value="`$sum+$TRANSACTIONS[transaction].amount`"} + {if $TRANSACTIONS[transaction].type == Credit} + {assign var="credits" value="`$credits+$TRANSACTIONS[transaction].amount`"} + {else} + {assign var="debits" value="`$debits+$TRANSACTIONS[transaction].amount`"} + {/if} {/if} {/section} - +
{$TRANSACTIONS[transaction].id} {$TRANSACTIONS[transaction].timestamp}{if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if} {$TRANSACTIONS[transaction].amount}
Unconfirmed Totals:{$sum}{$credits - $debits}
+

Listed are your estimated rewards and donations/fees for all blocks awaiting {$GLOBAL.confirmations} confirmations.

{include file="global/block_footer.tpl"} diff --git a/public/templates/mmcFE/global/sidebar.tpl b/public/templates/mmcFE/global/sidebar.tpl index 52e21a94..4c4f4061 100644 --- a/public/templates/mmcFE/global/sidebar.tpl +++ b/public/templates/mmcFE/global/sidebar.tpl @@ -1,25 +1,61 @@ -
-
-
-
-

Dashboard

-
-
-

- Your Current Hashrate
- {$GLOBAL.userdata.hashrate} KH/s

- Unpaid Shares
- Your Valid: {$GLOBAL.userdata.shares.valid}
- Pool Valid: {$GLOBAL.roundshares.valid}

- Round Shares
- Pool Valid: {$GLOBAL.roundshares.valid}
- Pool Inalid: {$GLOBAL.roundshares.invalid}
- Your Invalid: {$GLOBAL.userdata.shares.invalid}

- Round Estimate
- {math equation="round(( x / y ) * z, 8)" x=$GLOBAL.userdata.shares.valid y=$GLOBAL.roundshares.valid z=$GLOBAL.reward} LTC

- Account Balance
{$GLOBAL.userdata.balance|default:"0"} LTC

-

-
-
-
+
+
+
+
+

Dashboard

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + {math assign="block" equation="round(( x / y ) * z, 3)" x=$GLOBAL.userdata.shares.valid y=$GLOBAL.roundshares.valid z=$GLOBAL.reward} + {math assign="donation" equation="round(((d / 100) * est), 3)" d=$GLOBAL.userdata.donate_percent est=$block} + + + + + + + + + + + + + + + + + + +
+
+
+
diff --git a/sql/mmcfe_ng_structure.sql b/sql/mmcfe_ng_structure.sql index 69b0ea6a..780d00e1 100644 --- a/sql/mmcfe_ng_structure.sql +++ b/sql/mmcfe_ng_structure.sql @@ -1,11 +1,11 @@ -- phpMyAdmin SQL Dump --- version 3.5.1 +-- version 3.5.8.1deb1 -- http://www.phpmyadmin.net -- -- Host: localhost --- Generation Time: May 16, 2013 at 09:25 PM --- Server version: 5.5.31-log --- PHP Version: 5.4.15 +-- Generation Time: May 20, 2013 at 07:35 PM +-- Server version: 5.5.31-0ubuntu0.13.04.1 +-- PHP Version: 5.4.9-4ubuntu2 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; @@ -17,7 +17,7 @@ SET time_zone = "+00:00"; /*!40101 SET NAMES utf8 */; -- --- Database: `mmcfe_ng_db` +-- Database: `mmcfe_ng` -- -- -------------------------------------------------------- @@ -63,7 +63,7 @@ CREATE TABLE IF NOT EXISTS `blocks` ( PRIMARY KEY (`id`), UNIQUE KEY `height` (`height`,`blockhash`), KEY `time` (`time`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Discovered blocks persisted from Litecoin Service'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Discovered blocks persisted from Litecoin Service'; -- -------------------------------------------------------- @@ -115,7 +115,7 @@ CREATE TABLE IF NOT EXISTS `shares_archive` ( `time` datetime DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `share_id` (`share_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Archive shares for potential later debugging purposes'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Archive shares for potential later debugging purposes'; -- -------------------------------------------------------- @@ -132,7 +132,7 @@ CREATE TABLE IF NOT EXISTS `statistics_shares` ( PRIMARY KEY (`id`), KEY `account_id` (`account_id`), KEY `block_id` (`block_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -143,7 +143,7 @@ CREATE TABLE IF NOT EXISTS `statistics_shares` ( CREATE TABLE IF NOT EXISTS `transactions` ( `id` int(255) NOT NULL AUTO_INCREMENT, `account_id` int(255) unsigned NOT NULL, - `type` enum('Credit','Debit_MP','Debit_AP') DEFAULT NULL, + `type` enum('Credit','Debit_MP','Debit_AP','Fee','Donation') DEFAULT NULL, `coin_address` varchar(255) DEFAULT NULL, `amount` double DEFAULT '0', `fee_amount` float DEFAULT '0', @@ -153,7 +153,7 @@ CREATE TABLE IF NOT EXISTS `transactions` ( KEY `block_id` (`block_id`), KEY `account_id` (`account_id`), KEY `type` (`type`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- --------------------------------------------------------