diff --git a/src/mining.cpp b/src/mining.cpp index 98a4f99..cbffbca 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -340,16 +340,12 @@ void runMiner(void * task_id) { } shares++; - // check if valid header + // check if valid header if(checkValid(hash, mMiner.bytearray_target)){ Serial.printf("[WORKER] %d CONGRATULATIONS! Valid block found with nonce: %d | 0x%x\n", miner_id, nonce, nonce); valids++; Serial.printf("[WORKER] %d Submitted work valid!\n", miner_id); - // STEP 3: Submit mining job - tx_mining_submit(client, mWorker, mJob, nonce); - client.stop(); - // exit - nonce = MAX_NONCE; + // wait for new job break; } // increment nonce diff --git a/src/utils.cpp b/src/utils.cpp index 8216ef7..642e3f9 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -113,15 +113,18 @@ double diff_from_target(void *target) bool checkValid(unsigned char* hash, unsigned char* target) { bool valid = true; + unsigned char diff_target[32]; + memcpy(diff_target, &target, 32); + //convert target to little endian for comparison + reverse_bytes(diff_target, 32); + for(uint8_t i=31; i>=0; i--) { - if(hash[i] > target[i]) { + if(hash[i] > diff_target[i]) { valid = false; break; - } else if (hash[i] < target[i]) { - valid = true; - break; } } + #ifdef DEBUG_MINING if (valid) { Serial.print("\tvalid : ");