1 #include "kernelrecord.h"
11 bool KernelRecord::showTransaction(const CWalletTx &wtx)
15 if (wtx.GetDepthInMainChain() < 2)
30 * Decompose CWallet transaction to model kernel records.
32 vector<KernelRecord> KernelRecord::decomposeOutput(const CWallet *wallet, const CWalletTx &wtx)
34 vector<KernelRecord> parts;
35 int64 nTime = wtx.GetTxTime();
36 uint256 hash = wtx.GetHash();
37 std::map<std::string, std::string> mapValue = wtx.mapValue;
38 int64 nDayWeight = (min((GetAdjustedTime() - nTime), (int64)(nStakeMaxAge+nStakeMinAge)) - nStakeMinAge); // DayWeight * 86400, ÷òîáû áûë
39 // ïðàâèëüíûé ðàñ÷¸ò CoinAge
40 if (showTransaction(wtx))
42 for (int nOut = 0; nOut < wtx.vout.size(); nOut++)
44 CTxOut txOut = wtx.vout[nOut];
45 if( wallet->IsMine(txOut) ) {
46 CTxDestination address;
49 uint64 coinAge = max( (txOut.nValue * nDayWeight) / (COIN * 86400), (int64)0);
51 if (ExtractDestination(txOut.scriptPubKey, address))
53 // Sent to Bitcoin Address
54 addrStr = CBitcoinAddress(address).ToString();
58 // Sent to IP, or other non-address transaction like OP_EVAL
59 addrStr = mapValue["to"];
62 parts.push_back(KernelRecord(hash, nTime, addrStr, txOut.nValue, wtx.IsSpent(nOut), coinAge));
70 std::string KernelRecord::getTxID()
72 return hash.ToString() + strprintf("-%03d", idx);
75 int64 KernelRecord::getAge() const
77 return (GetAdjustedTime() - nTime) / 86400;
80 int64 KernelRecord::getPoSReward(int nBits, int minutes)
83 int64 nWeight = GetAdjustedTime() - nTime + minutes * 60;
84 if( nWeight < nStakeMinAge)
86 uint64 coinAge = (nValue * nWeight ) / (COIN * 86400);
87 PoSReward = GetProofOfStakeReward(coinAge, nBits, GetAdjustedTime() + minutes * 60);
91 double KernelRecord::getProbToMintStake(double difficulty, int timeOffset) const
93 //double maxTarget = pow(static_cast<double>(2), 224);
94 //double target = maxTarget / difficulty;
95 //int dayWeight = (min((GetAdjustedTime() - nTime) + timeOffset, (int64)(nStakeMinAge+nStakeMaxAge)) - nStakeMinAge) / 86400;
96 //uint64 coinAge = max(nValue * dayWeight / COIN, (int64)0);
97 //return target * coinAge / pow(static_cast<double>(2), 256);
98 int Weight = (min((GetAdjustedTime() - nTime) + timeOffset, (int64)(nStakeMinAge+nStakeMaxAge)) - nStakeMinAge);
99 uint64 coinAge = max(nValue * Weight / (COIN * 86400), (int64)0);
100 return coinAge / (pow(static_cast<double>(2),32) * difficulty);
103 double KernelRecord::getProbToMintWithinNMinutes(double difficulty, int minutes)
105 if(difficulty != prevDifficulty || minutes != prevMinutes)
109 int d = minutes / (60 * 24); // Number of full days
110 int m = minutes % (60 * 24); // Number of minutes in the last day
113 // Probabilities for the first d days
114 for(i = 0; i < d; i++)
116 timeOffset = i * 86400;
117 p = pow(1 - getProbToMintStake(difficulty, timeOffset), 86400);
121 // Probability for the m minutes of the last day
122 timeOffset = d * 86400;
123 p = pow(1 - getProbToMintStake(difficulty, timeOffset), 60 * m);
127 prevProbability = prob;
128 prevDifficulty = difficulty;
129 prevMinutes = minutes;
131 return prevProbability;