require 'lib/scrypt.php';
define('START_TIME' , microtime(true));
-define('CHECK_POINT' , 'chash.pos');
+define('CHECKPOINT_FILE' , 'chash.pos');
// Hashes needed to complete a "block"
$GLOBALS['block_size'] = 100;
$GLOBALS['difficulty'] = 2;
// Found hashes
-$GLOBALS['found_hashes'] = array(0 => array());
+$GLOBALS['found_hashes'] = array([]);
/**
* Continued-hashing
*/
// Is the check point there?
-if (is_readable(CHECK_POINT)) {
+if (is_readable(CHECKPOINT_FILE)) {
// Load it
loadCheckpointFile();
} else {
$gensisHashes = array(
// A famous quote from Deus Ex 2 - Invisible War
multiplehashString('"Informations must be free." - AI Helios from Deus Ex'),
- // My name + URL of my first StatusNet instance
- multipleHashString('Roland Haeder, https://status.mxchange.org'),
+ // My name + URL of my GNUSocial instance
+ multipleHashString('Roland Haeder, https://social.mxchange.org'),
// A famous quote from Linus Torwalds
multipleHashString('"Software is like sex. Its better when its free." - Linus Torwalds'),
// Well ...
// Calulcate final "genesis" hash
$genesisHash = hashString(
+ $genesisBlock[3] .
$genesisBlock[0] .
$genesisBlock[2] .
- $genesisBlock[1] .
- $genesisBlock[3]
+ $genesisBlock[1]
);
// Get all elements to get the last part out
while (true) {
// Init hash-per-block counter and hashrate
$GLOBALS['hashes_block'] = 0;
- $hashrate = 0;
+ $hashRate = 1;
// Wait for block_size iterations (= found hashes). This is one block
$timeBlock = microtime(true);
$testTime = abs(microtime(true) - $timeDisplay);
// Calculate hashrate/sec
- $hashrate = 1 / $testTime * $GLOBALS['iteration_second'] * $GLOBALS['hash_cycles'];
+ $hashRate = 1 / $testTime * $GLOBALS['iteration_second'] * $GLOBALS['hash_cycles'];
// Only every second
if ($testTime >= 1) {
// Display hash rate
- print ('hashrate=' . round($hashrate) . ' hashes/sec,iterSecond=' . $GLOBALS['iteration_second'] . ' iterations/sec,difficulty=' . $GLOBALS['difficulty'] . PHP_EOL);
+ print ('hashrate=' . round($hashRate) . ' hashes/sec,iterSecond=' . $GLOBALS['iteration_second'] . ' iterations/sec,difficulty=' . $GLOBALS['difficulty'] . PHP_EOL);
// Reset timer
$timeDisplay = microtime(true);
print('total_restarts=' . $GLOBALS['total_restarts'] . ' - Restarting ...');
// Count all root (genesis) hashes
- $rootHashes = array();
+ $rootHashes = [];
foreach ($GLOBALS['found_hashes'] as $block) {
// "Walk" through all blocks
foreach ($block as $hash) {
$timeBlock = abs(microtime(true) - $timeBlock);
// Calculate reward
- $reward = abs($timeBlock - $timeBadHashes) / $hashrate * $GLOBALS['hashes_block'] / $GLOBALS['block_size'] * 1000;
- print ('timeBlock=' . $timeBlock . ',timeBadHashes=' . $timeBadHashes . ',hashesPerBlock=' . $GLOBALS['hashes_block'] .',reward=' . $reward . PHP_EOL);
+ $reward = abs($timeBlock - $timeBadHashes) / $hashRate * $GLOBALS['hashes_block'] / max(1, $GLOBALS['block_size']) * 1000;
+ print('timeBlock=' . $timeBlock . ',timeBadHashes=' . $timeBadHashes . ',hashesPerBlock=' . $GLOBALS['hashes_block'] .',reward=' . $reward . PHP_EOL);
// Double difficulty
$GLOBALS['difficulty'] = $GLOBALS['difficulty'] * 2;
$GLOBALS['hashes_block'] = 0;
// Init next block
- $GLOBALS['found_hashes'][$GLOBALS['total_blocks']] = array();
+ $GLOBALS['found_hashes'][$GLOBALS['total_blocks']] = [];
// Calculate new nonce
calculateNonce();