adding block statistics, added finder and round shares for blocks, updates transactions for new columns, updated template and pool statistics code

This commit is contained in:
Sebastian Grewe 2013-05-13 09:21:41 +02:00
parent e8dcba2dcc
commit ece3d8fd25
6 changed files with 48 additions and 26 deletions

View File

@ -44,13 +44,19 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
} }
$aAccountShares = $share->getSharesForAccounts($share->getLastUpstreamId(), $iCurrentUpstreamId); $aAccountShares = $share->getSharesForAccounts($share->getLastUpstreamId(), $iCurrentUpstreamId);
$iRoundShares = $share->getRoundShares($share->getLastUpstreamId(), $iCurrentUpstreamId); $iRoundShares = $share->getRoundShares($share->getLastUpstreamId(), $iCurrentUpstreamId);
verbose("ID\tHeight\tTime\t\tShares\tFinder\t\tShare ID\tPrevious Share\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() . "\n\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)) { if (empty($aAccountShares)) {
verbose("\nNo shares found for this block\n\n"); verbose("\nNo shares found for this block\n\n");
sleep(2); sleep(2);
continue; 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"); verbose("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tStatus\n");
foreach ($aAccountShares as $key => $aData) { foreach ($aAccountShares as $key => $aData) {
$aData['percentage'] = number_format(round(( 100 / $iRoundShares ) * $aData['valid'], 8), 8); $aData['percentage'] = number_format(round(( 100 / $iRoundShares ) * $aData['valid'], 8), 8);
@ -62,7 +68,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
$aData['percentage'] . "\t" . $aData['percentage'] . "\t" .
$aData['payout'] . "\t"); $aData['payout'] . "\t");
// Do all database updates for statistics and payouts // Do all database updates for block, statistics and payouts
$strStatus = "OK"; $strStatus = "OK";
if (!$statistics->updateShareStatistics($aData, $aBlock['id'])) if (!$statistics->updateShareStatistics($aData, $aBlock['id']))
$strStatus = "Stats Failed"; $strStatus = "Stats Failed";
@ -74,6 +80,6 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
// Move counted shares to archive before this blockhash upstream share // Move counted shares to archive before this blockhash upstream share
$share->moveArchive($share->getLastUpstreamId(), $iCurrentUpstreamId, $aBlock['id']); $share->moveArchive($share->getLastUpstreamId(), $iCurrentUpstreamId, $aBlock['id']);
$block->setAccounted($aBlock['blockhash']); $block->setAccounted($aBlock['id']);
} }
} }

View File

