- fixed hexdec() errors, scrypt returns non-hexadecimal characters, too
- fixed division by zero
Signed-off-by: Roland Häder <roland@mxchange.org>
// Next round
$GLOBALS['iteration']++;
$GLOBALS['iteration_second']++;
// Next round
$GLOBALS['iteration']++;
$GLOBALS['iteration_second']++;
- //print ('nonce=' . $GLOBALS['nonce'] . ',iteration=' . $GLOBALS['iteration'] . PHP_EOL);
- //print ('nonceHash=' . $nonceHash . PHP_EOL);
- //print ('sumNonce=' . $sumNonce . PHP_EOL);
- //print ('sumGenesis=' . $GLOBALS['sum_genesis'] . PHP_EOL);
+ //* NOISY-DEBUG: */ print('nonce=' . $GLOBALS['nonce'] . ',iteration=' . $GLOBALS['iteration'] . PHP_EOL);
+ //* NOISY-DEBUG: */ print('nonceHash=' . $nonceHash . PHP_EOL);
+ //* NOISY-DEBUG: */ print('sumNonce=' . $sumNonce . PHP_EOL);
+ //* NOISY-DEBUG: */ print('sumGenesis=' . $GLOBALS['sum_genesis'] . PHP_EOL);
} // END - while
// If the iteration is zero, then no hash is found
} // END - while
// If the iteration is zero, then no hash is found
$timeBadHashes += abs(microtime(true) - $timeHash);
// And next round
$timeBadHashes += abs(microtime(true) - $timeHash);
// And next round
- print('BAD:nonce=' . $GLOBALS['nonce'] . PHP_EOL);
+ //* NOISY-DEBUG: */ print('BAD:nonce=' . $GLOBALS['nonce'] . PHP_EOL);
// Nothing found, so calculate new nonce
calculateNonce();
// Nothing found, so calculate new nonce
calculateNonce();
$timeBlock = abs(microtime(true) - $timeBlock);
// Calculate reward
$timeBlock = abs(microtime(true) - $timeBlock);
// Calculate reward
- $reward = abs($timeBlock - $timeBadHashes) / $hashRate * $GLOBALS['hashes_block'] / max(1, $GLOBALS['block_size']) * 1000;
+ $reward = abs($timeBlock - $timeBadHashes) / max(1, $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
print('timeBlock=' . $timeBlock . ',timeBadHashes=' . $timeBadHashes . ',hashesPerBlock=' . $GLOBALS['hashes_block'] .',reward=' . $reward . PHP_EOL);
// Double difficulty
*/
function calculateSumFromHash ($hash) {
// Everything starts with zero ...
*/
function calculateSumFromHash ($hash) {
// Everything starts with zero ...
+ //* NOISY-DEBUG: */ printf('[%s:%d]: hash(%d)=%s - CALLED!'. PHP_EOL, __FUNCTION__, __LINE__, strlen($hash), $hash);
+ // Part of the hash is not decodeable
+ $decodeA = explode('$', $hash);
+ $decode = $decodeA[4];
+
- for ($idx = 0; $idx < (strlen($hash) / 2); $idx++) {
+ //* NOISY-DEBUG: */ printf('[%s:%d]: decode=%s' . PHP_EOL, __FUNCTION__, __LINE__, $decode);
+ for ($idx = 0; $idx < (strlen($decode) / 2); $idx++) {
- $sum = $sum + hexdec(substr($hash, $idx, 2));
+ $sum = $sum + hexdec(substr($decode, $idx, 2));
} // END - for
// And return it
} // END - for
// And return it
+ //* NOISY-DEBUG: */ printf('[%s:%d]: sum=%d - EXIT!' . PHP_EOL, __FUNCTION__, __LINE__, $sum);