diff --git a/src/miner.cpp b/src/miner.cpp index aabc50627..da4af7a66 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1133,9 +1133,33 @@ void static RandomXMiner() arith_uint256 hashTarget; hashTarget = HASHTarget; - // TODO: RandomX solver code - randomx_flags flags = randomx_get_flags(); - randomx_cache *myCache = randomx_alloc_cache(flags); + char randomxHash[RANDOMX_HASH_SIZE]; + // TODO: decide on real RandomX key and input + const char randomxKey[] = "HUSH RandomX testing key"; + const char randomxInput[] = "HUSH RandomX testing input"; + randomx_flags flags = randomx_get_flags(); + randomx_cache *randomxCache = randomx_alloc_cache(flags); + + if (randomxCache == NULL) { + LogPrintf("RandomX cache is null, something is wrong, cannot mine!\n"); + return; + } + + randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey); + randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL); + + randomx_calculate_hash(myVM, &randomxInput, sizeof randomxInput, randomxHash); + + randomx_destroy_vm(myVM); + randomx_release_cache(randomxCache); + + printf("RandomX Hash: "); + for (unsigned i = 0; i < RANDOMX_HASH_SIZE; ++i) { + printf("%02x", randomxHash[i] & 0xff); + } + + printf("\n"); + // TODO: use randomx hash to build a block }