int ethash_quick_check_difficulty(ethash_h256_t const *header_hash, const uint64_t nonce, ethash_h256_t const *mix_hash, ethash_h256_t const *difficulty) { ethash_h256_t return_hash; ethash_quick_hash(&return_hash, header_hash, nonce, mix_hash); return ethash_check_difficulty(&return_hash, difficulty); }
bool ethash_quick_check_difficulty( ethash_h256_t const* header_hash, uint64_t const nonce, ethash_h256_t const* mix_hash, ethash_h256_t const* boundary ) { ethash_h256_t return_hash; ethash_quick_hash(&return_hash, header_hash, nonce, mix_hash); return ethash_check_difficulty(&return_hash, boundary); }
// mine(dataset_bytes, header, difficulty_bytes) static PyObject * mine(PyObject *self, PyObject *args) { char *full_bytes, *header, *difficulty; srand(time(0)); uint64_t nonce = ((uint64_t) rand()) << 32 | rand(); int full_size, header_size, difficulty_size; if (!PyArg_ParseTuple(args, PY_STRING_FORMAT PY_STRING_FORMAT PY_STRING_FORMAT, &full_bytes, &full_size, &header, &header_size, &difficulty, &difficulty_size)) return 0; if (full_size % MIX_WORDS != 0) { char error_message[1024]; sprintf(error_message, "The size of data set must be a multiple of %i bytes (was %i)", MIX_WORDS, full_size); PyErr_SetString(PyExc_ValueError, error_message); return 0; } if (header_size != 32) { char error_message[1024]; sprintf(error_message, "Header must be 32 bytes long (was %i)", header_size); PyErr_SetString(PyExc_ValueError, error_message); return 0; } if (difficulty_size != 32) { char error_message[1024]; sprintf(error_message, "Difficulty must be an array of 32 bytes (only had %i)", difficulty_size); PyErr_SetString(PyExc_ValueError, error_message); return 0; } ethash_return_value out; ethash_params params; params.full_size = (size_t) full_size; // TODO: Multi threading? do { ethash_full(&out, (void *) full_bytes, ¶ms, (const uint8_t *) header, nonce++); // TODO: disagrees with the spec https://github.com/ethereum/wiki/wiki/Ethash#mining } while (!ethash_check_difficulty(out.result, (const uint8_t *) difficulty)); return Py_BuildValue("{" PY_CONST_STRING_FORMAT ":" PY_STRING_FORMAT ", " PY_CONST_STRING_FORMAT ":" PY_STRING_FORMAT ", " PY_CONST_STRING_FORMAT ":K}", "mix digest", out.mix_hash, 32, "result", out.result, 32, "nonce", nonce); }