обновление значений в стоблце "Вес"
[novacoin.git] / src / kernelrecord.cpp
index eb68dd4..ef46b46 100644 (file)
@@ -2,7 +2,7 @@
 
 #include "wallet.h"
 #include "base58.h"
-#include "main.h"
+
 
 using namespace std;
 
@@ -75,13 +75,37 @@ int64 KernelRecord::getAge() const
     return (GetAdjustedTime() - nTime) / 86400;
 }
 
+uint64 KernelRecord::getCoinDay() const
+{
+    int64 nWeight = GetAdjustedTime() - nTime - nStakeMinAge;
+    if( nWeight <  0)
+        return 0;
+    nWeight = min(nWeight, (int64)nStakeMaxAge);
+    uint64 coinAge = (nValue * nWeight ) / (COIN * 86400);
+    return coinAge;
+}
+
+int64 KernelRecord::getPoSReward(int nBits, int minutes)
+{
+    double PoSReward;
+    int64 nWeight = GetAdjustedTime() - nTime + minutes * 60;
+    if( nWeight <  nStakeMinAge)
+        return 0;
+    uint64 coinAge = (nValue * nWeight ) / (COIN * 86400);
+    PoSReward = GetProofOfStakeReward(coinAge, nBits, GetAdjustedTime() + minutes * 60);
+    return PoSReward;
+}
+
 double KernelRecord::getProbToMintStake(double difficulty, int timeOffset) const
 {
-    double maxTarget = pow(static_cast<double>(2), 224);
-    double target = maxTarget / difficulty;
-    int dayWeight = (min((GetAdjustedTime() - nTime) + timeOffset, (int64)(nStakeMinAge+nStakeMaxAge)) - nStakeMinAge) / 86400;
-    uint64 coinAge = max(nValue * dayWeight / COIN, (int64)0);
-    return target * coinAge / pow(static_cast<double>(2), 256);
+    //double maxTarget = pow(static_cast<double>(2), 224);
+    //double target = maxTarget / difficulty;
+    //int dayWeight = (min((GetAdjustedTime() - nTime) + timeOffset, (int64)(nStakeMinAge+nStakeMaxAge)) - nStakeMinAge) / 86400;
+    //uint64 coinAge = max(nValue * dayWeight / COIN, (int64)0);
+    //return target * coinAge / pow(static_cast<double>(2), 256);
+    int Weight = (min((GetAdjustedTime() - nTime) + timeOffset, (int64)(nStakeMinAge+nStakeMaxAge)) - nStakeMinAge);
+    uint64 coinAge = max(nValue * Weight / (COIN * 86400), (int64)0);
+    return coinAge / (pow(static_cast<double>(2),32) * difficulty);
 }
 
 double KernelRecord::getProbToMintWithinNMinutes(double difficulty, int minutes)