diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php new file mode 100755 index 00000000..efdbfc94 --- /dev/null +++ b/cronjobs/pps_payout.php @@ -0,0 +1,105 @@ +#!/usr/bin/php +can_connect() === true ){ + $dDifficulty = $bitcoin->getdifficulty(); +} else { + verbose("Aborted: " . $bitcoin->can_connect() . "\n"); + exit(1); +} + +// Value per share calculation +$pps_value = number_format(round(50 / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); + +// Find our last share accounted and last inserted share for PPS calculations +$iPreviousShareId = $setting->getValue('pps_last_share_id'); +$iLastShareId = $share->getLastInsertedShareId(); + +// Check for all new shares, we start one higher as our last accounted share to avoid duplicates +$aAccountShares = $share->getSharesForAccounts($iPreviousShareId + 1, $iLastShareId); + +verbose("ID\tUsername\tInvalid\tValid\t\tPPS Value\t\tPayout\t\tDonation\tFee\t\tStatus\n"); + +foreach ($aAccountShares as $aData) { + // Take our valid shares and multiply by per share value + $aData['payout'] = number_format(round($aData['valid'] * $pps_value, 8), 8); + + // Defaults + $aData['fee' ] = 0; + $aData['donation'] = 0; + + // Calculate block fees + if ($config['fees'] > 0) + $aData['fee'] = number_format(round($config['fees'] / 100 * $aData['payout'], 8), 8); + // Calculate donation amount + $aData['donation'] = number_format(round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8), 8); + + verbose($aData['id'] . "\t" . + $aData['username'] . "\t" . + $aData['invalid'] . "\t" . + $aData['valid'] . "\t*\t" . + $pps_value . "\t=\t" . + $aData['payout'] . "\t" . + $aData['donation'] . "\t" . + $aData['fee'] . "\t"); + + $strStatus = "OK"; + // Add new credit transaction + if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit_PPS')) + $strStatus = "Transaction Failed"; + // Add new fee debit for this block + if ($aData['fee'] > 0 && $config['fees'] > 0) + if (!$transaction->addTransaction($aData['id'], $aData['fee'], 'Fee_PPS')) + $strStatus = "Fee Failed"; + // Add new donation debit + if ($aData['donation'] > 0) + if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation_PPS')) + $strStatus = "Donation Failed"; + verbose($strStatus . "\n"); +} + +// Store our last inserted ID for the next run +$setting->setValue('pps_last_share_id', $iLastShareId); + +verbose("\n\n------------------------------------------------------------------------------------\n\n"); + +// Fetch all unaccounted blocks +$aAllBlocks = $block->getAllUnaccounted('ASC'); +if (empty($aAllBlocks)) { + verbose("No new unaccounted blocks found\n"); +} + +// Go through blocks and archive/delete shares that have been accounted for +foreach ($aAllBlocks as $iIndex => $aBlock) { + $dummy = $iIndex - 1; + if ($config['archive_shares'] && $aBlock['share_id'] < $iLastShareId) { + $share->moveArchive($aBlock['share_id'], $aBlock['id'], @$aAllBlocks[$dummy]['share_id']); + } + if ($aBlock['share_id'] < $iLastShareId && !$share->deleteAccountedShares($aBlock['share_id'], @$aAllBlocks[$dummy]['share_id'])) { + verbose("\nERROR : Failed to delete accounted shares from " . $aBlock['share_id'] . " to " . @$aAllBlocks[$dummy]['share_id'] . ", aborting!\n"); + exit(1); + } +} +?> diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index b0a3b249..1033f92c 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -44,6 +44,21 @@ class Share { return $this->table; } + /** + * Get last inserted Share ID from Database + * Used for PPS calculations without moving to archive + **/ + public function getLastInsertedShareId() { + $stmt = $this->mysqli->prepare(" + SELECT MAX(id) AS id FROM $this->table + "); + if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result()) + return $result->fetch_object()->id; + // Catchall + $this->setErrorMessage('Failed to fetch last inserted share ID'); + return false; + } + /** * Get all valid shares for this round * @param previous_upstream int Previous found share accepted by upstream to limit results diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index d12d14ee..79d5ba66 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -131,8 +131,10 @@ class Transaction { SELECT sum(t.amount) AS credit FROM $this->table AS t LEFT JOIN " . $this->block->getTableName() . " AS b ON t.block_id = b.id - WHERE t.type IN ('Credit','Bonus') - AND b.confirmations >= " . $this->config['confirmations'] . " + WHERE ( + ( t.type IN ('Credit','Bonus') AND b.confirmations >= ? ) OR + ( t.type = 'Credit_PPS' ) + ) ) AS t1, ( SELECT sum(t.amount) AS debit @@ -143,10 +145,12 @@ class Transaction { 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','Fee') - AND b.confirmations >= " . $this->config['confirmations'] . " + WHERE ( + ( t.type IN ('Donation','Fee') AND b.confirmations >= ? ) OR + t.type IN ('Donation_PPS','Fee_PPS') + ) ) AS t3"); - if ($this->checkStmt($stmt) && $stmt->execute() && $stmt->bind_result($dBalance) && $stmt->fetch()) + if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $this->config['confirmations'], $this->config['confirmations']) && $stmt->execute() && $stmt->bind_result($dBalance) && $stmt->fetch()) return $dBalance; // Catchall $this->setErrorMessage('Unable to find locked credits for all users'); @@ -168,8 +172,11 @@ class Transaction { SELECT sum(t.amount) AS credit FROM $this->table AS t LEFT JOIN " . $this->block->getTableName() . " AS b ON t.block_id = b.id - WHERE t.type IN ('Credit','Bonus') - AND b.confirmations >= ? + WHERE + ( + ( t.type IN ('Credit','Bonus') AND b.confirmations >= ? ) OR + ( t.type = 'Credit_PPS' ) + ) AND t.account_id = ? ) AS t1, ( @@ -182,8 +189,11 @@ class Transaction { 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','Fee') - AND b.confirmations >= ? + WHERE + ( + ( t.type IN ('Donation','Fee') AND b.confirmations >= ? ) OR + ( t.type IN ('Donation_PPS', 'Fee_PPS') ) + ) AND t.account_id = ? ) AS t3 "); diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index f1cb0cbe..3d329645 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -35,6 +35,7 @@ $config = array( 'email' => 'test@example.com', // Mail address used for notifications ), 'block_bonus' => 0, + 'payout_system' => 'pps', // Set your payout here so template changes are activated 'archive_shares' => true, // Store accounted shares in archive table? 'blockexplorer' => 'http://explorer.litecoin.net/search?q=', // URL for block searches, prefixed to each block number 'chaininfo' => 'http://allchains.info', // Link to Allchains for Difficulty information diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index fa5c7923..209f6a71 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -12,12 +12,18 @@ $aRoundShares = $statistics->getRoundShares(); $iCurrentActiveWorkers = $worker->getCountAllActiveWorkers(); $iCurrentPoolHashrate = $statistics->getCurrentHashrate(); $iCurrentPoolShareRate = $statistics->getCurrentShareRate(); +if ($bitcoin->can_connect() === true){ + $dDifficulty = $bitcoin->query('getdifficulty'); +} else { + $dDifficulty = 1; +} $aGlobal = array( 'slogan' => $config['website']['slogan'], 'websitename' => $config['website']['name'], 'hashrate' => $iCurrentPoolHashrate, 'sharerate' => $iCurrentPoolShareRate, + 'ppsvalue' => number_format(round(50 / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12), 'workers' => $iCurrentActiveWorkers, 'roundshares' => $aRoundShares, 'fees' => $config['fees'], @@ -27,6 +33,7 @@ $aGlobal = array( 'blockexplorer' => $config['blockexplorer'], 'chaininfo' => $config['chaininfo'], 'config' => array( + 'payout_system' => $config['payout_system'], 'ap_threshold' => array( 'min' => $config['ap_threshold']['min'], 'max' => $config['ap_threshold']['max'] diff --git a/public/templates/mmcFE/account/transactions/default.tpl b/public/templates/mmcFE/account/transactions/default.tpl index 2e6ae074..d2393450 100644 --- a/public/templates/mmcFE/account/transactions/default.tpl +++ b/public/templates/mmcFE/account/transactions/default.tpl @@ -19,6 +19,9 @@ (($TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus')and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) or ($TRANSACTIONS[transaction].type == 'Donation' and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) or ($TRANSACTIONS[transaction].type == 'Fee' and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) + or $TRANSACTIONS[transaction].type == 'Credit_PPS' + or $TRANSACTIONS[transaction].type == 'Fee_PPS' + or $TRANSACTIONS[transaction].type == 'Donation_PPS' or $TRANSACTIONS[transaction].type == 'Debit_AP' or $TRANSACTIONS[transaction].type == 'Debit_MP' )} @@ -28,7 +31,7 @@
| Your Hashrate | |
| {$GLOBAL.userdata.hashrate|number_format} KH/s | |
| Your Stats | +|
| Hashrate | +{$GLOBAL.userdata.hashrate|number_format} KH/s | +
| PPS Value | +{$GLOBAL.ppsvalue} | +
Unpaid Shares ![]() |
Pool Valid | {$GLOBAL.roundshares.valid|number_format} | +{/if}
Round Shares ![]() |
Your Invalid | {$GLOBAL.userdata.shares.invalid|number_format} | +{if $GLOBAL.config.payout_system != 'pps'}
| LTC Round Estimate | Payout | {$GLOBAL.userdata.est_payout|number_format:"3"} | +{/if}
| Account Balance | |
| {$GLOBAL.userdata.balance|default:"0"} LTC | |