Merge pull request #58 from fsb4000/columnPoSReward
[novacoin.git] / src / kernelrecord.cpp
index f4ec68e..3121845 100644 (file)
@@ -2,9 +2,7 @@
 
 #include "wallet.h"
 #include "base58.h"
-#include "main.h"
 
-#include <math.h>
 
 using namespace std;
 
@@ -35,11 +33,11 @@ vector<KernelRecord> KernelRecord::decomposeOutput(const CWallet *wallet, const
     int64 nTime = wtx.GetTxTime();
     uint256 hash = wtx.GetHash();
     std::map<std::string, std::string> mapValue = wtx.mapValue;
-    int64 nDayWeight = (min((GetAdjustedTime() - nTime), (int64)(nStakeMaxAge+nStakeMinAge)) - nStakeMinAge); // DayWeight * 86400, ÷òîáû áûë
-                                                                                                              // ïðàâèëüíûé ðàñ÷¸ò CoinAge                                                         
+    int64 nDayWeight = (min((GetAdjustedTime() - nTime), (int64)(nStakeMaxAge+nStakeMinAge)) - nStakeMinAge); // DayWeight * 86400, чтобы был
+                                                                                                              // правильный расчёт CoinAge
     if (showTransaction(wtx))
     {
-        for (int nOut = 0; nOut < wtx.vout.size(); nOut++)
+        for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++)
         {
             CTxOut txOut = wtx.vout[nOut];
             if( wallet->IsMine(txOut) ) {
@@ -77,6 +75,16 @@ 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;