cleaned up crons, changed timestamp range to properly find shares, added verbose parameter
This commit is contained in:
parent
365a91e407
commit
47b3816d27
@ -31,27 +31,27 @@ if ( $bitcoin->can_connect() === true ){
|
|||||||
$aTransactions = $bitcoin->query('listsinceblock', $strLastBlockHash);
|
$aTransactions = $bitcoin->query('listsinceblock', $strLastBlockHash);
|
||||||
$iDifficulty = $bitcoin->query('getdifficulty');
|
$iDifficulty = $bitcoin->query('getdifficulty');
|
||||||
} else {
|
} else {
|
||||||
echo "Aborted: " . $bitcoin->can_connect() . "\n";
|
verbose("Aborted: " . $bitcoin->can_connect() . "\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Blockhash\t\tHeight\tAmount\tConfirmations\tDiff\t\tTime\t\t\tStatus\n";
|
verbose("Blockhash\t\tHeight\tAmount\tConfirmations\tDiff\t\tTime\t\t\tStatus\n");
|
||||||
|
|
||||||
foreach ($aTransactions['transactions'] as $iIndex => $aData) {
|
foreach ($aTransactions['transactions'] as $iIndex => $aData) {
|
||||||
if ( $aData['category'] == 'generate' || $aData['category'] == 'immature' ) {
|
if ( $aData['category'] == 'generate' || $aData['category'] == 'immature' ) {
|
||||||
$aBlockInfo = $bitcoin->query('getblock', $aData['blockhash']);
|
$aBlockInfo = $bitcoin->query('getblock', $aData['blockhash']);
|
||||||
$aData['height'] = $aBlockInfo['height'];
|
$aData['height'] = $aBlockInfo['height'];
|
||||||
$aData['difficulty'] = $iDifficulty;
|
$aData['difficulty'] = $iDifficulty;
|
||||||
echo substr($aData['blockhash'], 0, 15) . "...\t" .
|
verbose(substr($aData['blockhash'], 0, 15) . "...\t" .
|
||||||
$aData['height'] . "\t" .
|
$aData['height'] . "\t" .
|
||||||
$aData['amount'] . "\t" .
|
$aData['amount'] . "\t" .
|
||||||
$aData['confirmations'] . "\t\t" .
|
$aData['confirmations'] . "\t\t" .
|
||||||
$aData['difficulty'] . "\t" .
|
$aData['difficulty'] . "\t" .
|
||||||
strftime("%Y-%m-%d %H:%M:%S", $aData['time']) . "\t";
|
strftime("%Y-%m-%d %H:%M:%S", $aData['time']) . "\t");
|
||||||
if ( $block->addBlock($aData) ) {
|
if ( $block->addBlock($aData) ) {
|
||||||
echo "Added\n";
|
verbose("Added\n");
|
||||||
} else {
|
} else {
|
||||||
echo "Failed" . "\n";
|
verbose("Failed" . "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@ limitations under the License.
|
|||||||
// Include all settings and classes
|
// Include all settings and classes
|
||||||
require_once('shared.inc.php');
|
require_once('shared.inc.php');
|
||||||
|
|
||||||
// Fetch our last block found from the DB as a starting point
|
// Fetch all accounted blocks
|
||||||
$aAllBlocks = $block->getAllUnaccounted('ASC');
|
$aAllBlocks = $block->getAllUnaccounted('ASC');
|
||||||
foreach ($aAllBlocks as $iIndex => $aBlock) {
|
foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||||
if (!$aBlock['accounted']) {
|
if (!$aBlock['accounted']) {
|
||||||
@ -32,32 +32,31 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
|||||||
$aAccountShares = $share->getSharesForAccountsByTimeframe($aBlock['time'], $iPrevBlockTime);
|
$aAccountShares = $share->getSharesForAccountsByTimeframe($aBlock['time'], $iPrevBlockTime);
|
||||||
$iRoundShares = $share->getRoundSharesByTimeframe($aBlock['time'], $iPrevBlockTime);
|
$iRoundShares = $share->getRoundSharesByTimeframe($aBlock['time'], $iPrevBlockTime);
|
||||||
$strFinder = $share->getFinderByTimeframe($aBlock['time'], $iPrevBlockTime);
|
$strFinder = $share->getFinderByTimeframe($aBlock['time'], $iPrevBlockTime);
|
||||||
echo "ID\tHeight\tTime\t\tShares\tFinder\n";
|
verbose("ID\tHeight\tTime\t\tShares\tFinder\n");
|
||||||
echo $aBlock['id'] . "\t" . $aBlock['height'] . "\t" . $aBlock['time'] . "\t" . $iRoundShares . "\t" . $strFinder . "\n\n";
|
verbose($aBlock['id'] . "\t" . $aBlock['height'] . "\t" . $aBlock['time'] . "\t" . $iRoundShares . "\t" . $strFinder . "\n\n");
|
||||||
echo "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'], 10),10);
|
$aData['percentage'] = number_format(round(( 100 / $iRoundShares ) * $aData['valid'], 10),10);
|
||||||
$aData['payout'] = number_format(round(( $aData['percentage'] / 100 ) * $config['reward'], 10), 10);
|
$aData['payout'] = number_format(round(( $aData['percentage'] / 100 ) * $config['reward'], 10), 10);
|
||||||
echo $aData['id'] . "\t" .
|
verbose($aData['id'] . "\t" .
|
||||||
$aData['username'] . "\t" .
|
$aData['username'] . "\t" .
|
||||||
$aData['valid'] . "\t" .
|
$aData['valid'] . "\t" .
|
||||||
$aData['invalid'] . "\t" .
|
$aData['invalid'] . "\t" .
|
||||||
$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 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";
|
||||||
if (!$transaction->addCredit($aData['id'], $aData['payout'], $aBlock['id']))
|
if (!$transaction->addCredit($aData['id'], $aData['payout'], $aBlock['id']))
|
||||||
$strStatus = "Transaction Failed";
|
$strStatus = "Transaction Failed";
|
||||||
echo "$strStatus\n";
|
verbose("$strStatus\n");
|
||||||
}
|
}
|
||||||
echo "------------------------------------------------------------------------\n\n";
|
verbose("------------------------------------------------------------------------\n\n");
|
||||||
|
|
||||||
// Now that we have all shares counted internally let's update the tables
|
// Move counted shares to archive for this blockhash
|
||||||
// Set shares as counted and mark block as accounted for
|
$share->moveArchiveByTimeframe($aBlock['time'], $iPrevBlockTime, $aBlock['id']);
|
||||||
$share->setCountedByTimeframe($aBlock['time'], $iPrevBlockTime);
|
|
||||||
$block->setAccounted($aBlock['blockhash']);
|
$block->setAccounted($aBlock['blockhash']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,3 +30,17 @@ require_once(BASEPATH . '/include/config/global.inc.php');
|
|||||||
|
|
||||||
// We include all needed files here, even though our templates could load them themself
|
// We include all needed files here, even though our templates could load them themself
|
||||||
require_once(BASEPATH . INCLUDE_DIR . '/autoloader.inc.php');
|
require_once(BASEPATH . INCLUDE_DIR . '/autoloader.inc.php');
|
||||||
|
|
||||||
|
// Parse command line
|
||||||
|
$options = getopt("v");
|
||||||
|
if (array_key_exists('v', $options)) {
|
||||||
|
define("VERBOSE", true);
|
||||||
|
} else {
|
||||||
|
define("VERBOSE", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command line cron functions only
|
||||||
|
function verbose($msg) {
|
||||||
|
if (VERBOSE) echo $msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,11 +37,11 @@ class Share {
|
|||||||
COUNT(id) AS valid
|
COUNT(id) AS valid
|
||||||
FROM $this->table
|
FROM $this->table
|
||||||
WHERE
|
WHERE
|
||||||
UNIX_TIMESTAMP(time) BETWEEN ? AND ?
|
UNIX_TIMESTAMP(time) > ?
|
||||||
|
AND
|
||||||
|
UNIX_TIMESTAMP(time) <= ?
|
||||||
AND
|
AND
|
||||||
our_result = 'Y'
|
our_result = 'Y'
|
||||||
AND
|
|
||||||
counted = 0
|
|
||||||
GROUP BY account
|
GROUP BY account
|
||||||
) validT
|
) validT
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
@ -51,11 +51,11 @@ class Share {
|
|||||||
COUNT(id) AS invalid
|
COUNT(id) AS invalid
|
||||||
FROM $this->table
|
FROM $this->table
|
||||||
WHERE
|
WHERE
|
||||||
UNIX_TIMESTAMP(time) BETWEEN ? AND ?
|
UNIX_TIMESTAMP(time) > ?
|
||||||
|
AND
|
||||||
|
UNIX_TIMESTAMP(time) <= ?
|
||||||
AND
|
AND
|
||||||
our_result = 'N'
|
our_result = 'N'
|
||||||
AND
|
|
||||||
counted = 0
|
|
||||||
GROUP BY account
|
GROUP BY account
|
||||||
) invalidT
|
) invalidT
|
||||||
ON validT.account = invalidT.account
|
ON validT.account = invalidT.account
|
||||||
@ -76,8 +76,10 @@ class Share {
|
|||||||
count(id) as total
|
count(id) as total
|
||||||
FROM $this->table
|
FROM $this->table
|
||||||
WHERE our_result = 'Y'
|
WHERE our_result = 'Y'
|
||||||
AND UNIX_TIMESTAMP(time) BETWEEN ? AND ?
|
AND
|
||||||
AND counted = 0
|
UNIX_TIMESTAMP(time) > ?
|
||||||
|
AND
|
||||||
|
UNIX_TIMESTAMP(time) <= ?
|
||||||
");
|
");
|
||||||
if ($this->checkStmt($stmt)) {
|
if ($this->checkStmt($stmt)) {
|
||||||
$stmt->bind_param('ii', $old, $current);
|
$stmt->bind_param('ii', $old, $current);
|
||||||
@ -89,19 +91,28 @@ class Share {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCountedByTimeframe($current='', $old='') {
|
public function moveArchiveByTimeframe($current='', $old='',$block_id) {
|
||||||
$stmt = $this->mysqli->prepare("UPDATE $this->table
|
$archive_stmt = $this->mysqli->prepare("INSERT INTO shares_archive (share_id, username, our_result, upstream_result, block_id)
|
||||||
SET
|
SELECT id, username, our_result, upstream_result, ?
|
||||||
counted = 1
|
FROM $this->table
|
||||||
WHERE
|
WHERE
|
||||||
UNIX_TIMESTAMP(time) BETWEEN ? AND ?
|
UNIX_TIMESTAMP(time) > ?
|
||||||
AND counted = 0
|
AND
|
||||||
");
|
UNIX_TIMESTAMP(time) <= ?
|
||||||
if ($this->checkStmt($stmt)) {
|
");
|
||||||
$stmt->bind_param('ii', $old, $current);
|
$delete_stmt = $this->mysqli->prepare("DELETE FROM $this->table
|
||||||
$stmt->execute();
|
WHERE
|
||||||
$result = $stmt->get_result();
|
UNIX_TIMESTAMP(time) > ?
|
||||||
$stmt->close();
|
AND
|
||||||
|
UNIX_TIMESTAMP(time) <= ?
|
||||||
|
");
|
||||||
|
if ($this->checkStmt($archive_stmt) && $this->checkStmt($delete_stmt)) {
|
||||||
|
$archive_stmt->bind_param('iii', $block_id, $old, $current);
|
||||||
|
$archive_stmt->execute();
|
||||||
|
$delete_stmt->bind_param('ii', $old, $current);
|
||||||
|
$delete_stmt->execute();
|
||||||
|
$delete_stmt->close();
|
||||||
|
$archive_stmt->close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -112,7 +123,10 @@ class Share {
|
|||||||
SUBSTRING_INDEX( `username` , '.', 1 ) AS account
|
SUBSTRING_INDEX( `username` , '.', 1 ) AS account
|
||||||
FROM $this->table
|
FROM $this->table
|
||||||
WHERE upstream_result = 'Y'
|
WHERE upstream_result = 'Y'
|
||||||
AND UNIX_TIMESTAMP(time) BETWEEN ? AND ?
|
AND
|
||||||
|
UNIX_TIMESTAMP(time) > ?
|
||||||
|
AND
|
||||||
|
UNIX_TIMESTAMP(time) <= ?
|
||||||
ORDER BY id DESC");
|
ORDER BY id DESC");
|
||||||
if ($this->checkStmt($stmt)) {
|
if ($this->checkStmt($stmt)) {
|
||||||
$stmt->bind_param('ii', $old, $current);
|
$stmt->bind_param('ii', $old, $current);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user