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:
parent
e8dcba2dcc
commit
ece3d8fd25
@ -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']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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)) {
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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']);
|
||||
|
||||
@ -13,10 +13,10 @@
|
||||
<tbody>
|
||||
{assign var=rank value=1}
|
||||
{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"}">
|
||||
<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>{$BLOCKSFOUND[block].time|date_format:"%d/%m/%Y %H:%M:%S"}</td>
|
||||
<td>{$BLOCKSFOUND[block].difficulty|number_format}</td>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user