diff --git a/cronjobs/ledger.php b/cronjobs/ledger.php deleted file mode 100644 index bbb1467a..00000000 --- a/cronjobs/ledger.php +++ /dev/null @@ -1,25 +0,0 @@ -confirmCredits(); diff --git a/cronjobs/sharecounter.php b/cronjobs/pps_payout.php similarity index 82% rename from cronjobs/sharecounter.php rename to cronjobs/pps_payout.php index 77b1d6ca..c5270cbf 100644 --- a/cronjobs/sharecounter.php +++ b/cronjobs/pps_payout.php @@ -44,15 +44,20 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $aData['invalid'] . "\t" . $aData['percentage'] . "\t" . $aData['payout'] . "\t"; - if (!$statistics->updateShareStatistics($aData, $aBlock['id'])) { - echo "Stats Failed" . "\n"; - } + + // Do all database updates for statistics and payouts + $strStatus = "OK"; + // if (!$statistics->updateShareStatistics($aData, $aBlock['id'])) + // $strStatus = "Stats Failed"; + if (!$transaction->addCredit($aData['id'], $aData['payout'], $aBlock['id'])) + $strStatus = "Transaction Failed"; + echo "$strStatus\n"; } echo "------------------------------------------------------------------------\n\n"; // Now that we have all shares counted internally let's update the tables // Set shares as counted and mark block as accounted for - // $share->setCountedByTimeframe($aBlock['time'], $iPrevBlockTime); - // $block->setAccounted($aBlock['blockhash']); + $share->setCountedByTimeframe($aBlock['time'], $iPrevBlockTime); + $block->setAccounted($aBlock['blockhash']); } } diff --git a/public/include/autoloader.inc.php b/public/include/autoloader.inc.php index 6bc52a45..dad1ff39 100644 --- a/public/include/autoloader.inc.php +++ b/public/include/autoloader.inc.php @@ -9,5 +9,5 @@ require_once(CLASS_DIR . '/user.class.php'); require_once(CLASS_DIR . '/block.class.php'); require_once(CLASS_DIR . '/share.class.php'); require_once(CLASS_DIR . '/statistics.class.php'); -require_once(CLASS_DIR . '/ledger.class.php'); +require_once(CLASS_DIR . '/transaction.class.php'); require_once(CLASS_DIR . '/settings.class.php'); diff --git a/public/include/classes/ledger.class.php b/public/include/classes/ledger.class.php deleted file mode 100644 index 5138004b..00000000 --- a/public/include/classes/ledger.class.php +++ /dev/null @@ -1,56 +0,0 @@ -debug = $debug; - $this->mysqli = $mysqli; - $this->debug->append("Instantiated Ledger class", 2); - } - - // get and set methods - private function setErrorMessage($msg) { - $this->sError = $msg; - } - public function getError() { - return $this->sError; - } - - public function confirmCredits() { - $stmt = $this->mysqli->prepare("UPDATE - ledger AS l - INNER JOIN blocks as b ON l.assocBlock = b.height - SET l.confirmed = 1 - WHERE b.confirmations > 120 - AND l.confirmed = 0"); - if ($this->checkStmt($stmt)) { - if (!$stmt->execute()) { - $this->debug->append("Failed to execute statement: " . $stmt->error); - $stmt->close(); - return false; - } - $stmt->close(); - return true; - } - return false; - } - - private function checkStmt($bState) { - if ($bState ===! true) { - $this->debug->append("Failed to prepare statement: " . $this->mysqli->error); - $this->setErrorMessage('Internal application Error'); - return false; - } - return true; - } -} - -$ledger = new Ledger($debug, $mysqli, SALT); diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 27a85445..eee203d4 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -25,9 +25,9 @@ class Statistics { } public function updateShareStatistics($aStats, $iBlockId) { - $stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, block_id) VALUES (?, ?, ?, ?, ?)"); + $stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, block_id) VALUES (?, ?, ?, ?)"); if ($this->checkStmt($stmt)) { - $stmt->bind_param('iiiddi', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId); + $stmt->bind_param('iiii', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId); if ($stmt->execute()) { return true; } diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php new file mode 100644 index 00000000..3f0635f3 --- /dev/null +++ b/public/include/classes/transaction.class.php @@ -0,0 +1,95 @@ +debug = $debug; + $this->mysqli = $mysqli; + $this->debug->append("Instantiated Ledger class", 2); + } + + // get and set methods + private function setErrorMessage($msg) { + $this->sError = $msg; + } + public function getError() { + return $this->sError; + } + + public function addCredit($account_id, $amount, $block_id) { + $strType = 'Credit'; + $stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, amount, block_id, type) VALUES (?, ?, ?, ?)"); + echo $this->mysqli->error; + if ($this->checkStmt($stmt)) { + $stmt->bind_param("idis", $account_id, $amount, $block_id, $strType); + if ($stmt->execute()) { + $stmt->close(); + return true; + } + } + return false; + } + + public function confirmCredits() { + $stmt = $this->mysqli->prepare("UPDATE + ledger AS l + INNER JOIN blocks as b ON l.assocBlock = b.height + SET l.confirmed = 1 + WHERE b.confirmations > 120 + AND l.confirmed = 0"); + if ($this->checkStmt($stmt)) { + if (!$stmt->execute()) { + $this->debug->append("Failed to execute statement: " . $stmt->error); + $stmt->close(); + return false; + } + $stmt->close(); + return true; + } + return false; + } + + public function getTransactions($account_id, $start=0) { + $stmt = $this->mysqli->prepare(" + SELECT + t.id AS id, + t.type AS type, + t.amount AS amount, + t.sendAddress AS sendAddress, + t.timestamp AS timestamp, + b.height AS height, + b.confirmations AS confirmations + FROM transactions AS t + LEFT JOIN blocks AS b ON t.block_id = b.id + WHERE t.account_id = ? + ORDER BY timestamp DESC + LIMIT ? , 30"); + if ($this->checkStmt($stmt)) { + if(!$stmt->bind_param('ii', $account_id, $start)) return false; + $stmt->execute(); + $result = $stmt->get_result(); + return $result->fetch_all(MYSQLI_ASSOC); + } + $this->debug->append('Unable to fetch transactions'); + return false; + } + + private function checkStmt($bState) { + if ($bState ===! true) { + $this->debug->append("Failed to prepare statement: " . $this->mysqli->error); + $this->setErrorMessage('Internal application Error'); + return false; + } + return true; + } +} + +$transaction = new Transaction($debug, $mysqli); diff --git a/public/include/pages/account/transactions.inc.php b/public/include/pages/account/transactions.inc.php index e291b1dc..6e83e292 100644 --- a/public/include/pages/account/transactions.inc.php +++ b/public/include/pages/account/transactions.inc.php @@ -4,7 +4,7 @@ if (!defined('SECURITY')) die('Hacking attempt'); if (!$_SESSION['AUTHENTICATED']) header('Location: index.php?page=home'); -$aTransactions = $user->getTransactions($_SESSION['USERDATA']['id']); +$aTransactions = $transaction->getTransactions($_SESSION['USERDATA']['id']); if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg'); $smarty->assign('TRANSACTIONS', $aTransactions); diff --git a/public/templates/mmcFE/account/transactions/default.tpl b/public/templates/mmcFE/account/transactions/default.tpl index 51ee85b4..3e243b9b 100644 --- a/public/templates/mmcFE/account/transactions/default.tpl +++ b/public/templates/mmcFE/account/transactions/default.tpl @@ -19,14 +19,16 @@ {section transaction $TRANSACTIONS} + {if (($TRANSACTIONS[transaction].type == 'Credit' and $TRANSACTIONS[transaction].confirmations >= 120) or $TRANSACTIONS[transaction].type != 'Credit')} {$TRANSACTIONS[transaction].id} {$TRANSACTIONS[transaction].timestamp} - {$TRANSACTIONS[transaction].transType} + {$TRANSACTIONS[transaction].type} {$TRANSACTIONS[transaction].sendAddress} - {if $TRANSACTIONS[transaction].assocBlock == 0}n/a{else}{$TRANSACTIONS[transaction].assocBlock}{/if} - {$TRANSACTIONS[transaction].amount} + {if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if} + {$TRANSACTIONS[transaction].amount} + {/if} {/section} @@ -38,27 +40,31 @@ - - - - - + + + + + + - - - - - - +{section transaction $TRANSACTIONS} + {if $TRANSACTIONS[transaction].type == 'Credit' && $TRANSACTIONS[transaction].confirmations < 120} + + + + + + + + {assign var="sum" value="`$sum+$TRANSACTIONS[transaction].amount`"} + {/if} +{/section} - - - - - + +
Block #Estimated RewardValid SharesDonation / FeeValidityTX #DateTX TypePayment AddressBlock #Amount
TODOTODOTODOTODOTODO
{$TRANSACTIONS[transaction].id}{$TRANSACTIONS[transaction].timestamp}{$TRANSACTIONS[transaction].type}{$TRANSACTIONS[transaction].sendAddress}{if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if}{$TRANSACTIONS[transaction].amount}
Unconfirmed Totals:0.000000000.00000000Unconfirmed Totals:{$sum}