#include "kernel.h"
#include "kernel_worker.h"
+#include <openssl/sha.h>
+
using namespace std;
-KernelWorker::KernelWorker(unsigned char *kernel, uint32_t nBits, uint32_t nInputTxTime, int64_t nValueIn, uint32_t nIntervalBegin, uint32_t nIntervalEnd)
+KernelWorker::KernelWorker(uint8_t *kernel, uint32_t nBits, uint32_t nInputTxTime, int64_t nValueIn, uint32_t nIntervalBegin, uint32_t nIntervalEnd)
: kernel(kernel), nBits(nBits), nInputTxTime(nInputTxTime), bnValueIn(nValueIn), nIntervalBegin(nIntervalBegin), nIntervalEnd(nIntervalEnd)
{
- solutions = vector<std::pair<uint256,uint32_t> >();
+ solutions = vector<pair<uint256,uint32_t> >();
}
void KernelWorker::Do_generic()
// Compute maximum possible target to filter out majority of obviously insufficient hashes
CBigNum bnTargetPerCoinDay;
bnTargetPerCoinDay.SetCompact(nBits);
- uint256 nMaxTarget = (bnTargetPerCoinDay * bnValueIn * nStakeMaxAge / COIN / nOneDay).getuint256();
+ auto nMaxTarget = (bnTargetPerCoinDay * bnValueIn * nStakeMaxAge / COIN / nOneDay).getuint256();
SHA256_CTX ctx, workerCtx;
// Init new sha256 context and update it
// Search forward in time from the given timestamp
// Stopping search in case of shutting down
- for (uint32_t nTimeTx=nIntervalBegin, nMaxTarget32 = nMaxTarget.Get32(7); nTimeTx<nIntervalEnd && !fShutdown; nTimeTx++)
+ for (auto nTimeTx=nIntervalBegin, nMaxTarget32 = nMaxTarget.Get32(7); nTimeTx<nIntervalEnd && !fShutdown; nTimeTx++)
{
// Complete first hashing iteration
uint256 hash1;
SHA256_Update(&ctx, (unsigned char*)&nTimeTx, 4);
- SHA256_Final((unsigned char*)&hash1, &ctx);
+ SHA256_Final(hash1.begin(), &ctx);
// Restore context
ctx = workerCtx;
// Finally, calculate kernel hash
- SHA256((unsigned char*)&hash1, sizeof(hashProofOfStake), (unsigned char*)&hashProofOfStake);
+ SHA256(hash1.begin(), sizeof(hashProofOfStake), (unsigned char*)&hashProofOfStake);
// Skip if hash doesn't satisfy the maximum target
if (hashProofOfStake[7] > nMaxTarget32)
// Scan given kernel for solutions
-bool ScanKernelBackward(unsigned char *kernel, uint32_t nBits, uint32_t nInputTxTime, int64_t nValueIn, std::pair<uint32_t, uint32_t> &SearchInterval, std::pair<uint256, uint32_t> &solution)
+bool ScanKernelBackward(uint8_t *kernel, uint32_t nBits, uint32_t nInputTxTime, int64_t nValueIn, pair<uint32_t, uint32_t> &SearchInterval, pair<uint256, uint32_t> &solution)
{
CBigNum bnTargetPerCoinDay;
bnTargetPerCoinDay.SetCompact(nBits);
CBigNum bnValueIn(nValueIn);
// Get maximum possible target to filter out the majority of obviously insufficient hashes
- uint256 nMaxTarget = (bnTargetPerCoinDay * bnValueIn * nStakeMaxAge / COIN / nOneDay).getuint256();
+ auto nMaxTarget = (bnTargetPerCoinDay * bnValueIn * nStakeMaxAge / COIN / nOneDay).getuint256();
SHA256_CTX ctx, workerCtx;
// Init new sha256 context and update it
// Complete first hashing iteration
uint256 hash1;
SHA256_Update(&ctx, (unsigned char*)&nTimeTx, 4);
- SHA256_Final((unsigned char*)&hash1, &ctx);
+ SHA256_Final(hash1.begin(), &ctx);
// Restore context
ctx = workerCtx;
// Finally, calculate kernel hash
uint256 hashProofOfStake;
- SHA256((unsigned char*)&hash1, sizeof(hashProofOfStake), (unsigned char*)&hashProofOfStake);
+ SHA256(hash1.begin(), hashProofOfStake.size(), hashProofOfStake.begin());
// Skip if hash doesn't satisfy the maximum target
if (hashProofOfStake > nMaxTarget)
if (bnTargetProofOfStake >= CBigNum(hashProofOfStake))
{
- solution.first = hashProofOfStake;
- solution.second = nTimeTx;
-
+ solution = { hashProofOfStake, nTimeTx };
return true;
}
}