X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fkernelrecord.cpp;h=9c61d06f07d493b9fd81f717d1da154561d89aa6;hb=0a18ce8f4cd1a723f50333945d94c84b45c8d56b;hp=2c6f2d9b06f0223ac909be09f842e86156c2099e;hpb=5202470300632a3aa3b5bc6f9a34622264d005be;p=novacoin.git diff --git a/src/kernelrecord.cpp b/src/kernelrecord.cpp index 2c6f2d9..9c61d06 100644 --- a/src/kernelrecord.cpp +++ b/src/kernelrecord.cpp @@ -2,9 +2,10 @@ #include "wallet.h" #include "base58.h" -#include "main.h" -#include +#ifdef _MSC_VER +#pragma warning( disable : 4345) +#endif using namespace std; @@ -32,21 +33,21 @@ bool KernelRecord::showTransaction(const CWalletTx &wtx) vector KernelRecord::decomposeOutput(const CWallet *wallet, const CWalletTx &wtx) { vector parts; - int64 nTime = wtx.GetTxTime(); + int64_t nTime = wtx.GetTxTime(); uint256 hash = wtx.GetHash(); std::map mapValue = wtx.mapValue; - int64 nDayWeight = (min((GetAdjustedTime() - nTime), (int64)(nStakeMaxAge+nStakeMinAge)) - nStakeMinAge); // DayWeight * 86400, ÷òîáû áûë - // ïðàâèëüíûé ðàñ÷¸ò CoinAge + int64_t nDayWeight = (min((GetAdjustedTime() - nTime), (int64_t)(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) ) { CTxDestination address; std::string addrStr; - uint64 coinAge = max( (txOut.nValue * nDayWeight) / (COIN * 86400), (int64)0); + uint64_t coinAge = max( (txOut.nValue * nDayWeight) / (COIN * nOneDay), (int64_t)0); if (ExtractDestination(txOut.scriptPubKey, address)) { @@ -72,21 +73,29 @@ std::string KernelRecord::getTxID() return hash.ToString() + strprintf("-%03d", idx); } -int64 KernelRecord::getAge() const +int64_t KernelRecord::getAge() const { - return (GetAdjustedTime() - nTime) / 86400; + return (GetAdjustedTime() - nTime) / nOneDay; } -double KernelRecord::getPoSReward(double difficulty, int minutes) +uint64_t KernelRecord::getCoinDay() const { - double PoSReward; - int nWeight = GetAdjustedTime() - nTime + minutes * 60; + int64_t nWeight = GetAdjustedTime() - nTime - nStakeMinAge; + if( nWeight < 0) + return 0; + nWeight = min(nWeight, (int64_t)nStakeMaxAge); + uint64_t coinAge = (nValue * nWeight ) / (COIN * nOneDay); + return coinAge; +} + +int64_t KernelRecord::getPoSReward(int nBits, int minutes) +{ + int64_t PoSReward; + int64_t nWeight = GetAdjustedTime() - nTime + minutes * 60; if( nWeight < nStakeMinAge) return 0; - uint64 coinAge = (nValue * nWeight ) / (COIN * 86400); - double nRewardCoinYear = floor(pow((0.03125 / difficulty), 1.0/3) *100)/100; - PoSReward = (coinAge * nRewardCoinYear )/365; - PoSReward = min(PoSReward,10.0); + uint64_t coinAge = (nValue * nWeight ) / (COIN * nOneDay); + PoSReward = GetProofOfStakeReward(coinAge, nBits, GetAdjustedTime() + minutes * 60); return PoSReward; } @@ -94,11 +103,11 @@ double KernelRecord::getProbToMintStake(double difficulty, int timeOffset) const { //double maxTarget = pow(static_cast(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); + //int dayWeight = (min((GetAdjustedTime() - nTime) + timeOffset, (int64_t)(nStakeMinAge+nStakeMaxAge)) - nStakeMinAge) / 86400; + //uint64_t coinAge = max(nValue * dayWeight / COIN, (int64_t)0); //return target * coinAge / pow(static_cast(2), 256); - int Weight = (min((GetAdjustedTime() - nTime) + timeOffset, (int64)(nStakeMinAge+nStakeMaxAge)) - nStakeMinAge); - uint64 coinAge = max(nValue * Weight / (COIN * 86400), (int64)0); + int64_t Weight = (min((GetAdjustedTime() - nTime) + timeOffset, (int64_t)(nStakeMinAge+nStakeMaxAge)) - nStakeMinAge); + uint64_t coinAge = max(nValue * Weight / (COIN * nOneDay), (int64_t)0); return coinAge / (pow(static_cast(2),32) * difficulty); } @@ -115,13 +124,13 @@ double KernelRecord::getProbToMintWithinNMinutes(double difficulty, int minutes) // Probabilities for the first d days for(i = 0; i < d; i++) { - timeOffset = i * 86400; - p = pow(1 - getProbToMintStake(difficulty, timeOffset), 86400); + timeOffset = i * nOneDay; + p = pow(1 - getProbToMintStake(difficulty, timeOffset), nOneDay); prob *= p; } // Probability for the m minutes of the last day - timeOffset = d * 86400; + timeOffset = d * nOneDay; p = pow(1 - getProbToMintStake(difficulty, timeOffset), 60 * m); prob *= p;