Merge pull request #36 from TheSerapher/pool-fees

Pool fees
This commit is contained in:
Sebastian Grewe 2013-05-21 05:02:01 -07:00
commit de1303b144
6 changed files with 35 additions and 17 deletions

View File

@ -58,14 +58,19 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
if (!$block->setShares($aBlock['id'], $iRoundShares)) if (!$block->setShares($aBlock['id'], $iRoundShares))
$strStatus = "Shares Failed"; $strStatus = "Shares Failed";
verbose("\t\t$strStatus\n\n"); 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) { foreach ($aAccountShares as $key => $aData) {
// Payout based on shares, PPS system // Payout based on shares, PPS system
$aData['percentage'] = number_format(round(( 100 / $iRoundShares ) * $aData['valid'], 8), 8); $aData['percentage'] = number_format(round(( 100 / $iRoundShares ) * $aData['valid'], 8), 8);
$aData['payout'] = number_format(round(( $aData['percentage'] / 100 ) * $config['reward'], 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 if ($config['fees'] > 0)
$aData['donation'] = number_format(round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * $aData['payout'], 8), 8); $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 output of this users calculations
verbose($aData['id'] . "\t" . verbose($aData['id'] . "\t" .
@ -74,7 +79,8 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
$aData['invalid'] . "\t" . $aData['invalid'] . "\t" .
$aData['percentage'] . "\t" . $aData['percentage'] . "\t" .
$aData['payout'] . "\t" . $aData['payout'] . "\t" .
$aData['donation'] . "\t"); $aData['donation'] . "\t" .
$aData['fee'] . "\t");
$strStatus = "OK"; $strStatus = "OK";
// Update user share statistics // Update user share statistics
@ -84,11 +90,13 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit', $aBlock['id'])) if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit', $aBlock['id']))
$strStatus = "Transaction Failed"; $strStatus = "Transaction Failed";
// Add new donation debit // Add new donation debit
if ($aData['donation'] > 0) { if ($aData['donation'] > 0)
if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id'])) if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id']))
$strStatus = "Donation Failed"; $strStatus = "Donation Failed";
} if ($aData['fee'] > 0 && $config['fees'] > 0)
verbose("\t\t$strStatus\n"); if (!$transaction->addTransaction($aData['id'], $aData['fee'], 'Fee', $aBlock['id']))
$strStatus = "Fee Failed";
verbose("\t$strStatus\n");
} }
verbose("------------------------------------------------------------------------\n\n"); verbose("------------------------------------------------------------------------\n\n");

View File

@ -25,10 +25,10 @@ class Transaction {
return $this->sError; return $this->sError;
} }
public function addTransaction($account_id, $amount, $type='Credit', $block_id=NULL, $coin_address=NULL, $fee=0) { 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, fee_amount) VALUES (?, ?, ?, ?, ?, ?)"); $stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, amount, block_id, type, coin_address) VALUES (?, ?, ?, ?, ?)");
if ($this->checkStmt($stmt)) { 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()) { if ($stmt->execute()) {
$this->setErrorMessage("Failed to store transaction"); $this->setErrorMessage("Failed to store transaction");
$stmt->close(); $stmt->close();
@ -96,7 +96,7 @@ class Transaction {
SELECT sum(t.amount) AS other SELECT sum(t.amount) AS other
FROM $this->table AS t FROM $this->table AS t
LEFT JOIN " . $this->block->getTableName() . " AS b ON t.block_id = b.id 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 b.confirmations >= ?
AND t.account_id = ? AND t.account_id = ?
) AS t3 ) AS t3

View File

@ -20,6 +20,7 @@ $aGlobal = array(
'sharerate' => $iCurrentPoolShareRate, 'sharerate' => $iCurrentPoolShareRate,
'workers' => $iCurrentActiveWorkers, 'workers' => $iCurrentActiveWorkers,
'roundshares' => $aRoundShares, 'roundshares' => $aRoundShares,
'fees' => $config['fees'],
'confirmations' => $config['confirmations'], 'confirmations' => $config['confirmations'],
'reward' => $config['reward'] 'reward' => $config['reward']
); );
@ -32,6 +33,12 @@ $aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA']
$aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['id']); $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['id']);
$aGlobal['userdata']['hashrate'] = $statistics->getUserHashrate($_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 // Make it available in Smarty
$smarty->assign('PATH', 'site_assets/' . THEME); $smarty->assign('PATH', 'site_assets/' . THEME);
$smarty->assign('GLOBAL', $aGlobal); $smarty->assign('GLOBAL', $aGlobal);

View File

@ -17,6 +17,7 @@
{if ( {if (
($TRANSACTIONS[transaction].type == 'Credit' and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) ($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 == '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_AP'
or $TRANSACTIONS[transaction].type == 'Debit_MP' or $TRANSACTIONS[transaction].type == 'Debit_MP'
)} )}
@ -57,6 +58,7 @@
{if ( {if (
$TRANSACTIONS[transaction].type == 'Credit' && $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations $TRANSACTIONS[transaction].type == 'Credit' && $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations
or ($TRANSACTIONS[transaction].type == 'Donation' 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)
)} )}
<tr class="{cycle values="odd,even"}"> <tr class="{cycle values="odd,even"}">
<td>{$TRANSACTIONS[transaction].id}</td> <td>{$TRANSACTIONS[transaction].id}</td>

View File

@ -34,22 +34,24 @@
<td><b>Your Invalid</b></td> <td><b>Your Invalid</b></td>
<td><i>{$GLOBAL.userdata.shares.invalid}</i><font size='1px'></font></td> <td><i>{$GLOBAL.userdata.shares.invalid}</i><font size='1px'></font></td>
</tr> </tr>
{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}
<tr> <tr>
<td colspan="2"><b><u>Round Estimate</u></b></td> <td colspan="2"><b><u>Round Estimate</u></b></td>
</tr> </tr>
<tr> <tr>
<td><b>Block</b></td> <td><b>Block</b></td>
<td>{$block} LTC</td> <td>{$GLOBAL.userdata.est_block} LTC</td>
</tr> </tr>
<tr> <tr>
<td><b>Donation</b></td> <td><b>Donation</b></td>
<td>{$donation} LTC</td> <td>{$GLOBAL.userdata.est_donation} LTC</td>
</tr>
<tr>
<td><b>Fees</b></td>
<td>{$GLOBAL.userdata.est_fee} LTC</td>
</tr> </tr>
<tr> <tr>
<td><b>Payout</b></td> <td><b>Payout</b></td>
<td>{math equation="block - donation" block=$block donation=$donation} LTC</td> <td>{$GLOBAL.userdata.est_payout} LTC</td>
</tr> </tr>
<tr><td colspan="2">&nbsp;</td></tr> <tr><td colspan="2">&nbsp;</td></tr>
<tr><td colspan="2"><b><u>Account Balance</u></b></td></tr> <tr><td colspan="2"><b><u>Account Balance</u></b></td></tr>

View File

@ -146,7 +146,6 @@ CREATE TABLE IF NOT EXISTS `transactions` (
`type` enum('Credit','Debit_MP','Debit_AP','Fee','Donation') DEFAULT NULL, `type` enum('Credit','Debit_MP','Debit_AP','Fee','Donation') DEFAULT NULL,
`coin_address` varchar(255) DEFAULT NULL, `coin_address` varchar(255) DEFAULT NULL,
`amount` double DEFAULT '0', `amount` double DEFAULT '0',
`fee_amount` float DEFAULT '0',
`block_id` int(255) DEFAULT NULL, `block_id` int(255) DEFAULT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),