Continued with chash:
authorRoland Häder <roland@mxchange.org>
Sun, 15 Nov 2020 01:51:35 +0000 (02:51 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 15 Nov 2020 01:51:35 +0000 (02:51 +0100)
- fixed hexdec() errors, scrypt returns non-hexadecimal characters, too
- fixed division by zero

Signed-off-by: Roland Häder <roland@mxchange.org>
contrib/chash/chash.php
contrib/chash/lib/functions.php

index ed583d9946b113fb9faf42b40e779696cfc919b4..e04f03a472c17ff65968f9b9a3a6d0d249b7a186 100644 (file)
@@ -257,10 +257,10 @@ while (true) {
                        // 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
@@ -269,7 +269,7 @@ while (true) {
                        $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();
@@ -287,7 +287,7 @@ while (true) {
        $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
index c56cd6f06662bd31ca384a498aed54274918d324..c4a9433b22ec3de9a6f7f0aa1a07e6bb59c7757c 100644 (file)
@@ -43,15 +43,22 @@ function multipleHashString ($str) {
  */
 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);
        $sum = 0;
 
        $sum = 0;
 
+       // Part of the hash is not decodeable
+       $decodeA = explode('$', $hash);
+       $decode = $decodeA[4];
+
        // Loop through hash
        // Loop through hash
-       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++) {
                // And add it
                // And add it
-               $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);
        return $sum;
 }
 
        return $sum;
 }