PPCoin: Fix coinstake creation since 2a7d702
[novacoin.git] / src / wallet.cpp
index de203bc..1066dff 100644 (file)
@@ -1247,14 +1247,14 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
         CBlock block;
         if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false))
             continue;
-        if (block.GetBlockTime() + nStakeMinAge > txNew.nTime)
+        if (block.GetBlockTime() + nStakeMinAge > txNew.nTime - (60 * 60 * 2))
             continue; // only count coins meeting min age requirement
 
         int64 nValueIn = pcoin.first->vout[pcoin.second].nValue;
         CBigNum bnCoinDay = CBigNum(nValueIn) * min(txNew.nTime-pcoin.first->nTime, (unsigned int)STAKE_MAX_AGE) / COIN / (24 * 60 * 60);
 
         bool fKernelFound = false;
-        for (int n=0; n<5 && !fKernelFound; n++)
+        for (int n=0; n<min(nSearchInterval,(int64)5) && !fKernelFound && !fShutdown; n++)
         {
             // Randomly pick a timestamp from protocol allowed range
             txNew.nTime = GetAdjustedTime() - GetRandInt(60 * 60 * 2 - 60);
@@ -1310,7 +1310,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
                 fKernelFound = true;
             }
         }
-        if (fKernelFound)
+        if (fKernelFound || fShutdown)
             break; // if kernel is found stop searching
     }
     if (nCredit == 0 || nCredit > nBalance - nReserveBalance)