Adding support for PPS payout method
This commit changed a few things in the backend and classes code: * Any <type>_PPS transaction does NOT need to be confirmed * Queries updated for added <type>_PPS transactions * Template updated to properly display these transactions Cronjob * Added pps_payput cron to run payouts based on worker submitted shares * **IMPORTANT**: Can NOT be run with proportional_payout! Addresses #70
This commit is contained in:
parent
56f3d57c35
commit
4745a2f6f8
87
cronjobs/pps_payout.php
Executable file
87
cronjobs/pps_payout.php
Executable file
@ -0,0 +1,87 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
Copyright:: 2013, Sebastian Grewe
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
// Include all settings and classes
|
||||
require_once('shared.inc.php');
|
||||
|
||||
// Fetch all transactions since our last block
|
||||
if ( $bitcoin->can_connect() === true ){
|
||||
$dDifficulty = $bitcoin->getdifficulty();
|
||||
} else {
|
||||
verbose("Aborted: " . $bitcoin->can_connect() . "\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Value per share calculation
|
||||
$pps_value = 50 / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']);
|
||||
|
||||
// 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\t\tPayout\t\tDonation\tFee\t\tStatus\n");
|
||||
|
||||
foreach ($aAccountShares as $aData) {
|
||||
// Take our valid shares and multiply by per share value
|
||||
$aData['payout'] = $aData['valid'] * $pps_value;
|
||||
|
||||
// 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");
|
||||
?>
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
");
|
||||
|
||||
@ -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 @@
|
||||
<td>{$TRANSACTIONS[transaction].type}</td>
|
||||
<td>{$TRANSACTIONS[transaction].coin_address}</td>
|
||||
<td>{if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if}</td>
|
||||
<td><font color="{if $TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus'}green{else}red{/if}">{$TRANSACTIONS[transaction].amount}</td>
|
||||
<td><font color="{if $TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Credit_PPS' or $TRANSACTIONS[transaction].type == 'Bonus'}green{else}red{/if}">{$TRANSACTIONS[transaction].amount}</td>
|
||||
</tr>
|
||||
{/if}
|
||||
{/section}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user