@ -96,20 +96,32 @@ class Block {
return false; return false;
} }
public function setAccounted($blockhash='') { private function updateSingle($block_id, $field, $value) {
if ($blockhash == '') return false; $stmt = $this->mysqli->prepare("UPDATE $this->table SET $field = ? WHERE id = ?");
$stmt = $this->mysqli->prepare("UPDATE $this->table SET accounted = 1 WHERE blockhash = ?");
if ($this->checkStmt($stmt)) { if ($this->checkStmt($stmt)) {
$stmt->bind_param('s', $blockhash); $stmt->bind_param('ii', $value, $block_id);
if (!$stmt->execute()) { 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(); $stmt->close();
return false; return false;
} }
$stmt->close(); $stmt->close();
return true; 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) { private function checkStmt($bState) {

View File

@ -77,17 +77,17 @@ class Transaction {
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT IFNULL(c.credit, 0) - IFNULL(d.debit,0) AS balance SELECT IFNULL(c.credit, 0) - IFNULL(d.debit,0) AS balance
FROM ( FROM (
SELECT account_id, sum(t.amount) AS credit SELECT t.account_id, sum(t.amount) AS credit
FROM $this->table AS t FROM $this->table AS t
LEFT JOIN $this->tableBlocks AS b ON t.block_id = b.id LEFT JOIN $this->tableBlocks AS b ON t.block_id = b.id
WHERE type = 'Credit' WHERE type = 'Credit'
AND b.confirmations > ? AND b.confirmations > ?
AND account_id = ? ) AS c AND t.account_id = ? ) AS c
LEFT JOIN ( LEFT JOIN (
SELECT account_id, sum(amount) AS debit SELECT t.account_id, sum(amount) AS debit
FROM $this->table FROM $this->table AS t
WHERE type IN ('Debit_MP','Debit_AP') 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 ON c.account_id = d.account_id
"); ");
if ($this->checkStmt($stmt)) { if ($this->checkStmt($stmt)) {

View File

@ -26,8 +26,12 @@ class User {
return $this->sError; return $this->sError;
} }
public function getUserName($userID) { public function getUserName($id) {
return $this->getSingle($userID, 'username'); return $this->getSingle($id, 'username');
}
public function getUserId($username) {
return $this->getSingle($username, 'id', 'username');
} }
public function checkLogin($username, $password) { public function checkLogin($username, $password) {
@ -51,10 +55,10 @@ class User {
return $pin_hash === $row_pin; return $pin_hash === $row_pin;
} }
private function getSingle($userID, $search='id') { private function getSingle($value, $search='id', $field='id') {
$stmt = $this->mysqli->prepare("SELECT $search FROM $this->table WHERE id = ? LIMIT 1"); $stmt = $this->mysqli->prepare("SELECT $search FROM $this->table WHERE $field = ? LIMIT 1");
if ($this->checkStmt($stmt)) { if ($this->checkStmt($stmt)) {
$stmt->bind_param('i', $userID); $stmt->bind_param('i', $value);
$stmt->execute(); $stmt->execute();
$stmt->bind_result($retval); $stmt->bind_result($retval);
$stmt->fetch(); $stmt->fetch();

View File

@ -28,14 +28,14 @@ $stmt->execute();
$contributors = $stmt->get_result(); $contributors = $stmt->get_result();
$aContributorData = $contributors->fetch_all(MYSQLI_ASSOC); $aContributorData = $contributors->fetch_all(MYSQLI_ASSOC);
$stmt->close(); $stmt->close();
*/
// Grab the last block found // 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(); $stmt->execute();
$blocks = $stmt->get_result(); $blocks = $stmt->get_result();
$aBlockData = $blocks->fetch_array(); $aBlockData = $blocks->fetch_array();
$stmt->close(); $stmt->close();
*/
// Grab the last 10 blocks found // Grab the last 10 blocks found
$stmt = $mysqli->prepare("SELECT * FROM blocks ORDER BY height DESC LIMIT 10"); $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 // Estimated time to find the next block
$iEstTime = (($dDifficulty * bcpow(2,$config['difficulty'])) / ( $settings->getValue('currenthashrate') * 1000)); $iEstTime = (($dDifficulty * bcpow(2,$config['difficulty'])) / ( $settings->getValue('currenthashrate') * 1000));
$now = new DateTime( "now" ); $now = new DateTime( "now" );
$dTimeSinceLast = ($now->getTimestamp() - $aBlockData['timestamp']); $dTimeSinceLast = ($now->getTimestamp() - $aBlockData['time']);
// Propagate content our template // Propagate content our template
$smarty->assign("ESTTIME", $iEstTime); $smarty->assign("ESTTIME", $iEstTime);
@ -56,7 +56,7 @@ $smarty->assign("CONTRIBUTORS", $aContributorData);
$smarty->assign("BLOCKSFOUND", $aBlocksFoundData); $smarty->assign("BLOCKSFOUND", $aBlocksFoundData);
$smarty->assign("TOPHASHRATES", $aHashData); $smarty->assign("TOPHASHRATES", $aHashData);
$smarty->assign("CURRENTBLOCK", $iBlock); $smarty->assign("CURRENTBLOCK", $iBlock);
$smarty->assign("LASTBLOCK", $aBlockData['blockNumber']); $smarty->assign("LASTBLOCK", $aBlockData['height']);
$smarty->assign("DIFFICULTY", $dDifficulty); $smarty->assign("DIFFICULTY", $dDifficulty);
$smarty->assign("TARGETDIFF", $config['difficulty']); $smarty->assign("TARGETDIFF", $config['difficulty']);
$smarty->assign("REWARD", $config['reward']); $smarty->assign("REWARD", $config['reward']);

View File

@ -13,10 +13,10 @@
<tbody> <tbody>
{assign var=rank value=1} {assign var=rank value=1}
{section block $BLOCKSFOUND} {section block $BLOCKSFOUND}
{assign var=user value="."|explode:$BLOCKSFOUND[block].username} {assign var=user value="."|explode:$BLOCKSFOUND[block].finder}
<tr class="{cycle values="odd,even"}"> <tr class="{cycle values="odd,even"}">
<td>{$BLOCKSFOUND[block].height}</td> <td>{$BLOCKSFOUND[block].height}</td>
<td>{if $BLOCKSFOUND[block].confirmations >= 120}<font color="green">Confirmed</font>{else}<font color="orange">{120 - $BLOCKSFOUND[block].confirms} left</font>{/if}</td> <td>{if $BLOCKSFOUND[block].confirmations >= 120}<font color="green">Confirmed</font>{else}{120 - $BLOCKSFOUND[block].confirmations} left{/if}</td>
<td>{$user.0|default:"unknown"}</td> <td>{$user.0|default:"unknown"}</td>
<td>{$BLOCKSFOUND[block].time|date_format:"%d/%m/%Y %H:%M:%S"}</td> <td>{$BLOCKSFOUND[block].time|date_format:"%d/%m/%Y %H:%M:%S"}</td>
<td>{$BLOCKSFOUND[block].difficulty|number_format}</td> <td>{$BLOCKSFOUND[block].difficulty|number_format}</td>