message: Add ScanHash
diff: @@ -782,3 +782,41 @@ void StakeQtums(bool fStake, CWallet *pwallet)
  stakeThread->create_thread(boost::bind(&ThreadStakeMiner, pwallet));
  }
  }
  +
  +//////////////////////////////////////////////////////////////////////////////
  +//
  +// Proof Of Work miner
  +//
  +
  +//
  +// ScanHash scans nonces looking for a hash with at least some zero bits.
  +// The nonce is usually preserved between calls, but periodically or if the
  +// nonce is 0xffff0000 or above, the block is rebuilt and nNonce starts over at
  +// zero.
  +//
  +bool static ScanHash(const CBlockHeader *pblock, uint32_t& nNonce, uint256 *phash)
  +{
  + // Write the first 76 bytes of the block header to a double-SHA256 state.
  + CHash256 hasher;
  + CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
  + ss << *pblock;
  + //assert(ss.size() == 80);
  + hasher.Write((unsigned char*)&ss[0], 76);
  +
  + while (true) {
  + nNonce++;
  +
  + // Write the last 4 bytes of the block header (the nonce) to a copy of
  + // the double-SHA256 state, and compute the result.
  + CHash256(hasher).Write((unsigned char*)&nNonce, 4).Finalize((unsigned char*)phash);
  +
  + // Return the nonce if the hash has at least some zero bits,
  + // caller will check if it has enough to reach the target
  + if (((uint16_t*)phash)[15] == 0)
  + return true;
  +
  + // If nothing found after trying for a while, return -1
  + if ((nNonce & 0xfff) == 0)
  + return false;
  + }
  +}
  \ No newline at end of file
  