Adding confirmed and unconfirmed balance
* Added SQL code to support both balances * Added sidebar entries * Modified auto_payout to use new index * Mofified account page to use new index Addresses #140 but needs to be tested!
This commit is contained in:
parent
888461221f
commit
a006ea782a
@ -38,7 +38,8 @@ if (! empty($users)) {
|
||||
verbose("UserID\tUsername\tBalance\tThreshold\tAddress\t\t\t\t\tStatus\n\n");
|
||||
|
||||
foreach ($users as $aUserData) {
|
||||
$dBalance = $transaction->getBalance($aUserData['id']);
|
||||
$aBalance = $transaction->getBalance($aUserData['id']);
|
||||
$dBalance = $aBalance['confirmed'];
|
||||
verbose($aUserData['id'] . "\t" . $aUserData['username'] . "\t" . $dBalance . "\t" . $aUserData['ap_threshold'] . "\t\t" . $aUserData['coin_address'] . "\t");
|
||||
|
||||
// Only run if balance meets threshold and can pay the potential transaction fee
|
||||
|
||||
@ -166,7 +166,9 @@ class Transaction {
|
||||
public function getBalance($account_id) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT ROUND(IFNULL(t1.credit, 0) - IFNULL(t2.debit, 0) - IFNULL(t3.other, 0), 8) AS balance
|
||||
SELECT
|
||||
ROUND(IFNULL(t1.credit, 0) - IFNULL(t2.debit, 0) - IFNULL(t3.other, 0), 8) AS confirmed,
|
||||
ROUND(IFNULL(t4.credit, 0) - IFNULL(t5.other, 0), 8) AS unconfirmed
|
||||
FROM
|
||||
(
|
||||
SELECT sum(t.amount) AS credit
|
||||
@ -195,17 +197,39 @@ class Transaction {
|
||||
( t.type IN ('Donation_PPS', 'Fee_PPS') )
|
||||
)
|
||||
AND t.account_id = ?
|
||||
) AS t3
|
||||
) AS t3,
|
||||
(
|
||||
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 = 'Credit' AND b.confirmations < ? ) OR
|
||||
( t.type = 'Credit_PPS' )
|
||||
)
|
||||
AND t.account_id = ?
|
||||
) AS t4,
|
||||
(
|
||||
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 < ? ) OR
|
||||
( t.type IN ('Donation_PPS', 'Fee_PPS') )
|
||||
)
|
||||
AND t.account_id = ?
|
||||
) AS t5
|
||||
");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param("iiiii", $this->config['confirmations'], $account_id, $account_id, $this->config['confirmations'], $account_id);
|
||||
$stmt->bind_param("iiiiiiiii", $this->config['confirmations'], $account_id, $account_id, $this->config['confirmations'], $account_id, $this->config['confirmations'], $account_id, $this->config['confirmations'], $account_id);
|
||||
if (!$stmt->execute()) {
|
||||
$this->debug->append("Unable to execute statement: " . $stmt->error);
|
||||
$this->setErrorMessage("Fetching balance failed");
|
||||
}
|
||||
$result = $stmt->get_result();
|
||||
$stmt->close();
|
||||
return $result->fetch_object()->balance;
|
||||
return $result->fetch_assoc();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -18,7 +18,8 @@ if ( ! $user->checkPin($_SESSION['USERDATA']['id'], $_POST['authPin']) && $_POST
|
||||
} else {
|
||||
$setting->setValue('manual_payout_active', 1);
|
||||
$continue = true;
|
||||
$dBalance = $transaction->getBalance($_SESSION['USERDATA']['id']);
|
||||
$aBalance = $transaction->getBalance($_SESSION['USERDATA']['id']);
|
||||
$dBalance = $aBalance['confirmed'];
|
||||
$sCoinAddress = $user->getCoinAddress($_SESSION['USERDATA']['id']);
|
||||
// Ensure we can cover the potential transaction fee of 0.1 LTC with the balance
|
||||
if ($dBalance > 0.1) {
|
||||
|
||||
@ -20,7 +20,8 @@ if ($_POST['query']) {
|
||||
// This is not optimized yet, best is a proper SQL
|
||||
// Query against the stats table? Currently cached though.
|
||||
foreach ($aUsers as $iKey => $aUser) {
|
||||
$aUser['balance'] = $transaction->getBalance($aUser['id']);
|
||||
$aBalance = $transaction->getBalance($aUser['id']);
|
||||
$aUser['balance'] = $aBalance['confirmed'];
|
||||
$aUser['hashrate'] = $statistics->getUserHashrate($aUser['id']);
|
||||
$aUser['payout']['est_block'] = round(( (int)$aUser['shares'] / (int)$aRoundShares['valid'] ) * (int)$config['reward'], 3);
|
||||
$aUser['payout']['est_fee'] = round(($config['fees'] / 100) * $aUser['payout']['est_block'], 3);
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
<input type="hidden" name="action" value="{$smarty.request.action|escape}">
|
||||
<input type="hidden" name="do" value="cashOut">
|
||||
<table>
|
||||
<tbody><tr><td>Account Balance: </td><td>{$GLOBAL.userdata.balance|escape} LTC</td></tr>
|
||||
<tbody><tr><td>Account Balance: </td><td>{$GLOBAL.userdata.balance.confirmed|escape} LTC</td></tr>
|
||||
<tr><td>Payout to: </td><td><h6>{$GLOBAL.userdata.coin_address|escape}</h6></td></tr>
|
||||
<tr><td>4 digit PIN: </td><td><input type="password" name="authPin" size="4" maxlength="4"></td></tr>
|
||||
</tbody></table>
|
||||
|
||||
@ -70,7 +70,8 @@
|
||||
{/if}
|
||||
<tr><td colspan="2"> </td></tr>
|
||||
<tr><td colspan="2"><b><u>Account Balance</u></b></td></tr>
|
||||
<tr><td colspan="2" class="right"><b>{$GLOBAL.userdata.balance|default:"0"} LTC</td></tr>
|
||||
<tr><td>Confirmed</td><td class="right"><b>{$GLOBAL.userdata.balance.confirmed|default:"0"} LTC</td></tr>
|
||||
<tr><td>Unconfirmed</td><td class="right"><b>{$GLOBAL.userdata.balance.unconfirmed|default:"0"} LTC</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="bendl"></div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user