From 6429b2b442532c6403926c715dd3d683a1654589 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 21 May 2013 13:57:49 +0200 Subject: [PATCH 1/2] adding support for pool fees --- cronjobs/pps_payout.php | 22 +++++++++++++------ public/include/classes/transaction.class.php | 8 +++---- public/include/smarty_globals.inc.php | 7 ++++++ .../mmcFE/account/transactions/default.tpl | 2 ++ public/templates/mmcFE/global/sidebar.tpl | 12 +++++----- 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index 329104c5..848b9d5c 100755 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -58,14 +58,19 @@ 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\tDonation\t\tStatus\n"); + verbose("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tDonation\tFee\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); + // Defaults + $aData['fee' ] = 0; + $aData['donation'] = 0; - // Calculate donation amount for Donation transaction - $aData['donation'] = number_format(round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * $aData['payout'], 8), 8); + if ($config['fees'] > 0) + $aData['fee'] = number_format(round($config['fees'] / 100 * $aData['payout'], 8), 8); + // Calculate donation amount, fees not included + $aData['donation'] = number_format(round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8), 8); // Verbose output of this users calculations verbose($aData['id'] . "\t" . @@ -74,7 +79,8 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $aData['invalid'] . "\t" . $aData['percentage'] . "\t" . $aData['payout'] . "\t" . - $aData['donation'] . "\t"); + $aData['donation'] . "\t" . + $aData['fee'] . "\t"); $strStatus = "OK"; // Update user share statistics @@ -84,11 +90,13 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit', $aBlock['id'])) $strStatus = "Transaction Failed"; // Add new donation debit - if ($aData['donation'] > 0) { + if ($aData['donation'] > 0) if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id'])) $strStatus = "Donation Failed"; - } - verbose("\t\t$strStatus\n"); + if ($aData['fee'] > 0 && $config['fees'] > 0) + if (!$transaction->addTransaction($aData['id'], $aData['fee'], 'Fee', $aBlock['id'])) + $strStatus = "Fee Failed"; + verbose("\t$strStatus\n"); } verbose("------------------------------------------------------------------------\n\n"); diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index 5fff814b..7f8cd76d 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -25,10 +25,10 @@ class Transaction { return $this->sError; } - public function addTransaction($account_id, $amount, $type='Credit', $block_id=NULL, $coin_address=NULL, $fee=0) { - $stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, amount, block_id, type, coin_address, fee_amount) VALUES (?, ?, ?, ?, ?, ?)"); + public function addTransaction($account_id, $amount, $type='Credit', $block_id=NULL, $coin_address=NULL) { + $stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, amount, block_id, type, coin_address) VALUES (?, ?, ?, ?, ?)"); if ($this->checkStmt($stmt)) { - $stmt->bind_param("idissd", $account_id, $amount, $block_id, $type, $coin_address, $fee); + $stmt->bind_param("idiss", $account_id, $amount, $block_id, $type, $coin_address); if ($stmt->execute()) { $this->setErrorMessage("Failed to store transaction"); $stmt->close(); @@ -96,7 +96,7 @@ 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') + WHERE t.type IN ('Donation','Fee') AND b.confirmations >= ? AND t.account_id = ? ) AS t3 diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index a6cbcb3e..4d55829e 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -20,6 +20,7 @@ $aGlobal = array( 'sharerate' => $iCurrentPoolShareRate, 'workers' => $iCurrentActiveWorkers, 'roundshares' => $aRoundShares, + 'fees' => $config['fees'], 'confirmations' => $config['confirmations'], 'reward' => $config['reward'] ); @@ -32,6 +33,12 @@ $aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA'] $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['id']); $aGlobal['userdata']['hashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['id']); +// Some estimations +$aGlobal['userdata']['est_block'] = round(( (int)$aGlobal['userdata']['shares']['valid'] / (int)$aRoundShares['valid'] ) * (int)$config['reward'], 3); +$aGlobal['userdata']['est_donation'] = round((( $aGlobal['userdata']['donate_percent'] / 100) * $aGlobal['userdata']['est_block']), 3); +$aGlobal['userdata']['est_fee'] = round((($config['fees'] / 100) * ($aGlobal['userdata']['est_block'] - $aGlobal['userdata']['est_donation'])), 3); +$aGlobal['userdata']['est_payout'] = round($aGlobal['userdata']['est_block'] - $aGlobal['userdata']['est_donation'] - $aGlobal['userdata']['est_fee'], 3); + // Make it available in Smarty $smarty->assign('PATH', 'site_assets/' . THEME); $smarty->assign('GLOBAL', $aGlobal); diff --git a/public/templates/mmcFE/account/transactions/default.tpl b/public/templates/mmcFE/account/transactions/default.tpl index 4e490ad2..35ec2cc4 100644 --- a/public/templates/mmcFE/account/transactions/default.tpl +++ b/public/templates/mmcFE/account/transactions/default.tpl @@ -17,6 +17,7 @@ {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 == 'Fee' and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) or $TRANSACTIONS[transaction].type == 'Debit_AP' or $TRANSACTIONS[transaction].type == 'Debit_MP' )} @@ -57,6 +58,7 @@ {if ( $TRANSACTIONS[transaction].type == 'Credit' && $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) )} {$TRANSACTIONS[transaction].id} diff --git a/public/templates/mmcFE/global/sidebar.tpl b/public/templates/mmcFE/global/sidebar.tpl index 4c4f4061..3845d42d 100644 --- a/public/templates/mmcFE/global/sidebar.tpl +++ b/public/templates/mmcFE/global/sidebar.tpl @@ -34,22 +34,24 @@ Your Invalid {$GLOBAL.userdata.shares.invalid} - {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} Round Estimate Block - {$block} LTC + {$GLOBAL.userdata.est_block} LTC Donation - {$donation} LTC + {$GLOBAL.userdata.est_donation} LTC + + + Fees + {$GLOBAL.userdata.est_fee} LTC Payout - {math equation="block - donation" block=$block donation=$donation} LTC + {$GLOBAL.userdata.est_payout} LTC   Account Balance From edef3a5b111ad819270f9c359071b161258b09a2 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 21 May 2013 14:00:54 +0200 Subject: [PATCH 2/2] adding new SQL structure, removed a column from transactions --- sql/mmcfe_ng_structure.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/sql/mmcfe_ng_structure.sql b/sql/mmcfe_ng_structure.sql index 780d00e1..52639bbc 100644 --- a/sql/mmcfe_ng_structure.sql +++ b/sql/mmcfe_ng_structure.sql @@ -146,7 +146,6 @@ CREATE TABLE IF NOT EXISTS `transactions` ( `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', `block_id` int(255) DEFAULT NULL, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`),