diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index d1016664..1b91e73d 100644 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -44,13 +44,19 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { } $aAccountShares = $share->getSharesForAccounts($share->getLastUpstreamId(), $iCurrentUpstreamId); $iRoundShares = $share->getRoundShares($share->getLastUpstreamId(), $iCurrentUpstreamId); - verbose("ID\tHeight\tTime\t\tShares\tFinder\t\tShare ID\tPrevious Share\n"); - verbose($aBlock['id'] . "\t" . $aBlock['height'] . "\t" . $aBlock['time'] . "\t" . $iRoundShares . "\t" . $share->getUpstreamFinder() . "\t" . $share->getUpstreamId() . "\t\t" . $share->getLastUpstreamId() . "\n\n"); + verbose("ID\tHeight\tTime\t\tShares\tFinder\t\tShare ID\tPrev Share\tStatus\n"); + verbose($aBlock['id'] . "\t" . $aBlock['height'] . "\t" . $aBlock['time'] . "\t" . $iRoundShares . "\t" . $share->getUpstreamFinder() . "\t" . $share->getUpstreamId() . "\t\t" . $share->getLastUpstreamId()); if (empty($aAccountShares)) { verbose("\nNo shares found for this block\n\n"); sleep(2); continue; } + $strStatus = "OK"; + if (!$block->setFinder($aBlock['id'], $user->getUserId($share->getUpstreamFinder()))) + $strStatus = "Finder Failed"; + if (!$block->setShares($aBlock['id'], $iRoundShares)) + $strStatus = "Shares Failed"; + verbose("\t\t$strStatus\n\n"); verbose("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tStatus\n"); foreach ($aAccountShares as $key => $aData) { $aData['percentage'] = number_format(round(( 100 / $iRoundShares ) * $aData['valid'], 8), 8); @@ -62,7 +68,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $aData['percentage'] . "\t" . $aData['payout'] . "\t"); - // Do all database updates for statistics and payouts + // Do all database updates for block, statistics and payouts $strStatus = "OK"; if (!$statistics->updateShareStatistics($aData, $aBlock['id'])) $strStatus = "Stats Failed"; @@ -74,6 +80,6 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { // Move counted shares to archive before this blockhash upstream share $share->moveArchive($share->getLastUpstreamId(), $iCurrentUpstreamId, $aBlock['id']); - $block->setAccounted($aBlock['blockhash']); + $block->setAccounted($aBlock['id']); } } diff --git a/public/include/classes/block.class.php b/public/include/classes/block.class.php index a540bdb6..9ecc8655 100644 --- a/public/include/classes/block.class.php +++ b/public/include/classes/block.class.php @@ -96,20 +96,32 @@ class Block { return false; } - public function setAccounted($blockhash='') { - if ($blockhash == '') return false; - $stmt = $this->mysqli->prepare("UPDATE $this->table SET accounted = 1 WHERE blockhash = ?"); + private function updateSingle($block_id, $field, $value) { + $stmt = $this->mysqli->prepare("UPDATE $this->table SET $field = ? WHERE id = ?"); if ($this->checkStmt($stmt)) { - $stmt->bind_param('s', $blockhash); + $stmt->bind_param('ii', $value, $block_id); if (!$stmt->execute()) { - $this->debug->append("Failed to execute statement: " . $stmt->error); + $this->debug->append("Failed to update block ID $block_id with finder ID $account_id"); $stmt->close(); return false; } $stmt->close(); return true; } - return false; + return false; + } + + public function setFinder($block_id, $account_id=NULL) { + return $this->updateSingle($block_id, 'account_id', $account_id); + } + + public function setShares($block_id, $shares=NULL) { + return $this->updateSingle($block_id, 'shares', $shares); + } + + public function setAccounted($block_id=NULL) { + if (empty($block_id)) return false; + return $this->updateSingle($block_id, 'accounted', 1); } private function checkStmt($bState) { diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index b462834f..4f443acb 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -77,17 +77,17 @@ class Transaction { $stmt = $this->mysqli->prepare(" SELECT IFNULL(c.credit, 0) - IFNULL(d.debit,0) AS balance FROM ( - SELECT account_id, sum(t.amount) AS credit + SELECT t.account_id, sum(t.amount) AS credit FROM $this->table AS t LEFT JOIN $this->tableBlocks AS b ON t.block_id = b.id WHERE type = 'Credit' AND b.confirmations > ? - AND account_id = ? ) AS c + AND t.account_id = ? ) AS c LEFT JOIN ( - SELECT account_id, sum(amount) AS debit - FROM $this->table + SELECT t.account_id, sum(amount) AS debit + FROM $this->table AS t WHERE type IN ('Debit_MP','Debit_AP') - AND account_id = ? ) AS d + AND t.account_id = ? ) AS d ON c.account_id = d.account_id "); if ($this->checkStmt($stmt)) { diff --git a/public/include/classes/user.class.php b/public/include/classes/user.class.php index 0e7b3019..33fcd3c4 100644 --- a/public/include/classes/user.class.php +++ b/public/include/classes/user.class.php @@ -26,8 +26,12 @@ class User { return $this->sError; } - public function getUserName($userID) { - return $this->getSingle($userID, 'username'); + public function getUserName($id) { + return $this->getSingle($id, 'username'); + } + + public function getUserId($username) { + return $this->getSingle($username, 'id', 'username'); } public function checkLogin($username, $password) { @@ -51,10 +55,10 @@ class User { return $pin_hash === $row_pin; } - private function getSingle($userID, $search='id') { - $stmt = $this->mysqli->prepare("SELECT $search FROM $this->table WHERE id = ? LIMIT 1"); + private function getSingle($value, $search='id', $field='id') { + $stmt = $this->mysqli->prepare("SELECT $search FROM $this->table WHERE $field = ? LIMIT 1"); if ($this->checkStmt($stmt)) { - $stmt->bind_param('i', $userID); + $stmt->bind_param('i', $value); $stmt->execute(); $stmt->bind_result($retval); $stmt->fetch(); diff --git a/public/include/pages/statistics/pool.inc.php b/public/include/pages/statistics/pool.inc.php index 3c11e98e..4eecffc0 100644 --- a/public/include/pages/statistics/pool.inc.php +++ b/public/include/pages/statistics/pool.inc.php @@ -28,14 +28,14 @@ $stmt->execute(); $contributors = $stmt->get_result(); $aContributorData = $contributors->fetch_all(MYSQLI_ASSOC); $stmt->close(); + */ // Grab the last block found -$stmt = $mysqli->prepare("SELECT id, confirmations, timestamp FROM blocks ORDER BY height DESC LIMIT 1"); +$stmt = $mysqli->prepare("SELECT * FROM blocks ORDER BY height DESC LIMIT 1"); $stmt->execute(); $blocks = $stmt->get_result(); $aBlockData = $blocks->fetch_array(); $stmt->close(); - */ // Grab the last 10 blocks found $stmt = $mysqli->prepare("SELECT * FROM blocks ORDER BY height DESC LIMIT 10"); @@ -47,7 +47,7 @@ $stmt->close(); // Estimated time to find the next block $iEstTime = (($dDifficulty * bcpow(2,$config['difficulty'])) / ( $settings->getValue('currenthashrate') * 1000)); $now = new DateTime( "now" ); -$dTimeSinceLast = ($now->getTimestamp() - $aBlockData['timestamp']); +$dTimeSinceLast = ($now->getTimestamp() - $aBlockData['time']); // Propagate content our template $smarty->assign("ESTTIME", $iEstTime); @@ -56,7 +56,7 @@ $smarty->assign("CONTRIBUTORS", $aContributorData); $smarty->assign("BLOCKSFOUND", $aBlocksFoundData); $smarty->assign("TOPHASHRATES", $aHashData); $smarty->assign("CURRENTBLOCK", $iBlock); -$smarty->assign("LASTBLOCK", $aBlockData['blockNumber']); +$smarty->assign("LASTBLOCK", $aBlockData['height']); $smarty->assign("DIFFICULTY", $dDifficulty); $smarty->assign("TARGETDIFF", $config['difficulty']); $smarty->assign("REWARD", $config['reward']); diff --git a/public/templates/mmcFE/statistics/blocks/blocks_found.tpl b/public/templates/mmcFE/statistics/blocks/blocks_found.tpl index f24a2698..181cc3c8 100644 --- a/public/templates/mmcFE/statistics/blocks/blocks_found.tpl +++ b/public/templates/mmcFE/statistics/blocks/blocks_found.tpl @@ -13,10 +13,10 @@
{assign var=rank value=1} {section block $BLOCKSFOUND} - {assign var=user value="."|explode:$BLOCKSFOUND[block].username} + {assign var=user value="."|explode:$BLOCKSFOUND[block].finder}