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) - -
| {$TRANSACTIONS[transaction].id} | {$TRANSACTIONS[transaction].timestamp} | @@ -32,11 +32,15 @@ {/section}
+ + 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.
| {$TRANSACTIONS[transaction].id} | {$TRANSACTIONS[transaction].timestamp} | @@ -59,15 +66,20 @@{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.
- 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
-
| 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 Invalid | +{$GLOBAL.roundshares.invalid} | +|
| Your Invalid | +{$GLOBAL.userdata.shares.invalid} | +|
| Round Estimate | +||
| Block | +{$block} LTC | +|
| Donation | +{$donation} LTC | +|
| Payout | +{math equation="block - donation" block=$block donation=$donation} LTC | +|
| Account Balance | ||
| {$GLOBAL.userdata.balance|default:"0"} LTC | ||