message: Add the stake miner
diff: @@ -686,3 +686,69 @@ bool CheckStake(const std::shared_ptr<const CBlock> pblock, CWallet& wallet)
  return true;
  }
  +
  +void ThreadStakeMiner(CWallet *pwallet)
  +{
  + SetThreadPriority(THREAD_PRIORITY_LOWEST);
  +
  + // Make this thread recognisable as the mining thread
  + RenameThread("qtumcoin-miner");
  +
  + CReserveKey reservekey(pwallet);
  +
  + bool fTryToSync = true;
  +
  + while (true)
  + {
  + while (pwallet->IsLocked())
  + {
  + nLastCoinStakeSearchInterval = 0;
  + MilliSleep(1000);
  + }
  +
  + while (g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0 || IsInitialBlockDownload())
  + {
  + nLastCoinStakeSearchInterval = 0;
  + fTryToSync = true;
  + MilliSleep(1000);
  + }
  +
  + if (fTryToSync)
  + {
  + fTryToSync = false;
  + if (g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL) < 3 || pindexBestHeader->GetBlockTime() < GetTime() - 10 * 60)
  + {
  + MilliSleep(60000);
  + continue;
  + }
  + }
  +
  + //check the next block height, wait for PoS
  + if (chainActive.Tip()->nHeight + 1 < Params().GetConsensus().nLastPOWBlock)
  + {
  + MilliSleep(60000);
  + continue;
  + }
  +
  + //
  + // Create new block
  + //
  + int64_t nFees;
  + std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler(Params()).CreateNewBlock(reservekey.reserveScript, true, &nFees));
  + if (!pblocktemplate.get())
  + return;
  + CBlock *pblock = &pblocktemplate->block;
  +
  + // Trying to sign a block
  + if (SignBlock(*pblock, *pwallet, nFees))
  + {
  + SetThreadPriority(THREAD_PRIORITY_NORMAL);
  + std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);
  + CheckStake(shared_pblock, *pwallet);
  + SetThreadPriority(THREAD_PRIORITY_LOWEST);
  + MilliSleep(500);
  + }
  + else
  + MilliSleep(nMinerSleep);
  + }
  +}
  \ No newline at end of file
  